@memberjunction/ng-task-graph-editor 6.1.0-edge.1 → 6.1.0-edge.2
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/dist/lib/task-graph-canvas-adapter.d.ts +102 -5
- package/dist/lib/task-graph-canvas-adapter.d.ts.map +1 -1
- package/dist/lib/task-graph-canvas-adapter.js +154 -18
- package/dist/lib/task-graph-canvas-adapter.js.map +1 -1
- package/dist/lib/task-graph-editor.component.d.ts +106 -4
- package/dist/lib/task-graph-editor.component.d.ts.map +1 -1
- package/dist/lib/task-graph-editor.component.js +246 -24
- package/dist/lib/task-graph-editor.component.js.map +1 -1
- package/dist/lib/task-graph-editor.module.d.ts +6 -5
- package/dist/lib/task-graph-editor.module.d.ts.map +1 -1
- package/dist/lib/task-graph-editor.module.js +4 -3
- 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-view.component.d.ts +113 -0
- package/dist/lib/task-graph-run-view.component.d.ts.map +1 -0
- package/dist/lib/task-graph-run-view.component.js +289 -0
- package/dist/lib/task-graph-run-view.component.js.map +1 -0
- package/dist/public-api.d.ts +1 -0
- package/dist/public-api.d.ts.map +1 -1
- package/dist/public-api.js +1 -0
- package/dist/public-api.js.map +1 -1
- package/package.json +9 -8
|
@@ -16,9 +16,60 @@
|
|
|
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
|
+
/** What the palette offers — one entry per assignment shape the spec supports. */
|
|
58
|
+
export declare const TASK_GRAPH_NODE_TYPES: readonly TaskGraphNodeTypeConfig[];
|
|
59
|
+
/**
|
|
60
|
+
* Everything the canvas can DEPICT: the palette, plus the kinds that only ever arrive from a run.
|
|
61
|
+
*
|
|
62
|
+
* Deliberately a superset rather than an extension of the palette — adding these to
|
|
63
|
+
* `TASK_GRAPH_NODE_TYPES` would put un-configurable entries in the authoring toolbox.
|
|
64
|
+
*/
|
|
65
|
+
export declare const TASK_GRAPH_RENDER_TYPES: readonly TaskGraphRenderTypeConfig[];
|
|
66
|
+
/**
|
|
67
|
+
* The config for a node type, or null when the type is not one of ours.
|
|
68
|
+
*
|
|
69
|
+
* Searches the RENDER set, so a run's ForEach resolves to its own icon and label instead of
|
|
70
|
+
* silently falling back to the agent shape.
|
|
71
|
+
*/
|
|
72
|
+
export declare function GetNodeTypeConfig(type: string): TaskGraphRenderTypeConfig | null;
|
|
22
73
|
/** Live per-task state for the runtime overlay, keyed by `tempId`. */
|
|
23
74
|
export type TaskGraphRuntimeStatus = Record<string, TaskGraphRuntimeState>;
|
|
24
75
|
/** What a task is doing right now, in the durable engine's own vocabulary. */
|
|
@@ -32,8 +83,38 @@ export type TaskGraphRuntimeState = 'Pending' | 'In Progress' | 'Complete' | 'Fa
|
|
|
32
83
|
* on a schedule and waiting on a prerequisite look and mean the same thing.
|
|
33
84
|
*/
|
|
34
85
|
export declare function RuntimeStateToNodeStatus(state: TaskGraphRuntimeState | undefined): FlowNodeStatus;
|
|
35
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* True when the node is a person's step.
|
|
88
|
+
*
|
|
89
|
+
* One field decides it now: spec v2 gives every node exactly one `kind`, so "is this a person's
|
|
90
|
+
* step" stopped being an inference over three optional flags and became a comparison.
|
|
91
|
+
*/
|
|
36
92
|
export declare function IsHumanTask(node: TaskGraphSpecNode): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Which of the three shapes a node is, for rendering.
|
|
95
|
+
*
|
|
96
|
+
* An unassigned node (just added, nothing picked yet) reads as an agent step: it is the commonest
|
|
97
|
+
* intent, and the validator is already telling the author, in words, that it needs an assignee.
|
|
98
|
+
* Guessing "person" instead — which is what the old `!agentName` rule did — put a step in the
|
|
99
|
+
* graph that claimed to be waiting on someone when nobody had said so.
|
|
100
|
+
*/
|
|
101
|
+
export declare function GetTaskNodeType(node: TaskGraphSpecNode): TaskGraphRenderType;
|
|
102
|
+
/**
|
|
103
|
+
* Builds the task a palette entry stands for.
|
|
104
|
+
*
|
|
105
|
+
* Pure, and here rather than in the component, because "what does clicking *Person Step* actually
|
|
106
|
+
* put in the graph" is a fact about the spec — testable without a TestBed, and the one place the
|
|
107
|
+
* assignment xor is honoured on creation.
|
|
108
|
+
*
|
|
109
|
+
* `defaultAgentName` / `defaultActionName` are what the host has to offer. When it has nothing, the
|
|
110
|
+
* step is created unassigned on purpose: inventing an agent name that may not exist would produce a
|
|
111
|
+
* graph that passes the canvas and fails at submission, whereas an unassigned step is reported
|
|
112
|
+
* immediately by the same validator the engine runs.
|
|
113
|
+
*/
|
|
114
|
+
export declare function NewTaskFromNodeType(spec: TaskGraphSpec, type: TaskGraphNodeType, defaults?: {
|
|
115
|
+
agentName?: string;
|
|
116
|
+
actionName?: string;
|
|
117
|
+
}): TaskGraphSpecNode;
|
|
37
118
|
/** Entry points: nodes nothing else has to finish first. Same rule the traversal engine uses. */
|
|
38
119
|
export declare function GetEntryTempIds(spec: TaskGraphSpec): string[];
|
|
39
120
|
/** Every dependency of a node, in normalized object form. */
|
|
@@ -47,7 +128,23 @@ export declare function GetDependents(spec: TaskGraphSpec, tempId: string): stri
|
|
|
47
128
|
* geometry precisely because a task graph is a *logical* structure. An agent that emitted one never
|
|
48
129
|
* had an opinion about where the boxes go.
|
|
49
130
|
*/
|
|
50
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Projects the spec onto canvas nodes.
|
|
133
|
+
*
|
|
134
|
+
* `positions` carries geometry the spec cannot hold. `TaskGraphSpec` is an execution contract with
|
|
135
|
+
* no layout field, so without a caller-held map every re-projection would return every node to the
|
|
136
|
+
* origin — which is what previously forced a full re-arrange (and a viewport re-zoom) after every
|
|
137
|
+
* single edit. Unknown ids fall back to the origin, which is also the correct starting state for a
|
|
138
|
+
* graph that has never been laid out.
|
|
139
|
+
*/
|
|
140
|
+
export declare function SpecToNodes(spec: TaskGraphSpec, runtime?: TaskGraphRuntimeStatus, positions?: ReadonlyMap<string, FlowPosition>): FlowNode[];
|
|
141
|
+
/**
|
|
142
|
+
* The one line under a node's name: who or what runs it.
|
|
143
|
+
*
|
|
144
|
+
* An unassigned step says so rather than showing nothing — a blank subtitle looks like a step that
|
|
145
|
+
* is fine, and this one is the reason the validation banner is complaining.
|
|
146
|
+
*/
|
|
147
|
+
export declare function TaskSubtitle(task: TaskGraphSpecNode, type?: TaskGraphRenderType): string;
|
|
51
148
|
/**
|
|
52
149
|
* Projects the spec's dependencies onto canvas connections, reversing their direction.
|
|
53
150
|
*
|
|
@@ -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,EA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,CAAC,EAAE,MAAM,GAAG,aAAa,CAa1H;AAED,kDAAkD;AAClD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,aAAa,CASzG;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAO7E;AAED,yCAAyC;AACzC,wBAAgB,OAAO,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,iBAAiB,GAAG,aAAa,CAEnF;AAED,kEAAkE;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,22 @@
|
|
|
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
|
+
const TASK_GRAPH_PORTS = [
|
|
30
|
+
{ ID: 'in', Direction: 'input', Side: 'top', Multiple: true },
|
|
31
|
+
{ ID: 'out', Direction: 'output', Side: 'bottom', Multiple: true },
|
|
32
|
+
];
|
|
33
|
+
/** What the palette offers — one entry per assignment shape the spec supports. */
|
|
20
34
|
export const TASK_GRAPH_NODE_TYPES = [
|
|
21
35
|
{
|
|
22
36
|
Type: 'AgentTask',
|
|
@@ -24,10 +38,15 @@ export const TASK_GRAPH_NODE_TYPES = [
|
|
|
24
38
|
Icon: 'fa-robot',
|
|
25
39
|
Color: '#4A6FA5',
|
|
26
40
|
Category: 'Steps',
|
|
27
|
-
DefaultPorts:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
41
|
+
DefaultPorts: TASK_GRAPH_PORTS,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
Type: 'ActionTask',
|
|
45
|
+
Label: 'Action Step',
|
|
46
|
+
Icon: 'fa-bolt',
|
|
47
|
+
Color: '#3B82F6',
|
|
48
|
+
Category: 'Steps',
|
|
49
|
+
DefaultPorts: TASK_GRAPH_PORTS,
|
|
31
50
|
},
|
|
32
51
|
{
|
|
33
52
|
Type: 'HumanTask',
|
|
@@ -35,12 +54,31 @@ export const TASK_GRAPH_NODE_TYPES = [
|
|
|
35
54
|
Icon: 'fa-user-check',
|
|
36
55
|
Color: '#7B1FA2',
|
|
37
56
|
Category: 'Steps',
|
|
38
|
-
DefaultPorts:
|
|
39
|
-
{ ID: 'in', Direction: 'input', Side: 'top', Multiple: true },
|
|
40
|
-
{ ID: 'out', Direction: 'output', Side: 'bottom', Multiple: true },
|
|
41
|
-
],
|
|
57
|
+
DefaultPorts: TASK_GRAPH_PORTS,
|
|
42
58
|
},
|
|
43
59
|
];
|
|
60
|
+
/**
|
|
61
|
+
* Everything the canvas can DEPICT: the palette, plus the kinds that only ever arrive from a run.
|
|
62
|
+
*
|
|
63
|
+
* Deliberately a superset rather than an extension of the palette — adding these to
|
|
64
|
+
* `TASK_GRAPH_NODE_TYPES` would put un-configurable entries in the authoring toolbox.
|
|
65
|
+
*/
|
|
66
|
+
export const TASK_GRAPH_RENDER_TYPES = [
|
|
67
|
+
...TASK_GRAPH_NODE_TYPES,
|
|
68
|
+
{ Type: 'PromptTask', Label: 'Prompt Step', Icon: 'fa-comment-dots', Color: '#8B5CF6', Category: 'Steps', DefaultPorts: TASK_GRAPH_PORTS },
|
|
69
|
+
{ Type: 'ForEachTask', Label: 'For Each Step', Icon: 'fa-repeat', Color: '#D97706', Category: 'Steps', DefaultPorts: TASK_GRAPH_PORTS },
|
|
70
|
+
{ Type: 'WhileTask', Label: 'While Step', Icon: 'fa-rotate', Color: '#D97706', Category: 'Steps', DefaultPorts: TASK_GRAPH_PORTS },
|
|
71
|
+
{ Type: 'ExternalTask', Label: 'External Step', Icon: 'fa-arrow-up-right-from-square', Color: '#0891B2', Category: 'Steps', DefaultPorts: TASK_GRAPH_PORTS },
|
|
72
|
+
];
|
|
73
|
+
/**
|
|
74
|
+
* The config for a node type, or null when the type is not one of ours.
|
|
75
|
+
*
|
|
76
|
+
* Searches the RENDER set, so a run's ForEach resolves to its own icon and label instead of
|
|
77
|
+
* silently falling back to the agent shape.
|
|
78
|
+
*/
|
|
79
|
+
export function GetNodeTypeConfig(type) {
|
|
80
|
+
return TASK_GRAPH_RENDER_TYPES.find((c) => c.Type === type) ?? null;
|
|
81
|
+
}
|
|
44
82
|
/**
|
|
45
83
|
* Maps a durable task state onto the canvas's visual vocabulary.
|
|
46
84
|
*
|
|
@@ -61,10 +99,70 @@ export function RuntimeStateToNodeStatus(state) {
|
|
|
61
99
|
default: return 'default';
|
|
62
100
|
}
|
|
63
101
|
}
|
|
64
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* True when the node is a person's step.
|
|
104
|
+
*
|
|
105
|
+
* One field decides it now: spec v2 gives every node exactly one `kind`, so "is this a person's
|
|
106
|
+
* step" stopped being an inference over three optional flags and became a comparison.
|
|
107
|
+
*/
|
|
65
108
|
export function IsHumanTask(node) {
|
|
66
|
-
return
|
|
109
|
+
return node.kind === 'Human';
|
|
67
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Which of the three shapes a node is, for rendering.
|
|
113
|
+
*
|
|
114
|
+
* An unassigned node (just added, nothing picked yet) reads as an agent step: it is the commonest
|
|
115
|
+
* intent, and the validator is already telling the author, in words, that it needs an assignee.
|
|
116
|
+
* Guessing "person" instead — which is what the old `!agentName` rule did — put a step in the
|
|
117
|
+
* graph that claimed to be waiting on someone when nobody had said so.
|
|
118
|
+
*/
|
|
119
|
+
export function GetTaskNodeType(node) {
|
|
120
|
+
switch (node.kind) {
|
|
121
|
+
case 'Human': return 'HumanTask';
|
|
122
|
+
case 'Action': return 'ActionTask';
|
|
123
|
+
case 'Prompt': return 'PromptTask';
|
|
124
|
+
case 'ForEach': return 'ForEachTask';
|
|
125
|
+
case 'While': return 'WhileTask';
|
|
126
|
+
case 'External': return 'ExternalTask';
|
|
127
|
+
// An unassigned node — just added, nothing picked — reads as an agent step: the commonest
|
|
128
|
+
// intent, and the validator is already saying in words that it needs an assignee.
|
|
129
|
+
default: return 'AgentTask';
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Builds the task a palette entry stands for.
|
|
134
|
+
*
|
|
135
|
+
* Pure, and here rather than in the component, because "what does clicking *Person Step* actually
|
|
136
|
+
* put in the graph" is a fact about the spec — testable without a TestBed, and the one place the
|
|
137
|
+
* assignment xor is honoured on creation.
|
|
138
|
+
*
|
|
139
|
+
* `defaultAgentName` / `defaultActionName` are what the host has to offer. When it has nothing, the
|
|
140
|
+
* step is created unassigned on purpose: inventing an agent name that may not exist would produce a
|
|
141
|
+
* graph that passes the canvas and fails at submission, whereas an unassigned step is reported
|
|
142
|
+
* immediately by the same validator the engine runs.
|
|
143
|
+
*/
|
|
144
|
+
export function NewTaskFromNodeType(spec, type, defaults = {}) {
|
|
145
|
+
const base = {
|
|
146
|
+
tempId: NextTempId(spec),
|
|
147
|
+
name: NEW_TASK_NAMES[type],
|
|
148
|
+
description: '',
|
|
149
|
+
dependsOn: [],
|
|
150
|
+
};
|
|
151
|
+
switch (type) {
|
|
152
|
+
case 'HumanTask': return TaskNode.Human(base);
|
|
153
|
+
// A step created before the host has any names to offer is created with an empty one on
|
|
154
|
+
// purpose: the validator reports it immediately, whereas inventing a name would produce a
|
|
155
|
+
// graph that passes here and fails at submission.
|
|
156
|
+
case 'ActionTask': return TaskNode.Action(base, { actionName: defaults.actionName ?? '' });
|
|
157
|
+
default: return TaskNode.Agent(base, { agentName: defaults.agentName ?? '' });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/** Default step names, so a new box says what it is before the author renames it. */
|
|
161
|
+
const NEW_TASK_NAMES = {
|
|
162
|
+
AgentTask: 'New agent step',
|
|
163
|
+
ActionTask: 'New action step',
|
|
164
|
+
HumanTask: 'New person step',
|
|
165
|
+
};
|
|
68
166
|
/** Entry points: nodes nothing else has to finish first. Same rule the traversal engine uses. */
|
|
69
167
|
export function GetEntryTempIds(spec) {
|
|
70
168
|
return (spec.tasks ?? []).filter((t) => (t.dependsOn ?? []).length === 0).map((t) => t.tempId);
|
|
@@ -90,20 +188,30 @@ function edgeId(fromTempId, toTempId) {
|
|
|
90
188
|
* geometry precisely because a task graph is a *logical* structure. An agent that emitted one never
|
|
91
189
|
* had an opinion about where the boxes go.
|
|
92
190
|
*/
|
|
93
|
-
|
|
191
|
+
/**
|
|
192
|
+
* Projects the spec onto canvas nodes.
|
|
193
|
+
*
|
|
194
|
+
* `positions` carries geometry the spec cannot hold. `TaskGraphSpec` is an execution contract with
|
|
195
|
+
* no layout field, so without a caller-held map every re-projection would return every node to the
|
|
196
|
+
* origin — which is what previously forced a full re-arrange (and a viewport re-zoom) after every
|
|
197
|
+
* single edit. Unknown ids fall back to the origin, which is also the correct starting state for a
|
|
198
|
+
* graph that has never been laid out.
|
|
199
|
+
*/
|
|
200
|
+
export function SpecToNodes(spec, runtime, positions) {
|
|
94
201
|
const entryIds = new Set(GetEntryTempIds(spec));
|
|
95
202
|
return (spec.tasks ?? []).map((task) => {
|
|
96
|
-
const
|
|
203
|
+
const type = GetTaskNodeType(task);
|
|
204
|
+
const known = positions?.get(task.tempId);
|
|
97
205
|
return {
|
|
98
206
|
ID: task.tempId,
|
|
99
|
-
Type:
|
|
207
|
+
Type: type,
|
|
100
208
|
Label: task.name,
|
|
101
|
-
Subtitle:
|
|
102
|
-
Icon:
|
|
209
|
+
Subtitle: TaskSubtitle(task, type),
|
|
210
|
+
Icon: GetNodeTypeConfig(type)?.Icon ?? 'fa-circle-nodes',
|
|
103
211
|
Status: RuntimeStateToNodeStatus(runtime?.[task.tempId]),
|
|
104
212
|
StatusMessage: task.description,
|
|
105
213
|
IsStartNode: entryIds.has(task.tempId),
|
|
106
|
-
Position: { X: 0, Y: 0 },
|
|
214
|
+
Position: known ? { ...known } : { X: 0, Y: 0 },
|
|
107
215
|
Ports: [
|
|
108
216
|
{ ID: 'in', Direction: 'input', Side: 'top', Multiple: true },
|
|
109
217
|
{ ID: 'out', Direction: 'output', Side: 'bottom', Multiple: true },
|
|
@@ -112,6 +220,34 @@ export function SpecToNodes(spec, runtime) {
|
|
|
112
220
|
};
|
|
113
221
|
});
|
|
114
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* The one line under a node's name: who or what runs it.
|
|
225
|
+
*
|
|
226
|
+
* An unassigned step says so rather than showing nothing — a blank subtitle looks like a step that
|
|
227
|
+
* is fine, and this one is the reason the validation banner is complaining.
|
|
228
|
+
*/
|
|
229
|
+
export function TaskSubtitle(task, type = GetTaskNodeType(task)) {
|
|
230
|
+
switch (type) {
|
|
231
|
+
case 'HumanTask': return 'Waiting on a person';
|
|
232
|
+
case 'ActionTask': return ConfigOf(task, 'Action')?.actionName || 'No action chosen yet';
|
|
233
|
+
case 'PromptTask': return ConfigOf(task, 'Prompt')?.promptName || 'No prompt chosen yet';
|
|
234
|
+
// A loop's subtitle is what it REPEATS — the one fact that makes the node readable.
|
|
235
|
+
case 'ForEachTask': return LoopBodyLabel(ConfigOf(task, 'ForEach')) ?? 'Repeats for each item';
|
|
236
|
+
case 'WhileTask': return LoopBodyLabel(ConfigOf(task, 'While')) ?? 'Repeats until its condition is false';
|
|
237
|
+
case 'ExternalTask': return ConfigOf(task, 'External')?.domain || 'Completed by an outside system';
|
|
238
|
+
// Only a genuinely unassigned node reaches this now. It used to catch Prompt, ForEach,
|
|
239
|
+
// While and External too — so a fully-configured loop displayed "No agent chosen yet",
|
|
240
|
+
// which reads as a broken step rather than an unrecognised one.
|
|
241
|
+
default: return ConfigOf(task, 'Agent')?.agentName || 'No agent chosen yet';
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/** What a loop repeats, when it says. */
|
|
245
|
+
function LoopBodyLabel(op) {
|
|
246
|
+
if (!op)
|
|
247
|
+
return null;
|
|
248
|
+
const body = op.action?.name ?? op.subAgent?.name ?? op.prompt?.name;
|
|
249
|
+
return body ? `Repeats: ${body}` : null;
|
|
250
|
+
}
|
|
115
251
|
/**
|
|
116
252
|
* Projects the spec's dependencies onto canvas connections, reversing their direction.
|
|
117
253
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-graph-canvas-adapter.js","sourceRoot":"","sources":["../../src/lib/task-graph-canvas-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EACH,mBAAmB,GAItB,MAAM,8BAA8B,CAAC;AAGtC,6FAA6F;AAC7F,MAAM,CAAC,MAAM,qBAAqB,GAAyB;IACvD;QACI,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,YAAY;QACnB,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,SAAS;QAChB,QAAQ,EAAE,OAAO;QACjB,YAAY,EAAE;YACV,EAAE,EAAE,EAAE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verview Projects a `TaskGraphSpec` onto the generic canvas shapes, and back.\n *\n * **Kept pure and separate from the component on purpose.** Everything interesting about rendering a\n * task graph — which node is an entry point, which edge is conditional, how a runtime status maps to\n * a visual one, whether removing a node orphans an edge — is decidable from data alone. Putting it\n * in a component would make it reachable only through a TestBed, and the resulting tests would be\n * about Angular rather than about graphs.\n *\n * **The direction flip, again.** A `TaskGraphSpec` edge points *backwards* (`dependsOn`: \"I wait for\n * X\"); a canvas connection points *forwards* (source → target). Same edge, opposite authoring\n * convention — the graph is written by whoever knows the prerequisites, the canvas drawn by whoever\n * follows the arrows. This is the second place in the program that inversion appears (Save as\n * Workflow is the first), which is why it is stated rather than left implicit.\n *\n * @module @memberjunction/ng-task-graph-editor\n */\nimport {\n NormalizeDependency,\n type TaskGraphSpec,\n type TaskGraphSpecNode,\n type TaskGraphDependency,\n} from '@memberjunction/ai-core-plus';\nimport type { FlowConnection, FlowNode, FlowNodeStatus, FlowNodeTypeConfig } from '@memberjunction/ng-flow-editor';\n\n/** Node types the palette offers. Two, because a task is either an agent's or a person's. */\nexport const TASK_GRAPH_NODE_TYPES: FlowNodeTypeConfig[] = [\n {\n Type: 'AgentTask',\n Label: 'Agent Step',\n Icon: 'fa-robot',\n Color: '#4A6FA5',\n Category: 'Steps',\n DefaultPorts: [\n { ID: 'in', Direction: 'input', Side: 'top', Multiple: true },\n { ID: 'out', Direction: 'output', Side: 'bottom', Multiple: true },\n ],\n },\n {\n Type: 'HumanTask',\n Label: 'Person Step',\n Icon: 'fa-user-check',\n Color: '#7B1FA2',\n Category: 'Steps',\n DefaultPorts: [\n { ID: 'in', Direction: 'input', Side: 'top', Multiple: true },\n { ID: 'out', Direction: 'output', Side: 'bottom', Multiple: true },\n ],\n },\n];\n\n/** Live per-task state for the runtime overlay, keyed by `tempId`. */\nexport type TaskGraphRuntimeStatus = Record<string, TaskGraphRuntimeState>;\n\n/** What a task is doing right now, in the durable engine's own vocabulary. */\nexport type TaskGraphRuntimeState =\n | 'Pending'\n | 'In Progress'\n | 'Complete'\n | 'Failed'\n | 'Blocked'\n | 'Cancelled'\n | 'Deferred';\n\n/**\n * Maps a durable task state onto the canvas's visual vocabulary.\n *\n * Two mappings are worth explaining. `Blocked` renders as a **warning**, not an error: nothing went\n * wrong, the graph simply cannot reach it — showing it as a failure would send someone hunting for a\n * bug that does not exist. `Deferred` renders as `pending` because, to the person watching, waiting\n * on a schedule and waiting on a prerequisite look and mean the same thing.\n */\nexport function RuntimeStateToNodeStatus(state: TaskGraphRuntimeState | undefined): FlowNodeStatus {\n switch (state) {\n case 'In Progress': return 'running';\n case 'Complete': return 'success';\n case 'Failed': return 'error';\n case 'Blocked': return 'warning';\n case 'Cancelled': return 'disabled';\n case 'Deferred': return 'pending';\n case 'Pending': return 'pending';\n default: return 'default';\n }\n}\n\n/** True when the node is a person's step rather than an agent's. */\nexport function IsHumanTask(node: TaskGraphSpecNode): boolean {\n return !node.agentName;\n}\n\n/** Entry points: nodes nothing else has to finish first. Same rule the traversal engine uses. */\nexport function GetEntryTempIds(spec: TaskGraphSpec): string[] {\n return (spec.tasks ?? []).filter((t) => (t.dependsOn ?? []).length === 0).map((t) => t.tempId);\n}\n\n/** Every dependency of a node, in normalized object form. */\nexport function GetDependencies(node: TaskGraphSpecNode): TaskGraphDependency[] {\n return (node.dependsOn ?? []).map(NormalizeDependency);\n}\n\n/** The `tempId`s that depend on `tempId` — i.e. what breaks if it is removed. */\nexport function GetDependents(spec: TaskGraphSpec, tempId: string): string[] {\n return (spec.tasks ?? [])\n .filter((t) => GetDependencies(t).some((d) => d.tempId === tempId))\n .map((t) => t.tempId);\n}\n\n/** Deterministic id for a canvas edge, so re-renders don't churn selection. */\nfunction edgeId(fromTempId: string, toTempId: string): string {\n return `${fromTempId}->${toTempId}`;\n}\n\n/**\n * Projects the spec onto canvas nodes.\n *\n * Positions are left at the origin: layout is the canvas's job (Dagre), and a spec carries no\n * geometry precisely because a task graph is a *logical* structure. An agent that emitted one never\n * had an opinion about where the boxes go.\n */\nexport function SpecToNodes(spec: TaskGraphSpec, runtime?: TaskGraphRuntimeStatus): FlowNode[] {\n const entryIds = new Set(GetEntryTempIds(spec));\n\n return (spec.tasks ?? []).map((task) => {\n const human = IsHumanTask(task);\n return {\n ID: task.tempId,\n Type: human ? 'HumanTask' : 'AgentTask',\n Label: task.name,\n Subtitle: human ? 'Waiting on a person' : task.agentName,\n Icon: human ? 'fa-user-check' : 'fa-robot',\n Status: RuntimeStateToNodeStatus(runtime?.[task.tempId]),\n StatusMessage: task.description,\n IsStartNode: entryIds.has(task.tempId),\n Position: { X: 0, Y: 0 },\n Ports: [\n { ID: 'in', Direction: 'input', Side: 'top', Multiple: true },\n { ID: 'out', Direction: 'output', Side: 'bottom', Multiple: true },\n ],\n Data: { TempId: task.tempId },\n };\n });\n}\n\n/**\n * Projects the spec's dependencies onto canvas connections, reversing their direction.\n *\n * A conditional edge is drawn dashed and labeled with its condition, because the difference between\n * \"always\" and \"only sometimes\" is the single most consequential thing about an edge and the one a\n * reader is most likely to miss when scanning a diagram.\n *\n * Edges naming a task that is not in the graph are skipped rather than drawn dangling — the\n * validator reports them as `UnknownDependency`, and rendering a connection to nowhere would be a\n * second, worse way of saying the same thing.\n */\nexport function SpecToConnections(spec: TaskGraphSpec): FlowConnection[] {\n const known = new Set((spec.tasks ?? []).map((t) => t.tempId));\n const connections: FlowConnection[] = [];\n\n for (const task of spec.tasks ?? []) {\n for (const dep of GetDependencies(task)) {\n if (!known.has(dep.tempId)) continue;\n\n const conditional = !!dep.condition?.trim();\n connections.push({\n ID: edgeId(dep.tempId, task.tempId),\n // Reversed: dependsOn points back at the prerequisite, the drawn arrow points forward.\n SourceNodeID: dep.tempId,\n SourcePortID: 'out',\n TargetNodeID: task.tempId,\n TargetPortID: 'in',\n Label: conditional ? 'if' : undefined,\n LabelDetail: dep.condition ?? undefined,\n LabelIcon: conditional ? 'fa-code-branch' : undefined,\n Condition: dep.condition ?? undefined,\n Style: conditional ? 'dashed' : 'solid',\n Data: { FromTempId: dep.tempId, ToTempId: task.tempId },\n });\n }\n }\n return connections;\n}\n\n/**\n * Adds a dependency to the spec, returning a NEW spec.\n *\n * Immutable because the component emits the result to a host that may keep it, diff it, or reject\n * it; mutating the input would let a canceled edit leak into the host's copy anyway. A duplicate\n * edge is a no-op rather than an error — dragging the same connection twice is a slip, not a\n * request to corrupt the graph.\n */\nexport function AddDependency(spec: TaskGraphSpec, fromTempId: string, toTempId: string, condition?: string): TaskGraphSpec {\n return {\n ...spec,\n tasks: (spec.tasks ?? []).map((task) => {\n if (task.tempId !== toTempId) return task;\n const existing = GetDependencies(task);\n if (existing.some((d) => d.tempId === fromTempId)) return task;\n const next: TaskGraphDependency | string = condition?.trim()\n ? { tempId: fromTempId, condition }\n : fromTempId;\n return { ...task, dependsOn: [...(task.dependsOn ?? []), next] };\n }),\n };\n}\n\n/** Removes a dependency, returning a NEW spec. */\nexport function RemoveDependency(spec: TaskGraphSpec, fromTempId: string, toTempId: string): TaskGraphSpec {\n return {\n ...spec,\n tasks: (spec.tasks ?? []).map((task) =>\n task.tempId !== toTempId\n ? task\n : { ...task, dependsOn: (task.dependsOn ?? []).filter((d) => NormalizeDependency(d).tempId !== fromTempId) },\n ),\n };\n}\n\n/**\n * Removes a task AND every edge into it, returning a NEW spec.\n *\n * Severing the inbound edges is not a convenience — leaving them would produce a graph whose\n * `dependsOn` names a task that no longer exists, which the validator rejects as\n * `UnknownDependency`. Deleting a box on a canvas should not make the graph invalid.\n */\nexport function RemoveTask(spec: TaskGraphSpec, tempId: string): TaskGraphSpec {\n return {\n ...spec,\n tasks: (spec.tasks ?? [])\n .filter((t) => t.tempId !== tempId)\n .map((t) => ({ ...t, dependsOn: (t.dependsOn ?? []).filter((d) => NormalizeDependency(d).tempId !== tempId) })),\n };\n}\n\n/** Adds a task, returning a NEW spec. */\nexport function AddTask(spec: TaskGraphSpec, task: TaskGraphSpecNode): TaskGraphSpec {\n return { ...spec, tasks: [...(spec.tasks ?? []), task] };\n}\n\n/** Replaces a task in place by `tempId`, returning a NEW spec. */\nexport function UpdateTask(spec: TaskGraphSpec, tempId: string, next: TaskGraphSpecNode): TaskGraphSpec {\n return { ...spec, tasks: (spec.tasks ?? []).map((t) => (t.tempId === tempId ? next : t)) };\n}\n\n/**\n * Would adding `from → to` create a cycle?\n *\n * Answered before the edge exists, so the canvas can refuse it rather than create an invalid graph\n * and report it afterwards. A self-edge is the degenerate case and is caught first.\n *\n * Iterative rather than recursive: the graph may come from an LLM, and a deeply-chained spec should\n * produce a refusal, not a stack overflow.\n */\nexport function WouldCreateCycle(spec: TaskGraphSpec, fromTempId: string, toTempId: string): boolean {\n if (fromTempId === toTempId) return true;\n\n // A cycle appears iff `from` is already reachable from `to` by following dependsOn edges —\n // i.e. `to` already (transitively) waits on `from`.\n const dependenciesOf = new Map<string, string[]>(\n (spec.tasks ?? []).map((t) => [t.tempId, GetDependencies(t).map((d) => d.tempId)]),\n );\n\n const stack = [...(dependenciesOf.get(fromTempId) ?? [])];\n const seen = new Set<string>();\n while (stack.length > 0) {\n const current = stack.pop()!;\n if (current === toTempId) return true;\n if (seen.has(current)) continue;\n seen.add(current);\n stack.push(...(dependenciesOf.get(current) ?? []));\n }\n return false;\n}\n\n/** A unique `tempId` for a newly added task, stable and readable. */\nexport function NextTempId(spec: TaskGraphSpec, prefix = 'task'): string {\n const taken = new Set((spec.tasks ?? []).map((t) => t.tempId));\n let n = (spec.tasks ?? []).length + 1;\n while (taken.has(`${prefix}${n}`)) n++;\n return `${prefix}${n}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"task-graph-canvas-adapter.js","sourceRoot":"","sources":["../../src/lib/task-graph-canvas-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EACH,QAAQ,EACR,mBAAmB,EACnB,QAAQ,GAKX,MAAM,8BAA8B,CAAC;AA6BtC;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAyB;IAC1D,OAAO,I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AC;IACtC,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC;QAAE,CAAC,EAAE,CAAC;IACvC,OAAO,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC;AAC3B,CAAC","sourcesContent":["/**\n * @fileoverview Projects a `TaskGraphSpec` onto the generic canvas shapes, and back.\n *\n * **Kept pure and separate from the component on purpose.** Everything interesting about rendering a\n * task graph — which node is an entry point, which edge is conditional, how a runtime status maps to\n * a visual one, whether removing a node orphans an edge — is decidable from data alone. Putting it\n * in a component would make it reachable only through a TestBed, and the resulting tests would be\n * about Angular rather than about graphs.\n *\n * **The direction flip, again.** A `TaskGraphSpec` edge points *backwards* (`dependsOn`: \"I wait for\n * X\"); a canvas connection points *forwards* (source → target). Same edge, opposite authoring\n * convention — the graph is written by whoever knows the prerequisites, the canvas drawn by whoever\n * follows the arrows. This is the second place in the program that inversion appears (Save as\n * Workflow is the first), which is why it is stated rather than left implicit.\n *\n * @module @memberjunction/ng-task-graph-editor\n */\nimport {\n ConfigOf,\n NormalizeDependency,\n TaskNode,\n type TaskNodeBase,\n type TaskGraphSpec,\n type TaskGraphSpecNode,\n type TaskGraphDependency,\n} from '@memberjunction/ai-core-plus';\nimport type { FlowConnection, FlowNode, FlowNodeStatus, FlowNodeTypeConfig, FlowPosition } from '@memberjunction/ng-flow-editor';\n\n/**\n * The shapes this canvas can DRAW.\n *\n * Three of the spec's seven `kind`s, and the choice is the canvas's: these are the shapes a person\n * authors. `Prompt`, `ForEach`, `While` and `External` are expressible in the spec but have no\n * authoring affordance here — a palette entry that cannot be configured would be worse than none.\n *\n * **Drawing and RENDERING are different questions**, which this type used to conflate. A run's\n * graph is displayed on the same canvas, and it contains kinds nobody can draw — so mapping them\n * all to `AgentTask` made a fully-configured ForEach render as \"AGENT STEP · No agent chosen yet\",\n * which is not merely imprecise: it says the step is broken. See {@link TaskGraphRenderType}.\n */\nexport type TaskGraphNodeType = 'AgentTask' | 'ActionTask' | 'HumanTask';\n\n/**\n * The shapes this canvas can SHOW — a superset of what it can draw.\n *\n * Display-only kinds exist because a task graph is rendered in two places: the editor, where a\n * person builds one, and a run view, where one that already ran is shown. The second must be able\n * to depict every kind the dispatcher can execute, whether or not the palette offers it.\n */\nexport type TaskGraphRenderType = TaskGraphNodeType | 'PromptTask' | 'ForEachTask' | 'WhileTask' | 'ExternalTask';\n\n/** A palette entry, pinned to one of the three authorable shapes. */\nexport type TaskGraphNodeTypeConfig = FlowNodeTypeConfig & { Type: TaskGraphNodeType };\n\n/**\n * Whether a shape is one a person can actually author here.\n *\n * The authoring paths — the palette, `NewTaskFromNodeType`, the properties panel — only handle the\n * three drawable shapes. Rendering handles more. This is the seam between the two, stated as a type\n * guard so the compiler enforces it rather than a cast pretending the distinction does not exist.\n */\nexport function IsAuthorableNodeType(type: TaskGraphRenderType): type is TaskGraphNodeType {\n return type === 'AgentTask' || type === 'ActionTask' || type === 'HumanTask';\n}\n\n/** A rendering entry — every shape the canvas can depict, authorable or not. */\nexport type TaskGraphRenderTypeConfig = FlowNodeTypeConfig & { Type: TaskGraphRenderType };\n\nconst TASK_GRAPH_PORTS: FlowNodeTypeConfig['DefaultPorts'] = [\n { ID: 'in', Direction: 'input', Side: 'top', Multiple: true },\n { ID: 'out', Direction: 'output', Side: 'bottom', Multiple: true },\n];\n\n/** What the palette offers — one entry per assignment shape the spec supports. */\nexport const TASK_GRAPH_NODE_TYPES: readonly TaskGraphNodeTypeConfig[] = [\n {\n Type: 'AgentTask',\n Label: 'Agent Step',\n Icon: 'fa-robot',\n Color: '#4A6FA5',\n Category: 'Steps',\n DefaultPorts: TASK_GRAPH_PORTS,\n },\n {\n Type: 'ActionTask',\n Label: 'Action Step',\n Icon: 'fa-bolt',\n Color: '#3B82F6',\n Category: 'Steps',\n DefaultPorts: TASK_GRAPH_PORTS,\n },\n {\n Type: 'HumanTask',\n Label: 'Person Step',\n Icon: 'fa-user-check',\n Color: '#7B1FA2',\n Category: 'Steps',\n DefaultPorts: TASK_GRAPH_PORTS,\n },\n];\n\n/**\n * Everything the canvas can DEPICT: the palette, plus the kinds that only ever arrive from a run.\n *\n * Deliberately a superset rather than an extension of the palette — adding these to\n * `TASK_GRAPH_NODE_TYPES` would put un-configurable entries in the authoring toolbox.\n */\nexport const TASK_GRAPH_RENDER_TYPES: readonly TaskGraphRenderTypeConfig[] = [\n ...TASK_GRAPH_NODE_TYPES,\n { Type: 'PromptTask', Label: 'Prompt Step', Icon: 'fa-comment-dots', Color: '#8B5CF6', Category: 'Steps', DefaultPorts: TASK_GRAPH_PORTS },\n { Type: 'ForEachTask', Label: 'For Each Step', Icon: 'fa-repeat', Color: '#D97706', Category: 'Steps', DefaultPorts: TASK_GRAPH_PORTS },\n { Type: 'WhileTask', Label: 'While Step', Icon: 'fa-rotate', Color: '#D97706', Category: 'Steps', DefaultPorts: TASK_GRAPH_PORTS },\n { Type: 'ExternalTask', Label: 'External Step', Icon: 'fa-arrow-up-right-from-square', Color: '#0891B2', Category: 'Steps', DefaultPorts: TASK_GRAPH_PORTS },\n];\n\n/**\n * The config for a node type, or null when the type is not one of ours.\n *\n * Searches the RENDER set, so a run's ForEach resolves to its own icon and label instead of\n * silently falling back to the agent shape.\n */\nexport function GetNodeTypeConfig(type: string): TaskGraphRenderTypeConfig | null {\n return TASK_GRAPH_RENDER_TYPES.find((c) => c.Type === type) ?? null;\n}\n\n/** Live per-task state for the runtime overlay, keyed by `tempId`. */\nexport type TaskGraphRuntimeStatus = Record<string, TaskGraphRuntimeState>;\n\n/** What a task is doing right now, in the durable engine's own vocabulary. */\nexport type TaskGraphRuntimeState =\n | 'Pending'\n | 'In Progress'\n | 'Complete'\n | 'Failed'\n | 'Blocked'\n | 'Cancelled'\n | 'Deferred';\n\n/**\n * Maps a durable task state onto the canvas's visual vocabulary.\n *\n * Two mappings are worth explaining. `Blocked` renders as a **warning**, not an error: nothing went\n * wrong, the graph simply cannot reach it — showing it as a failure would send someone hunting for a\n * bug that does not exist. `Deferred` renders as `pending` because, to the person watching, waiting\n * on a schedule and waiting on a prerequisite look and mean the same thing.\n */\nexport function RuntimeStateToNodeStatus(state: TaskGraphRuntimeState | undefined): FlowNodeStatus {\n switch (state) {\n case 'In Progress': return 'running';\n case 'Complete': return 'success';\n case 'Failed': return 'error';\n case 'Blocked': return 'warning';\n case 'Cancelled': return 'disabled';\n case 'Deferred': return 'pending';\n case 'Pending': return 'pending';\n default: return 'default';\n }\n}\n\n/**\n * True when the node is a person's step.\n *\n * One field decides it now: spec v2 gives every node exactly one `kind`, so \"is this a person's\n * step\" stopped being an inference over three optional flags and became a comparison.\n */\nexport function IsHumanTask(node: TaskGraphSpecNode): boolean {\n return node.kind === 'Human';\n}\n\n/**\n * Which of the three shapes a node is, for rendering.\n *\n * An unassigned node (just added, nothing picked yet) reads as an agent step: it is the commonest\n * intent, and the validator is already telling the author, in words, that it needs an assignee.\n * Guessing \"person\" instead — which is what the old `!agentName` rule did — put a step in the\n * graph that claimed to be waiting on someone when nobody had said so.\n */\nexport function GetTaskNodeType(node: TaskGraphSpecNode): TaskGraphRenderType {\n switch (node.kind) {\n case 'Human': return 'HumanTask';\n case 'Action': return 'ActionTask';\n case 'Prompt': return 'PromptTask';\n case 'ForEach': return 'ForEachTask';\n case 'While': return 'WhileTask';\n case 'External': return 'ExternalTask';\n // An unassigned node — just added, nothing picked — reads as an agent step: the commonest\n // intent, and the validator is already saying in words that it needs an assignee.\n default: return 'AgentTask';\n }\n}\n\n/**\n * Builds the task a palette entry stands for.\n *\n * Pure, and here rather than in the component, because \"what does clicking *Person Step* actually\n * put in the graph\" is a fact about the spec — testable without a TestBed, and the one place the\n * assignment xor is honoured on creation.\n *\n * `defaultAgentName` / `defaultActionName` are what the host has to offer. When it has nothing, the\n * step is created unassigned on purpose: inventing an agent name that may not exist would produce a\n * graph that passes the canvas and fails at submission, whereas an unassigned step is reported\n * immediately by the same validator the engine runs.\n */\nexport function NewTaskFromNodeType(\n spec: TaskGraphSpec,\n type: TaskGraphNodeType,\n defaults: { agentName?: string; actionName?: string } = {},\n): TaskGraphSpecNode {\n const base: TaskNodeBase = {\n tempId: NextTempId(spec),\n name: NEW_TASK_NAMES[type],\n description: '',\n dependsOn: [],\n };\n switch (type) {\n case 'HumanTask': return TaskNode.Human(base);\n // A step created before the host has any names to offer is created with an empty one on\n // purpose: the validator reports it immediately, whereas inventing a name would produce a\n // graph that passes here and fails at submission.\n case 'ActionTask': return TaskNode.Action(base, { actionName: defaults.actionName ?? '' });\n default: return TaskNode.Agent(base, { agentName: defaults.agentName ?? '' });\n }\n}\n\n/** Default step names, so a new box says what it is before the author renames it. */\nconst NEW_TASK_NAMES: Record<TaskGraphNodeType, string> = {\n AgentTask: 'New agent step',\n ActionTask: 'New action step',\n HumanTask: 'New person step',\n};\n\n/** Entry points: nodes nothing else has to finish first. Same rule the traversal engine uses. */\nexport function GetEntryTempIds(spec: TaskGraphSpec): string[] {\n return (spec.tasks ?? []).filter((t) => (t.dependsOn ?? []).length === 0).map((t) => t.tempId);\n}\n\n/** Every dependency of a node, in normalized object form. */\nexport function GetDependencies(node: TaskGraphSpecNode): TaskGraphDependency[] {\n return (node.dependsOn ?? []).map(NormalizeDependency);\n}\n\n/** The `tempId`s that depend on `tempId` — i.e. what breaks if it is removed. */\nexport function GetDependents(spec: TaskGraphSpec, tempId: string): string[] {\n return (spec.tasks ?? [])\n .filter((t) => GetDependencies(t).some((d) => d.tempId === tempId))\n .map((t) => t.tempId);\n}\n\n/** Deterministic id for a canvas edge, so re-renders don't churn selection. */\nfunction edgeId(fromTempId: string, toTempId: string): string {\n return `${fromTempId}->${toTempId}`;\n}\n\n/**\n * Projects the spec onto canvas nodes.\n *\n * Positions are left at the origin: layout is the canvas's job (Dagre), and a spec carries no\n * geometry precisely because a task graph is a *logical* structure. An agent that emitted one never\n * had an opinion about where the boxes go.\n */\n/**\n * Projects the spec onto canvas nodes.\n *\n * `positions` carries geometry the spec cannot hold. `TaskGraphSpec` is an execution contract with\n * no layout field, so without a caller-held map every re-projection would return every node to the\n * origin — which is what previously forced a full re-arrange (and a viewport re-zoom) after every\n * single edit. Unknown ids fall back to the origin, which is also the correct starting state for a\n * graph that has never been laid out.\n */\nexport function SpecToNodes(\n spec: TaskGraphSpec,\n runtime?: TaskGraphRuntimeStatus,\n positions?: ReadonlyMap<string, FlowPosition>,\n): FlowNode[] {\n const entryIds = new Set(GetEntryTempIds(spec));\n\n return (spec.tasks ?? []).map((task) => {\n const type = GetTaskNodeType(task);\n const known = positions?.get(task.tempId);\n return {\n ID: task.tempId,\n Type: type,\n Label: task.name,\n Subtitle: TaskSubtitle(task, type),\n Icon: GetNodeTypeConfig(type)?.Icon ?? 'fa-circle-nodes',\n Status: RuntimeStateToNodeStatus(runtime?.[task.tempId]),\n StatusMessage: task.description,\n IsStartNode: entryIds.has(task.tempId),\n Position: known ? { ...known } : { X: 0, Y: 0 },\n Ports: [\n { ID: 'in', Direction: 'input', Side: 'top', Multiple: true },\n { ID: 'out', Direction: 'output', Side: 'bottom', Multiple: true },\n ],\n Data: { TempId: task.tempId },\n };\n });\n}\n\n/**\n * The one line under a node's name: who or what runs it.\n *\n * An unassigned step says so rather than showing nothing — a blank subtitle looks like a step that\n * is fine, and this one is the reason the validation banner is complaining.\n */\nexport function TaskSubtitle(task: TaskGraphSpecNode, type: TaskGraphRenderType = GetTaskNodeType(task)): string {\n switch (type) {\n case 'HumanTask': return 'Waiting on a person';\n case 'ActionTask': return ConfigOf(task, 'Action')?.actionName || 'No action chosen yet';\n case 'PromptTask': return ConfigOf(task, 'Prompt')?.promptName || 'No prompt chosen yet';\n // A loop's subtitle is what it REPEATS — the one fact that makes the node readable.\n case 'ForEachTask': return LoopBodyLabel(ConfigOf(task, 'ForEach')) ?? 'Repeats for each item';\n case 'WhileTask': return LoopBodyLabel(ConfigOf(task, 'While')) ?? 'Repeats until its condition is false';\n case 'ExternalTask': return ConfigOf(task, 'External')?.domain || 'Completed by an outside system';\n // Only a genuinely unassigned node reaches this now. It used to catch Prompt, ForEach,\n // While and External too — so a fully-configured loop displayed \"No agent chosen yet\",\n // which reads as a broken step rather than an unrecognised one.\n default: return ConfigOf(task, 'Agent')?.agentName || 'No agent chosen yet';\n }\n}\n\n/** What a loop repeats, when it says. */\nfunction LoopBodyLabel(\n op: { action?: { name: string }; subAgent?: { name: string }; prompt?: { name: string } } | null | undefined,\n): string | null {\n if (!op) return null;\n const body = op.action?.name ?? op.subAgent?.name ?? op.prompt?.name;\n return body ? `Repeats: ${body}` : null;\n}\n\n/**\n * Projects the spec's dependencies onto canvas connections, reversing their direction.\n *\n * A conditional edge is drawn dashed and labeled with its condition, because the difference between\n * \"always\" and \"only sometimes\" is the single most consequential thing about an edge and the one a\n * reader is most likely to miss when scanning a diagram.\n *\n * Edges naming a task that is not in the graph are skipped rather than drawn dangling — the\n * validator reports them as `UnknownDependency`, and rendering a connection to nowhere would be a\n * second, worse way of saying the same thing.\n */\nexport function SpecToConnections(spec: TaskGraphSpec): FlowConnection[] {\n const known = new Set((spec.tasks ?? []).map((t) => t.tempId));\n const connections: FlowConnection[] = [];\n\n for (const task of spec.tasks ?? []) {\n for (const dep of GetDependencies(task)) {\n if (!known.has(dep.tempId)) continue;\n\n const conditional = !!dep.condition?.trim();\n connections.push({\n ID: edgeId(dep.tempId, task.tempId),\n // Reversed: dependsOn points back at the prerequisite, the drawn arrow points forward.\n SourceNodeID: dep.tempId,\n SourcePortID: 'out',\n TargetNodeID: task.tempId,\n TargetPortID: 'in',\n Label: conditional ? 'if' : undefined,\n LabelDetail: dep.condition ?? undefined,\n LabelIcon: conditional ? 'fa-code-branch' : undefined,\n Condition: dep.condition ?? undefined,\n Style: conditional ? 'dashed' : 'solid',\n Data: { FromTempId: dep.tempId, ToTempId: task.tempId },\n });\n }\n }\n return connections;\n}\n\n/**\n * Adds a dependency to the spec, returning a NEW spec.\n *\n * Immutable because the component emits the result to a host that may keep it, diff it, or reject\n * it; mutating the input would let a canceled edit leak into the host's copy anyway. A duplicate\n * edge is a no-op rather than an error — dragging the same connection twice is a slip, not a\n * request to corrupt the graph.\n */\nexport function AddDependency(spec: TaskGraphSpec, fromTempId: string, toTempId: string, condition?: string): TaskGraphSpec {\n return {\n ...spec,\n tasks: (spec.tasks ?? []).map((task) => {\n if (task.tempId !== toTempId) return task;\n const existing = GetDependencies(task);\n if (existing.some((d) => d.tempId === fromTempId)) return task;\n const next: TaskGraphDependency | string = condition?.trim()\n ? { tempId: fromTempId, condition }\n : fromTempId;\n return { ...task, dependsOn: [...(task.dependsOn ?? []), next] };\n }),\n };\n}\n\n/** Removes a dependency, returning a NEW spec. */\nexport function RemoveDependency(spec: TaskGraphSpec, fromTempId: string, toTempId: string): TaskGraphSpec {\n return {\n ...spec,\n tasks: (spec.tasks ?? []).map((task) =>\n task.tempId !== toTempId\n ? task\n : { ...task, dependsOn: (task.dependsOn ?? []).filter((d) => NormalizeDependency(d).tempId !== fromTempId) },\n ),\n };\n}\n\n/**\n * Removes a task AND every edge into it, returning a NEW spec.\n *\n * Severing the inbound edges is not a convenience — leaving them would produce a graph whose\n * `dependsOn` names a task that no longer exists, which the validator rejects as\n * `UnknownDependency`. Deleting a box on a canvas should not make the graph invalid.\n */\nexport function RemoveTask(spec: TaskGraphSpec, tempId: string): TaskGraphSpec {\n return {\n ...spec,\n tasks: (spec.tasks ?? [])\n .filter((t) => t.tempId !== tempId)\n .map((t) => ({ ...t, dependsOn: (t.dependsOn ?? []).filter((d) => NormalizeDependency(d).tempId !== tempId) })),\n };\n}\n\n/** Adds a task, returning a NEW spec. */\nexport function AddTask(spec: TaskGraphSpec, task: TaskGraphSpecNode): TaskGraphSpec {\n return { ...spec, tasks: [...(spec.tasks ?? []), task] };\n}\n\n/** Replaces a task in place by `tempId`, returning a NEW spec. */\nexport function UpdateTask(spec: TaskGraphSpec, tempId: string, next: TaskGraphSpecNode): TaskGraphSpec {\n return { ...spec, tasks: (spec.tasks ?? []).map((t) => (t.tempId === tempId ? next : t)) };\n}\n\n/**\n * Would adding `from → to` create a cycle?\n *\n * Answered before the edge exists, so the canvas can refuse it rather than create an invalid graph\n * and report it afterwards. A self-edge is the degenerate case and is caught first.\n *\n * Iterative rather than recursive: the graph may come from an LLM, and a deeply-chained spec should\n * produce a refusal, not a stack overflow.\n */\nexport function WouldCreateCycle(spec: TaskGraphSpec, fromTempId: string, toTempId: string): boolean {\n if (fromTempId === toTempId) return true;\n\n // A cycle appears iff `from` is already reachable from `to` by following dependsOn edges —\n // i.e. `to` already (transitively) waits on `from`.\n const dependenciesOf = new Map<string, string[]>(\n (spec.tasks ?? []).map((t) => [t.tempId, GetDependencies(t).map((d) => d.tempId)]),\n );\n\n const stack = [...(dependenciesOf.get(fromTempId) ?? [])];\n const seen = new Set<string>();\n while (stack.length > 0) {\n const current = stack.pop()!;\n if (current === toTempId) return true;\n if (seen.has(current)) continue;\n seen.add(current);\n stack.push(...(dependenciesOf.get(current) ?? []));\n }\n return false;\n}\n\n/** A unique `tempId` for a newly added task, stable and readable. */\nexport function NextTempId(spec: TaskGraphSpec, prefix = 'task'): string {\n const taken = new Set((spec.tasks ?? []).map((t) => t.tempId));\n let n = (spec.tasks ?? []).length + 1;\n while (taken.has(`${prefix}${n}`)) n++;\n return `${prefix}${n}`;\n}\n"]}
|