@memberjunction/ng-task-graph-editor 6.1.0-edge.1 → 6.1.0-edge.3
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 +180 -4
- package/README.md +197 -0
- package/dist/lib/debug-variables.d.ts +27 -0
- package/dist/lib/debug-variables.d.ts.map +1 -0
- package/dist/lib/debug-variables.js +96 -0
- package/dist/lib/debug-variables.js.map +1 -0
- package/dist/lib/pane-split.d.ts +11 -0
- package/dist/lib/pane-split.d.ts.map +1 -0
- package/dist/lib/pane-split.js +36 -0
- package/dist/lib/pane-split.js.map +1 -0
- package/dist/lib/task-graph-canvas-adapter.d.ts +142 -7
- package/dist/lib/task-graph-canvas-adapter.d.ts.map +1 -1
- package/dist/lib/task-graph-canvas-adapter.js +319 -44
- package/dist/lib/task-graph-canvas-adapter.js.map +1 -1
- package/dist/lib/task-graph-debug-toolbar.component.d.ts +27 -0
- package/dist/lib/task-graph-debug-toolbar.component.d.ts.map +1 -0
- package/dist/lib/task-graph-debug-toolbar.component.js +153 -0
- package/dist/lib/task-graph-debug-toolbar.component.js.map +1 -0
- package/dist/lib/task-graph-debugger.component.d.ts +96 -0
- package/dist/lib/task-graph-debugger.component.d.ts.map +1 -0
- package/dist/lib/task-graph-debugger.component.js +371 -0
- package/dist/lib/task-graph-debugger.component.js.map +1 -0
- package/dist/lib/task-graph-editor.component.d.ts +144 -5
- package/dist/lib/task-graph-editor.component.d.ts.map +1 -1
- package/dist/lib/task-graph-editor.component.js +321 -26
- package/dist/lib/task-graph-editor.component.js.map +1 -1
- package/dist/lib/task-graph-editor.module.d.ts +10 -5
- package/dist/lib/task-graph-editor.module.d.ts.map +1 -1
- package/dist/lib/task-graph-editor.module.js +53 -5
- package/dist/lib/task-graph-editor.module.js.map +1 -1
- package/dist/lib/task-graph-properties-panel.component.d.ts +34 -8
- package/dist/lib/task-graph-properties-panel.component.d.ts.map +1 -1
- package/dist/lib/task-graph-properties-panel.component.js +164 -45
- package/dist/lib/task-graph-properties-panel.component.js.map +1 -1
- package/dist/lib/task-graph-run-prefs.d.ts +34 -0
- package/dist/lib/task-graph-run-prefs.d.ts.map +1 -0
- package/dist/lib/task-graph-run-prefs.js +67 -0
- package/dist/lib/task-graph-run-prefs.js.map +1 -0
- package/dist/lib/task-graph-run-view.component.d.ts +290 -0
- package/dist/lib/task-graph-run-view.component.d.ts.map +1 -0
- package/dist/lib/task-graph-run-view.component.js +826 -0
- package/dist/lib/task-graph-run-view.component.js.map +1 -0
- package/dist/lib/task-graph-runtime-source.d.ts +7 -1
- package/dist/lib/task-graph-runtime-source.d.ts.map +1 -1
- package/dist/lib/task-graph-runtime-source.js +14 -2
- package/dist/lib/task-graph-runtime-source.js.map +1 -1
- package/dist/lib/task-graph-variables.component.d.ts +23 -0
- package/dist/lib/task-graph-variables.component.d.ts.map +1 -0
- package/dist/lib/task-graph-variables.component.js +192 -0
- package/dist/lib/task-graph-variables.component.js.map +1 -0
- package/dist/lib/workflow-debug-host.d.ts +23 -0
- package/dist/lib/workflow-debug-host.d.ts.map +1 -0
- package/dist/lib/workflow-debug-host.js +101 -0
- package/dist/lib/workflow-debug-host.js.map +1 -0
- package/dist/public-api.d.ts +8 -0
- package/dist/public-api.d.ts.map +1 -1
- package/dist/public-api.js +8 -0
- package/dist/public-api.js.map +1 -1
- package/package.json +11 -9
|
@@ -16,13 +16,79 @@
|
|
|
16
16
|
* @module @memberjunction/ng-task-graph-editor
|
|
17
17
|
*/
|
|
18
18
|
import { type TaskGraphSpec, type TaskGraphSpecNode, type TaskGraphDependency } from '@memberjunction/ai-core-plus';
|
|
19
|
-
import type { FlowConnection, FlowNode, FlowNodeStatus, FlowNodeTypeConfig } from '@memberjunction/ng-flow-editor';
|
|
20
|
-
/**
|
|
21
|
-
|
|
19
|
+
import type { FlowConnection, FlowNode, FlowNodeStatus, FlowNodeTypeConfig, FlowPosition } from '@memberjunction/ng-flow-editor';
|
|
20
|
+
/**
|
|
21
|
+
* The shapes this canvas can DRAW.
|
|
22
|
+
*
|
|
23
|
+
* Three of the spec's seven `kind`s, and the choice is the canvas's: these are the shapes a person
|
|
24
|
+
* authors. `Prompt`, `ForEach`, `While` and `External` are expressible in the spec but have no
|
|
25
|
+
* authoring affordance here — a palette entry that cannot be configured would be worse than none.
|
|
26
|
+
*
|
|
27
|
+
* **Drawing and RENDERING are different questions**, which this type used to conflate. A run's
|
|
28
|
+
* graph is displayed on the same canvas, and it contains kinds nobody can draw — so mapping them
|
|
29
|
+
* all to `AgentTask` made a fully-configured ForEach render as "AGENT STEP · No agent chosen yet",
|
|
30
|
+
* which is not merely imprecise: it says the step is broken. See {@link TaskGraphRenderType}.
|
|
31
|
+
*/
|
|
32
|
+
export type TaskGraphNodeType = 'AgentTask' | 'ActionTask' | 'HumanTask';
|
|
33
|
+
/**
|
|
34
|
+
* The shapes this canvas can SHOW — a superset of what it can draw.
|
|
35
|
+
*
|
|
36
|
+
* Display-only kinds exist because a task graph is rendered in two places: the editor, where a
|
|
37
|
+
* person builds one, and a run view, where one that already ran is shown. The second must be able
|
|
38
|
+
* to depict every kind the dispatcher can execute, whether or not the palette offers it.
|
|
39
|
+
*/
|
|
40
|
+
export type TaskGraphRenderType = TaskGraphNodeType | 'PromptTask' | 'ForEachTask' | 'WhileTask' | 'ExternalTask';
|
|
41
|
+
/** A palette entry, pinned to one of the three authorable shapes. */
|
|
42
|
+
export type TaskGraphNodeTypeConfig = FlowNodeTypeConfig & {
|
|
43
|
+
Type: TaskGraphNodeType;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Whether a shape is one a person can actually author here.
|
|
47
|
+
*
|
|
48
|
+
* The authoring paths — the palette, `NewTaskFromNodeType`, the properties panel — only handle the
|
|
49
|
+
* three drawable shapes. Rendering handles more. This is the seam between the two, stated as a type
|
|
50
|
+
* guard so the compiler enforces it rather than a cast pretending the distinction does not exist.
|
|
51
|
+
*/
|
|
52
|
+
export declare function IsAuthorableNodeType(type: TaskGraphRenderType): type is TaskGraphNodeType;
|
|
53
|
+
/** A rendering entry — every shape the canvas can depict, authorable or not. */
|
|
54
|
+
export type TaskGraphRenderTypeConfig = FlowNodeTypeConfig & {
|
|
55
|
+
Type: TaskGraphRenderType;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Port ids are scoped to their NODE, and must be.
|
|
59
|
+
*
|
|
60
|
+
* The canvas resolves a connection by looking its `fOutputId` / `fInputId` up among all registered
|
|
61
|
+
* ports — a flat, graph-wide namespace. Giving every node ports literally called `in` and `out` made
|
|
62
|
+
* every node's ports collide with every other node's, so a connection could not name which node's
|
|
63
|
+
* port it meant. The result was a workflow that drew its boxes correctly and **no edges at all**:
|
|
64
|
+
* nothing errored, because an unresolvable port is simply a connection with nowhere to attach.
|
|
65
|
+
*
|
|
66
|
+
* The Flow Agent editor — the other consumer of this canvas, whose edges have always drawn — scopes
|
|
67
|
+
* its ports the same way (`${stepId}-input` / `${stepId}-output`). This is that convention, named,
|
|
68
|
+
* so a future producer cannot reintroduce the collision by writing the obvious literal.
|
|
69
|
+
*/
|
|
70
|
+
export declare function InputPortID(tempId: string): string;
|
|
71
|
+
export declare function OutputPortID(tempId: string): string;
|
|
72
|
+
/** What the palette offers — one entry per assignment shape the spec supports. */
|
|
73
|
+
export declare const TASK_GRAPH_NODE_TYPES: readonly TaskGraphNodeTypeConfig[];
|
|
74
|
+
/**
|
|
75
|
+
* Everything the canvas can DEPICT: the palette, plus the kinds that only ever arrive from a run.
|
|
76
|
+
*
|
|
77
|
+
* Deliberately a superset rather than an extension of the palette — adding these to
|
|
78
|
+
* `TASK_GRAPH_NODE_TYPES` would put un-configurable entries in the authoring toolbox.
|
|
79
|
+
*/
|
|
80
|
+
export declare const TASK_GRAPH_RENDER_TYPES: readonly TaskGraphRenderTypeConfig[];
|
|
81
|
+
/**
|
|
82
|
+
* The config for a node type, or null when the type is not one of ours.
|
|
83
|
+
*
|
|
84
|
+
* Searches the RENDER set, so a run's ForEach resolves to its own icon and label instead of
|
|
85
|
+
* silently falling back to the agent shape.
|
|
86
|
+
*/
|
|
87
|
+
export declare function GetNodeTypeConfig(type: string): TaskGraphRenderTypeConfig | null;
|
|
22
88
|
/** Live per-task state for the runtime overlay, keyed by `tempId`. */
|
|
23
89
|
export type TaskGraphRuntimeStatus = Record<string, TaskGraphRuntimeState>;
|
|
24
90
|
/** What a task is doing right now, in the durable engine's own vocabulary. */
|
|
25
|
-
export type TaskGraphRuntimeState = 'Pending' | 'In Progress' | 'Complete' | 'Failed' | 'Blocked' | 'Cancelled' | 'Deferred';
|
|
91
|
+
export type TaskGraphRuntimeState = 'Pending' | 'In Progress' | 'Complete' | 'Failed' | 'Blocked' | 'Cancelled' | 'Deferred' | 'Skipped';
|
|
26
92
|
/**
|
|
27
93
|
* Maps a durable task state onto the canvas's visual vocabulary.
|
|
28
94
|
*
|
|
@@ -32,8 +98,38 @@ export type TaskGraphRuntimeState = 'Pending' | 'In Progress' | 'Complete' | 'Fa
|
|
|
32
98
|
* on a schedule and waiting on a prerequisite look and mean the same thing.
|
|
33
99
|
*/
|
|
34
100
|
export declare function RuntimeStateToNodeStatus(state: TaskGraphRuntimeState | undefined): FlowNodeStatus;
|
|
35
|
-
/**
|
|
101
|
+
/**
|
|
102
|
+
* True when the node is a person's step.
|
|
103
|
+
*
|
|
104
|
+
* One field decides it now: spec v2 gives every node exactly one `kind`, so "is this a person's
|
|
105
|
+
* step" stopped being an inference over three optional flags and became a comparison.
|
|
106
|
+
*/
|
|
36
107
|
export declare function IsHumanTask(node: TaskGraphSpecNode): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Which of the three shapes a node is, for rendering.
|
|
110
|
+
*
|
|
111
|
+
* An unassigned node (just added, nothing picked yet) reads as an agent step: it is the commonest
|
|
112
|
+
* intent, and the validator is already telling the author, in words, that it needs an assignee.
|
|
113
|
+
* Guessing "person" instead — which is what the old `!agentName` rule did — put a step in the
|
|
114
|
+
* graph that claimed to be waiting on someone when nobody had said so.
|
|
115
|
+
*/
|
|
116
|
+
export declare function GetTaskNodeType(node: TaskGraphSpecNode): TaskGraphRenderType;
|
|
117
|
+
/**
|
|
118
|
+
* Builds the task a palette entry stands for.
|
|
119
|
+
*
|
|
120
|
+
* Pure, and here rather than in the component, because "what does clicking *Person Step* actually
|
|
121
|
+
* put in the graph" is a fact about the spec — testable without a TestBed, and the one place the
|
|
122
|
+
* assignment xor is honoured on creation.
|
|
123
|
+
*
|
|
124
|
+
* `defaultAgentName` / `defaultActionName` are what the host has to offer. When it has nothing, the
|
|
125
|
+
* step is created unassigned on purpose: inventing an agent name that may not exist would produce a
|
|
126
|
+
* graph that passes the canvas and fails at submission, whereas an unassigned step is reported
|
|
127
|
+
* immediately by the same validator the engine runs.
|
|
128
|
+
*/
|
|
129
|
+
export declare function NewTaskFromNodeType(spec: TaskGraphSpec, type: TaskGraphNodeType, defaults?: {
|
|
130
|
+
agentName?: string;
|
|
131
|
+
actionName?: string;
|
|
132
|
+
}): TaskGraphSpecNode;
|
|
37
133
|
/** Entry points: nodes nothing else has to finish first. Same rule the traversal engine uses. */
|
|
38
134
|
export declare function GetEntryTempIds(spec: TaskGraphSpec): string[];
|
|
39
135
|
/** Every dependency of a node, in normalized object form. */
|
|
@@ -47,7 +143,44 @@ export declare function GetDependents(spec: TaskGraphSpec, tempId: string): stri
|
|
|
47
143
|
* geometry precisely because a task graph is a *logical* structure. An agent that emitted one never
|
|
48
144
|
* had an opinion about where the boxes go.
|
|
49
145
|
*/
|
|
50
|
-
|
|
146
|
+
/**
|
|
147
|
+
* Projects the spec onto canvas nodes.
|
|
148
|
+
*
|
|
149
|
+
* `positions` carries geometry the spec cannot hold. `TaskGraphSpec` is an execution contract with
|
|
150
|
+
* no layout field, so without a caller-held map every re-projection would return every node to the
|
|
151
|
+
* origin — which is what previously forced a full re-arrange (and a viewport re-zoom) after every
|
|
152
|
+
* single edit. Unknown ids fall back to the origin, which is also the correct starting state for a
|
|
153
|
+
* graph that has never been laid out.
|
|
154
|
+
*/
|
|
155
|
+
/**
|
|
156
|
+
* Debug overlay the run view hands the adapter. Paint only — the widget never calls an operation.
|
|
157
|
+
*
|
|
158
|
+
* Breakpoints and the paused-at step become badges. Overrides restyle connections (dotted, never
|
|
159
|
+
* dashed — dashed already means "this edge is conditional"). Held/forced edges stay visible even
|
|
160
|
+
* when a skip cascade would otherwise drop them, so the run history cannot lie about why a branch
|
|
161
|
+
* ran.
|
|
162
|
+
*/
|
|
163
|
+
export type TaskGraphDebugOverlay = {
|
|
164
|
+
breakpoints?: readonly string[];
|
|
165
|
+
pausedAtTaskID?: string | null;
|
|
166
|
+
/** Graph is claim-gated. With no paused-at step, the entry node is what is waiting. */
|
|
167
|
+
paused?: boolean;
|
|
168
|
+
edgeOverrides?: Readonly<Record<string, 'true' | 'false'>>;
|
|
169
|
+
/** Show the condition expression on the connection label, not just the word "if". */
|
|
170
|
+
showConditions?: boolean;
|
|
171
|
+
/** Edge IDs (or from→to) currently flowing — painted animated + brand. */
|
|
172
|
+
activeEdgeIDs?: readonly string[];
|
|
173
|
+
};
|
|
174
|
+
export declare function SpecToNodes(spec: TaskGraphSpec, runtime?: TaskGraphRuntimeStatus, positions?: ReadonlyMap<string, FlowPosition>, debug?: TaskGraphDebugOverlay): FlowNode[];
|
|
175
|
+
/** Badge pills for an armed breakpoint and the step the graph actually stopped on. */
|
|
176
|
+
export declare function NodeDebugBadges(taskID: string, breakpoints: ReadonlySet<string>, debug?: TaskGraphDebugOverlay, runtime?: TaskGraphRuntimeStatus, entryIds?: ReadonlySet<string>): FlowNode['Badges'];
|
|
177
|
+
/**
|
|
178
|
+
* The one line under a node's name: who or what runs it.
|
|
179
|
+
*
|
|
180
|
+
* An unassigned step says so rather than showing nothing — a blank subtitle looks like a step that
|
|
181
|
+
* is fine, and this one is the reason the validation banner is complaining.
|
|
182
|
+
*/
|
|
183
|
+
export declare function TaskSubtitle(task: TaskGraphSpecNode, type?: TaskGraphRenderType): string;
|
|
51
184
|
/**
|
|
52
185
|
* Projects the spec's dependencies onto canvas connections, reversing their direction.
|
|
53
186
|
*
|
|
@@ -59,7 +192,9 @@ export declare function SpecToNodes(spec: TaskGraphSpec, runtime?: TaskGraphRunt
|
|
|
59
192
|
* validator reports them as `UnknownDependency`, and rendering a connection to nowhere would be a
|
|
60
193
|
* second, worse way of saying the same thing.
|
|
61
194
|
*/
|
|
62
|
-
export declare function SpecToConnections(spec: TaskGraphSpec): FlowConnection[];
|
|
195
|
+
export declare function SpecToConnections(spec: TaskGraphSpec, runtime?: TaskGraphRuntimeStatus, debug?: TaskGraphDebugOverlay): FlowConnection[];
|
|
196
|
+
/** One canvas connection, including the override styling that must never look like a real verdict. */
|
|
197
|
+
export declare function ProjectConnection(dep: TaskGraphDependency, toTempId: string, override?: 'true' | 'false', showConditions?: boolean, flowing?: boolean, traveled?: boolean): FlowConnection;
|
|
63
198
|
/**
|
|
64
199
|
* Adds a dependency to the spec, returning a NEW spec.
|
|
65
200
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-graph-canvas-adapter.d.ts","sourceRoot":"","sources":["../../src/lib/task-graph-canvas-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"task-graph-canvas-adapter.d.ts","sourceRoot":"","sources":["../../src/lib/task-graph-canvas-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAKH,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EAC3B,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,cAAc,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAEjI;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,YAAY,GAAG,WAAW,CAAC;AAEzE;;;;;;GAMG;AACH,MAAM,MAAM,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AAkE;AAClE,wBAAgB,UAAU,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,GAAG,aAAa,CAEtG;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAmBnG;AAED,qEAAqE;AACrE,wBAAgB,UAAU,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,SAAS,GAAG,MAAM,CAKvE"}
|
|
@@ -15,8 +15,46 @@
|
|
|
15
15
|
*
|
|
16
16
|
* @module @memberjunction/ng-task-graph-editor
|
|
17
17
|
*/
|
|
18
|
-
import { NormalizeDependency, } from '@memberjunction/ai-core-plus';
|
|
19
|
-
/**
|
|
18
|
+
import { ConfigOf, NormalizeDependency, TaskNode, } from '@memberjunction/ai-core-plus';
|
|
19
|
+
/**
|
|
20
|
+
* Whether a shape is one a person can actually author here.
|
|
21
|
+
*
|
|
22
|
+
* The authoring paths — the palette, `NewTaskFromNodeType`, the properties panel — only handle the
|
|
23
|
+
* three drawable shapes. Rendering handles more. This is the seam between the two, stated as a type
|
|
24
|
+
* guard so the compiler enforces it rather than a cast pretending the distinction does not exist.
|
|
25
|
+
*/
|
|
26
|
+
export function IsAuthorableNodeType(type) {
|
|
27
|
+
return type === 'AgentTask' || type === 'ActionTask' || type === 'HumanTask';
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Port ids are scoped to their NODE, and must be.
|
|
31
|
+
*
|
|
32
|
+
* The canvas resolves a connection by looking its `fOutputId` / `fInputId` up among all registered
|
|
33
|
+
* ports — a flat, graph-wide namespace. Giving every node ports literally called `in` and `out` made
|
|
34
|
+
* every node's ports collide with every other node's, so a connection could not name which node's
|
|
35
|
+
* port it meant. The result was a workflow that drew its boxes correctly and **no edges at all**:
|
|
36
|
+
* nothing errored, because an unresolvable port is simply a connection with nowhere to attach.
|
|
37
|
+
*
|
|
38
|
+
* The Flow Agent editor — the other consumer of this canvas, whose edges have always drawn — scopes
|
|
39
|
+
* its ports the same way (`${stepId}-input` / `${stepId}-output`). This is that convention, named,
|
|
40
|
+
* so a future producer cannot reintroduce the collision by writing the obvious literal.
|
|
41
|
+
*/
|
|
42
|
+
export function InputPortID(tempId) {
|
|
43
|
+
return `${tempId}-in`;
|
|
44
|
+
}
|
|
45
|
+
export function OutputPortID(tempId) {
|
|
46
|
+
return `${tempId}-out`;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Palette defaults. These carry the bare names because a palette entry describes a node TYPE, not a
|
|
50
|
+
* placed node — there is no id to scope them to yet. {@link SpecToNodes} assigns the real, scoped
|
|
51
|
+
* ids when a node is actually placed on the canvas.
|
|
52
|
+
*/
|
|
53
|
+
const TASK_GRAPH_PORTS = [
|
|
54
|
+
{ ID: 'in', Direction: 'input', Side: 'top', Multiple: true },
|
|
55
|
+
{ ID: 'out', Direction: 'output', Side: 'bottom', Multiple: true },
|
|
56
|
+
];
|
|
57
|
+
/** What the palette offers — one entry per assignment shape the spec supports. */
|
|
20
58
|
export const TASK_GRAPH_NODE_TYPES = [
|
|
21
59
|
{
|
|
22
60
|
Type: 'AgentTask',
|
|
@@ -24,10 +62,15 @@ export const TASK_GRAPH_NODE_TYPES = [
|
|
|
24
62
|
Icon: 'fa-robot',
|
|
25
63
|
Color: '#4A6FA5',
|
|
26
64
|
Category: 'Steps',
|
|
27
|
-
DefaultPorts:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
65
|
+
DefaultPorts: TASK_GRAPH_PORTS,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
Type: 'ActionTask',
|
|
69
|
+
Label: 'Action Step',
|
|
70
|
+
Icon: 'fa-bolt',
|
|
71
|
+
Color: '#3B82F6',
|
|
72
|
+
Category: 'Steps',
|
|
73
|
+
DefaultPorts: TASK_GRAPH_PORTS,
|
|
31
74
|
},
|
|
32
75
|
{
|
|
33
76
|
Type: 'HumanTask',
|
|
@@ -35,12 +78,31 @@ export const TASK_GRAPH_NODE_TYPES = [
|
|
|
35
78
|
Icon: 'fa-user-check',
|
|
36
79
|
Color: '#7B1FA2',
|
|
37
80
|
Category: 'Steps',
|
|
38
|
-
DefaultPorts:
|
|
39
|
-
{ ID: 'in', Direction: 'input', Side: 'top', Multiple: true },
|
|
40
|
-
{ ID: 'out', Direction: 'output', Side: 'bottom', Multiple: true },
|
|
41
|
-
],
|
|
81
|
+
DefaultPorts: TASK_GRAPH_PORTS,
|
|
42
82
|
},
|
|
43
83
|
];
|
|
84
|
+
/**
|
|
85
|
+
* Everything the canvas can DEPICT: the palette, plus the kinds that only ever arrive from a run.
|
|
86
|
+
*
|
|
87
|
+
* Deliberately a superset rather than an extension of the palette — adding these to
|
|
88
|
+
* `TASK_GRAPH_NODE_TYPES` would put un-configurable entries in the authoring toolbox.
|
|
89
|
+
*/
|
|
90
|
+
export const TASK_GRAPH_RENDER_TYPES = [
|
|
91
|
+
...TASK_GRAPH_NODE_TYPES,
|
|
92
|
+
{ Type: 'PromptTask', Label: 'Prompt Step', Icon: 'fa-comment-dots', Color: '#8B5CF6', Category: 'Steps', DefaultPorts: TASK_GRAPH_PORTS },
|
|
93
|
+
{ Type: 'ForEachTask', Label: 'For Each Step', Icon: 'fa-repeat', Color: '#D97706', Category: 'Steps', DefaultPorts: TASK_GRAPH_PORTS },
|
|
94
|
+
{ Type: 'WhileTask', Label: 'While Step', Icon: 'fa-rotate', Color: '#D97706', Category: 'Steps', DefaultPorts: TASK_GRAPH_PORTS },
|
|
95
|
+
{ Type: 'ExternalTask', Label: 'External Step', Icon: 'fa-arrow-up-right-from-square', Color: '#0891B2', Category: 'Steps', DefaultPorts: TASK_GRAPH_PORTS },
|
|
96
|
+
];
|
|
97
|
+
/**
|
|
98
|
+
* The config for a node type, or null when the type is not one of ours.
|
|
99
|
+
*
|
|
100
|
+
* Searches the RENDER set, so a run's ForEach resolves to its own icon and label instead of
|
|
101
|
+
* silently falling back to the agent shape.
|
|
102
|
+
*/
|
|
103
|
+
export function GetNodeTypeConfig(type) {
|
|
104
|
+
return TASK_GRAPH_RENDER_TYPES.find((c) => c.Type === type) ?? null;
|
|
105
|
+
}
|
|
44
106
|
/**
|
|
45
107
|
* Maps a durable task state onto the canvas's visual vocabulary.
|
|
46
108
|
*
|
|
@@ -56,15 +118,79 @@ export function RuntimeStateToNodeStatus(state) {
|
|
|
56
118
|
case 'Failed': return 'error';
|
|
57
119
|
case 'Blocked': return 'warning';
|
|
58
120
|
case 'Cancelled': return 'disabled';
|
|
121
|
+
// Its own state, not a shade of disabled: a branch the workflow did not take is a normal
|
|
122
|
+
// outcome. Falling through to 'default' — which is what happened before — drew it as an
|
|
123
|
+
// ordinary node, so a conditional workflow looked like it had run every branch.
|
|
124
|
+
case 'Skipped': return 'skipped';
|
|
59
125
|
case 'Deferred': return 'pending';
|
|
60
126
|
case 'Pending': return 'pending';
|
|
61
127
|
default: return 'default';
|
|
62
128
|
}
|
|
63
129
|
}
|
|
64
|
-
/**
|
|
130
|
+
/**
|
|
131
|
+
* True when the node is a person's step.
|
|
132
|
+
*
|
|
133
|
+
* One field decides it now: spec v2 gives every node exactly one `kind`, so "is this a person's
|
|
134
|
+
* step" stopped being an inference over three optional flags and became a comparison.
|
|
135
|
+
*/
|
|
65
136
|
export function IsHumanTask(node) {
|
|
66
|
-
return
|
|
137
|
+
return node.kind === 'Human';
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Which of the three shapes a node is, for rendering.
|
|
141
|
+
*
|
|
142
|
+
* An unassigned node (just added, nothing picked yet) reads as an agent step: it is the commonest
|
|
143
|
+
* intent, and the validator is already telling the author, in words, that it needs an assignee.
|
|
144
|
+
* Guessing "person" instead — which is what the old `!agentName` rule did — put a step in the
|
|
145
|
+
* graph that claimed to be waiting on someone when nobody had said so.
|
|
146
|
+
*/
|
|
147
|
+
export function GetTaskNodeType(node) {
|
|
148
|
+
switch (node.kind) {
|
|
149
|
+
case 'Human': return 'HumanTask';
|
|
150
|
+
case 'Action': return 'ActionTask';
|
|
151
|
+
case 'Prompt': return 'PromptTask';
|
|
152
|
+
case 'ForEach': return 'ForEachTask';
|
|
153
|
+
case 'While': return 'WhileTask';
|
|
154
|
+
case 'External': return 'ExternalTask';
|
|
155
|
+
// An unassigned node — just added, nothing picked — reads as an agent step: the commonest
|
|
156
|
+
// intent, and the validator is already saying in words that it needs an assignee.
|
|
157
|
+
default: return 'AgentTask';
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Builds the task a palette entry stands for.
|
|
162
|
+
*
|
|
163
|
+
* Pure, and here rather than in the component, because "what does clicking *Person Step* actually
|
|
164
|
+
* put in the graph" is a fact about the spec — testable without a TestBed, and the one place the
|
|
165
|
+
* assignment xor is honoured on creation.
|
|
166
|
+
*
|
|
167
|
+
* `defaultAgentName` / `defaultActionName` are what the host has to offer. When it has nothing, the
|
|
168
|
+
* step is created unassigned on purpose: inventing an agent name that may not exist would produce a
|
|
169
|
+
* graph that passes the canvas and fails at submission, whereas an unassigned step is reported
|
|
170
|
+
* immediately by the same validator the engine runs.
|
|
171
|
+
*/
|
|
172
|
+
export function NewTaskFromNodeType(spec, type, defaults = {}) {
|
|
173
|
+
const base = {
|
|
174
|
+
tempId: NextTempId(spec),
|
|
175
|
+
name: NEW_TASK_NAMES[type],
|
|
176
|
+
description: '',
|
|
177
|
+
dependsOn: [],
|
|
178
|
+
};
|
|
179
|
+
switch (type) {
|
|
180
|
+
case 'HumanTask': return TaskNode.Human(base);
|
|
181
|
+
// A step created before the host has any names to offer is created with an empty one on
|
|
182
|
+
// purpose: the validator reports it immediately, whereas inventing a name would produce a
|
|
183
|
+
// graph that passes here and fails at submission.
|
|
184
|
+
case 'ActionTask': return TaskNode.Action(base, { actionName: defaults.actionName ?? '' });
|
|
185
|
+
default: return TaskNode.Agent(base, { agentName: defaults.agentName ?? '' });
|
|
186
|
+
}
|
|
67
187
|
}
|
|
188
|
+
/** Default step names, so a new box says what it is before the author renames it. */
|
|
189
|
+
const NEW_TASK_NAMES = {
|
|
190
|
+
AgentTask: 'New agent step',
|
|
191
|
+
ActionTask: 'New action step',
|
|
192
|
+
HumanTask: 'New person step',
|
|
193
|
+
};
|
|
68
194
|
/** Entry points: nodes nothing else has to finish first. Same rule the traversal engine uses. */
|
|
69
195
|
export function GetEntryTempIds(spec) {
|
|
70
196
|
return (spec.tasks ?? []).filter((t) => (t.dependsOn ?? []).length === 0).map((t) => t.tempId);
|
|
@@ -83,35 +209,86 @@ export function GetDependents(spec, tempId) {
|
|
|
83
209
|
function edgeId(fromTempId, toTempId) {
|
|
84
210
|
return `${fromTempId}->${toTempId}`;
|
|
85
211
|
}
|
|
86
|
-
|
|
87
|
-
* Projects the spec onto canvas nodes.
|
|
88
|
-
*
|
|
89
|
-
* Positions are left at the origin: layout is the canvas's job (Dagre), and a spec carries no
|
|
90
|
-
* geometry precisely because a task graph is a *logical* structure. An agent that emitted one never
|
|
91
|
-
* had an opinion about where the boxes go.
|
|
92
|
-
*/
|
|
93
|
-
export function SpecToNodes(spec, runtime) {
|
|
212
|
+
export function SpecToNodes(spec, runtime, positions, debug) {
|
|
94
213
|
const entryIds = new Set(GetEntryTempIds(spec));
|
|
214
|
+
const breakpoints = new Set(debug?.breakpoints ?? []);
|
|
95
215
|
return (spec.tasks ?? []).map((task) => {
|
|
96
|
-
const
|
|
216
|
+
const type = GetTaskNodeType(task);
|
|
217
|
+
const known = positions?.get(task.tempId);
|
|
218
|
+
const awaiting = isAwaitingUser(task.tempId, entryIds, runtime, debug);
|
|
219
|
+
const nextToRun = isNextToRun(task, runtime, debug, entryIds);
|
|
220
|
+
const running = runtime?.[task.tempId] === 'In Progress';
|
|
97
221
|
return {
|
|
98
222
|
ID: task.tempId,
|
|
99
|
-
Type:
|
|
223
|
+
Type: type,
|
|
100
224
|
Label: task.name,
|
|
101
|
-
Subtitle:
|
|
102
|
-
Icon:
|
|
225
|
+
Subtitle: TaskSubtitle(task, type),
|
|
226
|
+
Icon: GetNodeTypeConfig(type)?.Icon ?? 'fa-circle-nodes',
|
|
227
|
+
IconColor: awaiting || nextToRun || running ? 'var(--mj-brand-primary)' : undefined,
|
|
228
|
+
// Keep the real runtime status. Mapping "paused here" to `running` drew a spinner
|
|
229
|
+
// on a step that is waiting for the operator — it read as "this is executing".
|
|
103
230
|
Status: RuntimeStateToNodeStatus(runtime?.[task.tempId]),
|
|
104
231
|
StatusMessage: task.description,
|
|
105
232
|
IsStartNode: entryIds.has(task.tempId),
|
|
106
|
-
|
|
233
|
+
Badges: NodeDebugBadges(task.tempId, breakpoints, debug, runtime, entryIds),
|
|
234
|
+
Position: known ? { ...known } : { X: 0, Y: 0 },
|
|
107
235
|
Ports: [
|
|
108
|
-
{ ID:
|
|
109
|
-
{ ID:
|
|
236
|
+
{ ID: InputPortID(task.tempId), Direction: 'input', Side: 'top', Multiple: true },
|
|
237
|
+
{ ID: OutputPortID(task.tempId), Direction: 'output', Side: 'bottom', Multiple: true },
|
|
110
238
|
],
|
|
111
|
-
Data: { TempId: task.tempId },
|
|
239
|
+
Data: { TempId: task.tempId, AwaitingUser: awaiting, NextToRun: nextToRun },
|
|
112
240
|
};
|
|
113
241
|
});
|
|
114
242
|
}
|
|
243
|
+
/** Badge pills for an armed breakpoint and the step the graph actually stopped on. */
|
|
244
|
+
export function NodeDebugBadges(taskID, breakpoints, debug, runtime, entryIds) {
|
|
245
|
+
const badges = [];
|
|
246
|
+
if (isAwaitingUser(taskID, entryIds ?? new Set(), runtime, debug)) {
|
|
247
|
+
badges.push({
|
|
248
|
+
Label: 'Waiting on you — Continue or Step to run this step',
|
|
249
|
+
Value: 'Waiting here',
|
|
250
|
+
Icon: 'fa-pause',
|
|
251
|
+
Color: 'var(--mj-brand-primary)',
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
if (breakpoints.has(taskID)) {
|
|
255
|
+
badges.push({
|
|
256
|
+
Label: 'Breakpoint',
|
|
257
|
+
Value: 'break',
|
|
258
|
+
Icon: 'fa-circle',
|
|
259
|
+
Color: 'var(--mj-status-error)',
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
return badges.length > 0 ? badges : undefined;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* The one line under a node's name: who or what runs it.
|
|
266
|
+
*
|
|
267
|
+
* An unassigned step says so rather than showing nothing — a blank subtitle looks like a step that
|
|
268
|
+
* is fine, and this one is the reason the validation banner is complaining.
|
|
269
|
+
*/
|
|
270
|
+
export function TaskSubtitle(task, type = GetTaskNodeType(task)) {
|
|
271
|
+
switch (type) {
|
|
272
|
+
case 'HumanTask': return 'Waiting on a person';
|
|
273
|
+
case 'ActionTask': return ConfigOf(task, 'Action')?.actionName || 'No action chosen yet';
|
|
274
|
+
case 'PromptTask': return ConfigOf(task, 'Prompt')?.promptName || 'No prompt chosen yet';
|
|
275
|
+
// A loop's subtitle is what it REPEATS — the one fact that makes the node readable.
|
|
276
|
+
case 'ForEachTask': return LoopBodyLabel(ConfigOf(task, 'ForEach')) ?? 'Repeats for each item';
|
|
277
|
+
case 'WhileTask': return LoopBodyLabel(ConfigOf(task, 'While')) ?? 'Repeats until its condition is false';
|
|
278
|
+
case 'ExternalTask': return ConfigOf(task, 'External')?.domain || 'Completed by an outside system';
|
|
279
|
+
// Only a genuinely unassigned node reaches this now. It used to catch Prompt, ForEach,
|
|
280
|
+
// While and External too — so a fully-configured loop displayed "No agent chosen yet",
|
|
281
|
+
// which reads as a broken step rather than an unrecognised one.
|
|
282
|
+
default: return ConfigOf(task, 'Agent')?.agentName || 'No agent chosen yet';
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
/** What a loop repeats, when it says. */
|
|
286
|
+
function LoopBodyLabel(op) {
|
|
287
|
+
if (!op)
|
|
288
|
+
return null;
|
|
289
|
+
const body = op.action?.name ?? op.subAgent?.name ?? op.prompt?.name;
|
|
290
|
+
return body ? `Repeats: ${body}` : null;
|
|
291
|
+
}
|
|
115
292
|
/**
|
|
116
293
|
* Projects the spec's dependencies onto canvas connections, reversing their direction.
|
|
117
294
|
*
|
|
@@ -123,32 +300,130 @@ export function SpecToNodes(spec, runtime) {
|
|
|
123
300
|
* validator reports them as `UnknownDependency`, and rendering a connection to nowhere would be a
|
|
124
301
|
* second, worse way of saying the same thing.
|
|
125
302
|
*/
|
|
126
|
-
export function SpecToConnections(spec) {
|
|
303
|
+
export function SpecToConnections(spec, runtime, debug) {
|
|
127
304
|
const known = new Set((spec.tasks ?? []).map((t) => t.tempId));
|
|
305
|
+
const entryIds = new Set(GetEntryTempIds(spec));
|
|
128
306
|
const connections = [];
|
|
129
307
|
for (const task of spec.tasks ?? []) {
|
|
130
308
|
for (const dep of GetDependencies(task)) {
|
|
131
309
|
if (!known.has(dep.tempId))
|
|
132
310
|
continue;
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
LabelIcon: conditional ? 'fa-code-branch' : undefined,
|
|
144
|
-
Condition: dep.condition ?? undefined,
|
|
145
|
-
Style: conditional ? 'dashed' : 'solid',
|
|
146
|
-
Data: { FromTempId: dep.tempId, ToTempId: task.tempId },
|
|
147
|
-
});
|
|
311
|
+
const override = dep.id ? debug?.edgeOverrides?.[dep.id] : undefined;
|
|
312
|
+
const eitherSkipped = runtime
|
|
313
|
+
&& (runtime[task.tempId] === 'Skipped' || runtime[dep.tempId] === 'Skipped');
|
|
314
|
+
// RUN MODE DRAWS ONLY THE PATH TAKEN — except an operator-forced edge, which must stay
|
|
315
|
+
// visible or the history lies about why a branch ran (or did not).
|
|
316
|
+
if (eitherSkipped && !override)
|
|
317
|
+
continue;
|
|
318
|
+
const destQueued = isNextToRun(task, runtime, debug, entryIds);
|
|
319
|
+
const flowing = destQueued || isFlowingEdge(dep.tempId, task.tempId, runtime, debug);
|
|
320
|
+
connections.push(ProjectConnection(dep, task.tempId, override, debug?.showConditions === true, flowing, !flowing && isTraveledEdge(dep.tempId, task.tempId, runtime)));
|
|
148
321
|
}
|
|
149
322
|
}
|
|
150
323
|
return connections;
|
|
151
324
|
}
|
|
325
|
+
/** One canvas connection, including the override styling that must never look like a real verdict. */
|
|
326
|
+
export function ProjectConnection(dep, toTempId, override, showConditions = false, flowing = false, traveled = false) {
|
|
327
|
+
const conditional = !!dep.condition?.trim();
|
|
328
|
+
const forced = override === 'true' || override === 'false';
|
|
329
|
+
const conditionLabel = dep.condition?.trim()
|
|
330
|
+
? TruncateCondition(dep.condition.trim())
|
|
331
|
+
: undefined;
|
|
332
|
+
return {
|
|
333
|
+
ID: edgeId(dep.tempId, toTempId),
|
|
334
|
+
SourceNodeID: dep.tempId,
|
|
335
|
+
SourcePortID: OutputPortID(dep.tempId),
|
|
336
|
+
TargetNodeID: toTempId,
|
|
337
|
+
TargetPortID: InputPortID(toTempId),
|
|
338
|
+
Label: forced
|
|
339
|
+
? (override === 'true' ? 'forced yes' : 'forced no')
|
|
340
|
+
: (conditional ? (showConditions && conditionLabel ? conditionLabel : 'if') : undefined),
|
|
341
|
+
LabelDetail: forced
|
|
342
|
+
? `Operator set this path to ${override}${dep.condition ? ` — ${dep.condition}` : ''}`
|
|
343
|
+
: (dep.condition ?? undefined),
|
|
344
|
+
LabelIcon: forced ? 'fa-hand' : (conditional ? 'fa-code-branch' : undefined),
|
|
345
|
+
LabelIconColor: forced ? 'var(--mj-status-warning)' : undefined,
|
|
346
|
+
Condition: dep.condition ?? undefined,
|
|
347
|
+
// Dotted is the override. Dashed means "only sometimes" until the path is taken —
|
|
348
|
+
// after that the condition stays on the label, but the stroke is solid so a finished
|
|
349
|
+
// branch does not still look tentative.
|
|
350
|
+
Style: forced ? 'dotted' : (conditional && !traveled ? 'dashed' : 'solid'),
|
|
351
|
+
Color: flowing
|
|
352
|
+
? 'var(--mj-brand-primary)'
|
|
353
|
+
: (forced ? 'var(--mj-status-warning)' : (traveled ? 'var(--mj-status-success)' : undefined)),
|
|
354
|
+
StrokeWidth: flowing ? 4.5 : (traveled || forced ? 3 : undefined),
|
|
355
|
+
Animated: flowing,
|
|
356
|
+
Data: { FromTempId: dep.tempId, ToTempId: toTempId, EdgeID: dep.id },
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
const TERMINAL_RUNTIME = new Set(['Complete', 'Failed', 'Cancelled', 'Skipped']);
|
|
360
|
+
function isPausedHere(taskID, runtime, debug) {
|
|
361
|
+
if (debug?.pausedAtTaskID !== taskID)
|
|
362
|
+
return false;
|
|
363
|
+
const state = runtime?.[taskID];
|
|
364
|
+
return !state || !TERMINAL_RUNTIME.has(state);
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* The step the operator has to act on: the breakpoint we stopped at, or — at start-paused
|
|
368
|
+
* before any claim — the entry node.
|
|
369
|
+
*/
|
|
370
|
+
function isAwaitingUser(taskID, entryIds, runtime, debug) {
|
|
371
|
+
if (isPausedHere(taskID, runtime, debug))
|
|
372
|
+
return true;
|
|
373
|
+
if (!debug?.paused || debug.pausedAtTaskID)
|
|
374
|
+
return false;
|
|
375
|
+
if (!entryIds.has(taskID))
|
|
376
|
+
return false;
|
|
377
|
+
const state = runtime?.[taskID];
|
|
378
|
+
return !state || !TERMINAL_RUNTIME.has(state);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* The next claimable step: prerequisites are done (or it is an entry) and the engine has not
|
|
382
|
+
* started it. Distinct from "waiting on you" — this one is waiting on the dispatcher.
|
|
383
|
+
*/
|
|
384
|
+
function isNextToRun(task, runtime, debug, entryIds) {
|
|
385
|
+
if (isAwaitingUser(task.tempId, entryIds ?? new Set(), runtime, debug))
|
|
386
|
+
return false;
|
|
387
|
+
const state = runtime?.[task.tempId];
|
|
388
|
+
if (state === 'In Progress' || (state && TERMINAL_RUNTIME.has(state)))
|
|
389
|
+
return false;
|
|
390
|
+
const incoming = GetDependencies(task);
|
|
391
|
+
if (incoming.length === 0)
|
|
392
|
+
return true;
|
|
393
|
+
const live = incoming.filter((d) => runtime?.[d.tempId] !== 'Skipped');
|
|
394
|
+
if (live.length === 0)
|
|
395
|
+
return false;
|
|
396
|
+
return live.every((d) => runtime?.[d.tempId] === 'Complete');
|
|
397
|
+
}
|
|
398
|
+
function isFlowingEdge(fromTempId, toTempId, runtime, debug) {
|
|
399
|
+
if (isPausedHere(toTempId, runtime, debug))
|
|
400
|
+
return true;
|
|
401
|
+
if (debug?.activeEdgeIDs?.includes(edgeId(fromTempId, toTempId)))
|
|
402
|
+
return true;
|
|
403
|
+
if (!runtime)
|
|
404
|
+
return false;
|
|
405
|
+
return runtime[fromTempId] === 'Complete' && runtime[toTempId] === 'In Progress';
|
|
406
|
+
}
|
|
407
|
+
const TAKEN_ORIGIN = new Set(['Complete', 'Failed', 'Cancelled']);
|
|
408
|
+
const TAKEN_DEST = new Set(['In Progress', 'Complete', 'Failed', 'Cancelled']);
|
|
409
|
+
/**
|
|
410
|
+
* Path already taken — origin finished AND dest has actually started. Pending dests are still
|
|
411
|
+
* candidates (a gate has not fired), so they stay dashed until one is claimed and the rest skip.
|
|
412
|
+
*/
|
|
413
|
+
function isTraveledEdge(fromTempId, toTempId, runtime) {
|
|
414
|
+
if (!runtime)
|
|
415
|
+
return false;
|
|
416
|
+
const fromState = runtime[fromTempId];
|
|
417
|
+
const toState = runtime[toTempId];
|
|
418
|
+
if (!fromState || !TAKEN_ORIGIN.has(fromState))
|
|
419
|
+
return false;
|
|
420
|
+
if (!toState || !TAKEN_DEST.has(toState))
|
|
421
|
+
return false;
|
|
422
|
+
return true;
|
|
423
|
+
}
|
|
424
|
+
function TruncateCondition(text, max = 28) {
|
|
425
|
+
return text.length <= max ? text : `${text.slice(0, max - 1)}…`;
|
|
426
|
+
}
|
|
152
427
|
/**
|
|
153
428
|
* Adds a dependency to the spec, returning a NEW spec.
|
|
154
429
|
*
|