@memberjunction/ng-flow-editor 6.3.0-edge.2 → 6.3.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.
|
@@ -19,14 +19,5 @@ export declare const STEP_CONFIGURATION_CODES: ReadonlyArray<FlowRunProblem['Cod
|
|
|
19
19
|
export declare function StepRunProblems(problems: readonly FlowRunProblem[], stepID: string | null | undefined): FlowRunProblem[];
|
|
20
20
|
/** The problems with one path's condition. */
|
|
21
21
|
export declare function PathRunProblems(problems: readonly FlowRunProblem[], pathID: string | null | undefined): FlowRunProblem[];
|
|
22
|
-
/**
|
|
23
|
-
* Every reason the flow would not run as it stands. Empty when the dispatcher would accept it.
|
|
24
|
-
*
|
|
25
|
-
* Compile problems come first and, like the dispatcher, stop there: a flow that does not compile has
|
|
26
|
-
* no graph to validate.
|
|
27
|
-
*
|
|
28
|
-
* @param steps the flow's steps (`MJAIAgentStepEntity` satisfies the shape as-is)
|
|
29
|
-
* @param paths the flow's paths (`MJAIAgentStepPathEntity` satisfies the shape as-is)
|
|
30
|
-
*/
|
|
31
22
|
export declare function CheckFlowRun(steps: readonly FlowCompilerStep[], paths: readonly FlowCompilerPath[]): FlowRunProblem[];
|
|
32
23
|
//# sourceMappingURL=flow-run-check.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-run-check.d.ts","sourceRoot":"","sources":["../../../src/lib/agent-editor/flow-run-check.ts"],"names":[],"mappings":"AAaA,OAAO,EAKL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EAGrB,KAAK,wBAAwB,EAC9B,MAAM,8BAA8B,CAAC;AAEtC,yFAAyF;AACzF,MAAM,MAAM,cAAc,GAAG;IAC3B,0CAA0C;IAC1C,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAAC;IAClE,mGAAmG;IACnG,OAAO,EAAE,MA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G,IAAI,GAAG,SAAS,GAAG,cAAc,EAAE,CAIxH;AAED,8CAA8C;AAC9C,wBAAgB,eAAe,CAAC,QAAQ,EAAE,SAAS,cAAc,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,cAAc,EAAE,CAExH;AAkDD,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,gBAAgB,EAAE,EAAE,KAAK,EAAE,SAAS,gBAAgB,EAAE,GAAG,cAAc,EAAE,CAiDrH"}
|
|
@@ -38,8 +38,68 @@ const PROBE_PREFIX = 'path-check:';
|
|
|
38
38
|
* @param steps the flow's steps (`MJAIAgentStepEntity` satisfies the shape as-is)
|
|
39
39
|
* @param paths the flow's paths (`MJAIAgentStepPathEntity` satisfies the shape as-is)
|
|
40
40
|
*/
|
|
41
|
+
/** Projects a step (including prototype-getter-backed BaseEntity objects) onto a plain FlowCompilerStep. */
|
|
42
|
+
function projectCompilerStep(step, overrideAsExternalPlaceholder = false) {
|
|
43
|
+
return {
|
|
44
|
+
ID: step.ID,
|
|
45
|
+
Name: step.Name,
|
|
46
|
+
Description: step.Description,
|
|
47
|
+
StepType: overrideAsExternalPlaceholder ? 'External' : step.StepType,
|
|
48
|
+
StartingStep: step.StartingStep === true,
|
|
49
|
+
Status: step.Status,
|
|
50
|
+
ActionID: step.ActionID,
|
|
51
|
+
SubAgentID: step.SubAgentID,
|
|
52
|
+
PromptID: step.PromptID,
|
|
53
|
+
LoopBodyType: step.LoopBodyType,
|
|
54
|
+
Configuration: overrideAsExternalPlaceholder
|
|
55
|
+
? JSON.stringify({ domain: 'custom-step-placeholder' })
|
|
56
|
+
: step.Configuration,
|
|
57
|
+
ActionInputMapping: step.ActionInputMapping,
|
|
58
|
+
ActionOutputMapping: step.ActionOutputMapping,
|
|
59
|
+
TimeoutSeconds: step.TimeoutSeconds,
|
|
60
|
+
RetryCount: step.RetryCount,
|
|
61
|
+
OnErrorBehavior: step.OnErrorBehavior,
|
|
62
|
+
PositionX: step.PositionX,
|
|
63
|
+
PositionY: step.PositionY,
|
|
64
|
+
Width: step.Width,
|
|
65
|
+
Height: step.Height,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
41
68
|
export function CheckFlowRun(steps, paths) {
|
|
42
|
-
const
|
|
69
|
+
const activeCustomSteps = steps.filter((s) => s.Status === 'Active' && s.StepType === 'Custom');
|
|
70
|
+
if (activeCustomSteps.length > 0) {
|
|
71
|
+
const dispatcherOnlySteps = steps.filter((s) => {
|
|
72
|
+
if (s.Status !== 'Active')
|
|
73
|
+
return false;
|
|
74
|
+
if (s.StepType === 'Human' || s.StepType === 'Wait' || s.StepType === 'External')
|
|
75
|
+
return true;
|
|
76
|
+
if (s.StepType === 'ForEach' && typeof s.Configuration === 'string' && s.Configuration.trim().length > 0) {
|
|
77
|
+
try {
|
|
78
|
+
const parsed = JSON.parse(s.Configuration);
|
|
79
|
+
return Boolean(parsed && typeof parsed === 'object' && parsed['enqueue'] && typeof parsed['enqueue'] === 'object');
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
});
|
|
87
|
+
if (dispatcherOnlySteps.length > 0) {
|
|
88
|
+
return dispatcherOnlySteps.map((step) => ({
|
|
89
|
+
Code: 'UnsupportedStepType',
|
|
90
|
+
Message: `Step "${step.Name}" requires the task-graph dispatcher and cannot be combined in the same ` +
|
|
91
|
+
`workflow as in-process Custom step(s) (${activeCustomSteps.map((c) => `"${c.Name}"`).join(', ')}).`,
|
|
92
|
+
StepID: step.ID,
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Mirror FlowAgentType's in-run pre-flight check (R5 Follow-up #3 & R6-1): explicitly project named
|
|
97
|
+
// fields (never spread a BaseEntity, whose columns are prototype getters) and substitute active
|
|
98
|
+
// Custom steps with synthetic External placeholders so valid Custom flows are validated accurately.
|
|
99
|
+
const stepsForCompile = activeCustomSteps.length > 0
|
|
100
|
+
? steps.map((step) => projectCompilerStep(step, step.StepType === 'Custom'))
|
|
101
|
+
: steps;
|
|
102
|
+
const compiled = CompileFlowToTaskGraph(stepsForCompile, paths, {
|
|
43
103
|
WorkflowName: 'Flow',
|
|
44
104
|
// Whether a referenced action, prompt or agent still exists is the server's to say — the editor's
|
|
45
105
|
// pickers need not list every row the runtime can run — so names resolve to the IDs here and only
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-run-check.js","sourceRoot":"","sources":["../../../src/lib/agent-editor/flow-run-check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,QAAQ,EACR,qBAAqB,EAOtB,MAAM,8BAA8B,CAAC;AActC;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAA0C,CAAC,qBAAqB,EAAE,qBAAqB,CAAC,CAAC;AAE9H,+FAA+F;AAC/F,MAAM,UAAU,eAAe,CAAC,QAAmC,EAAE,MAAiC;IACpG,OAAO,MAAM;QACX,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACjH,CAAC,CAAC,EAAE,CAAC;AACT,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,eAAe,CAAC,QAAmC,EAAE,MAAiC;IACpG,OAAO,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC5E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Q,CAAC,IAAI,KAAK,CAAC;QAAE,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC;IACrD,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IAClH,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS,YAAY,CAAC,IAAY;IAChC,OAAO,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC","sourcesContent":["/**\n * @fileoverview Whether a Flow agent would run as it stands, asked of the runtime itself.\n *\n * The editor keeps no rules of its own about what a flow may say. It compiles the flow with the\n * runtime's compiler (`CompileFlowToTaskGraph`) and checks the result with the runtime's validator\n * (`ValidateTaskGraphSpec`) — the two calls the dispatcher makes before it runs a flow, and refuses\n * the whole flow on — and places each refusal on the step or path it is about. So a path that reads\n * a question the step no longer asks, or a field its kind does not have (`.value` of a Likelihood),\n * is flagged while the author can still see why, not when a run fails. That includes a path that\n * tests a Choice answer against a value the question does not offer — a typo, or an option renamed\n * outside this editor — which the validator refuses on any edge.\n */\nimport { UUIDsEqual } from '@memberjunction/global';\nimport {\n CompileFlowToTaskGraph,\n NormalizeDependency,\n TaskNode,\n ValidateTaskGraphSpec,\n type FlowCompileError,\n type FlowCompilerPath,\n type FlowCompilerStep,\n type TaskGraphSpec,\n type TaskGraphSpecNode,\n type TaskGraphValidationError\n} from '@memberjunction/ai-core-plus';\n\n/** Why the flow would not run as it stands, placed where its author will look for it. */\nexport type FlowRunProblem = {\n /** The runtime's code for the problem. */\n Code: FlowCompileError['Code'] | TaskGraphValidationError['Code'];\n /** The runtime's message, naming steps by name and quoting conditions as the author wrote them. */\n Message: string;\n /** The step the problem is on, when it is on one. */\n StepID?: string;\n /** The path whose condition is at fault, when it is one path's. */\n PathID?: string;\n};\n\n/**\n * Codes a step already reports through its own configuration warning — the Decision reader's message,\n * or \"No action selected\" — so a view of the step does not say them twice. They stay in the full list.\n */\nexport const STEP_CONFIGURATION_CODES: ReadonlyArray<FlowRunProblem['Code']> = ['InvalidDecisionStep', 'UnresolvedReference'];\n\n/** The problems on a step itself, less those its own configuration warning already reports. */\nexport function StepRunProblems(problems: readonly FlowRunProblem[], stepID: string | null | undefined): FlowRunProblem[] {\n return stepID\n ? problems.filter((p) => !p.PathID && UUIDsEqual(p.StepID, stepID) && !STEP_CONFIGURATION_CODES.includes(p.Code))\n : [];\n}\n\n/** The problems with one path's condition. */\nexport function PathRunProblems(problems: readonly FlowRunProblem[], pathID: string | null | undefined): FlowRunProblem[] {\n return pathID ? problems.filter((p) => UUIDsEqual(p.PathID, pathID)) : [];\n}\n\n/** A path's condition, checked on its own task so a problem lands on the path rather than its destination. */\ntype PathProbe = {\n Path: FlowCompilerPath;\n Task: TaskGraphSpecNode;\n /** The condition as compiled, naming Decision steps by step ID. */\n Compiled: string;\n};\n\n/** Prefixes a probe task's ID, so it cannot collide with a step's. */\nconst PROBE_PREFIX = 'path-check:';\n\n/**\n * Every reason the flow would not run as it stands. Empty when the dispatcher would accept it.\n *\n * Compile problems come first and, like the dispatcher, stop there: a flow that does not compile has\n * no graph to validate.\n *\n * @param steps the flow's steps (`MJAIAgentStepEntity` satisfies the shape as-is)\n * @param paths the flow's paths (`MJAIAgentStepPathEntity` satisfies the shape as-is)\n */\nexport function CheckFlowRun(steps: readonly FlowCompilerStep[], paths: readonly FlowCompilerPath[]): FlowRunProblem[] {\n const compiled = CompileFlowToTaskGraph(steps, paths, {\n WorkflowName: 'Flow',\n // Whether a referenced action, prompt or agent still exists is the server's to say — the editor's\n // pickers need not list every row the runtime can run — so names resolve to the IDs here and only\n // the flow's own shape is checked. A reference that was never set is still reported.\n ResolveAgentName: (id) => id,\n ResolveActionName: (id) => id,\n ResolvePromptName: (id) => id,\n // What the dispatcher compiles a flow with (`CompileFlowAgentToTaskGraph`).\n TraversalMode: 'sequential'\n });\n return compiled.Success && compiled.Spec\n ? validationProblems(compiled.Spec, paths)\n : compiled.Errors.map((error) => compileProblem(error, paths));\n}\n\n/** A compile error, on the path it quotes when it is about one path's condition. */\nfunction compileProblem(error: FlowCompileError, paths: readonly FlowCompilerPath[]): FlowRunProblem {\n const path = error.Code === 'UnknownDecisionKey'\n ? paths.find((p) => UUIDsEqual(p.OriginStepID, error.StepID) && !!p.Condition?.trim() && error.Message.endsWith(p.Condition))\n : undefined;\n return { Code: error.Code, Message: error.Message, StepID: error.StepID, PathID: path?.ID };\n}\n\n/**\n * The validator's refusals of the compiled flow.\n *\n * The validator names the task a condition guards, not the edge that carries it, so conditions are\n * validated again on probes (see {@link conditionProblems}); every other refusal comes from validating\n * the compiled graph as the dispatcher does.\n */\nfunction validationProblems(spec: TaskGraphSpec, paths: readonly FlowCompilerPath[]): FlowRunProblem[] {\n const named = stepNamer(spec);\n const graph = ValidateTaskGraphSpec(spec).Errors\n .filter((error) => error.Code !== 'InvalidCondition')\n .map((error): FlowRunProblem => ({ Code: error.Code, Message: named(error.Message), StepID: error.TempId }));\n return [...graph, ...conditionProblems(spec, paths, named)];\n}\n\n/**\n * Every condition's refusals, each on the path it belongs to.\n *\n * Validates the compiled graph's tasks without their edges, plus one probe task per conditional path\n * that waits on the path's origin under the path's compiled condition. It is the same validator over\n * the same conditions and the same Decision steps; only where each refusal lands differs. A While\n * step's loop condition stays on its own task, and is reported on that step.\n */\nfunction conditionProblems(\n spec: TaskGraphSpec,\n paths: readonly FlowCompilerPath[],\n named: (message: string) => string\n): FlowRunProblem[] {\n const probes = pathProbes(spec, paths);\n const probed: TaskGraphSpec = {\n ...spec,\n tasks: [...spec.tasks.map((task) => ({ ...task, dependsOn: [] })), ...probes.map((probe) => probe.Task)]\n };\n return ValidateTaskGraphSpec(probed).Errors\n .filter((error) => error.Code === 'InvalidCondition')\n .map((error): FlowRunProblem => {\n const probe = probes.find((p) => p.Task.tempId === error.TempId);\n if (!probe) return { Code: error.Code, Message: named(error.Message), StepID: error.TempId };\n // The condition is quoted as the author wrote it — keys, not step IDs — and left untouched by the naming.\n const message = error.Message.split(probe.Compiled).map(named).join(probe.Path.Condition ?? '');\n return { Code: error.Code, Message: message, StepID: probe.Path.OriginStepID, PathID: probe.Path.ID };\n });\n}\n\n/** One probe per conditional path, matched to the dependency the compiler emitted for it. */\nfunction pathProbes(spec: TaskGraphSpec, paths: readonly FlowCompilerPath[]): PathProbe[] {\n const probes: PathProbe[] = [];\n const matched = new Set<FlowCompilerPath>();\n for (const task of spec.tasks) {\n for (const dependency of (task.dependsOn ?? []).map(NormalizeDependency)) {\n if (!dependency.condition) continue;\n // The compiler emits one dependency per path, in path order, so each is the first unmatched path\n // between the same two steps.\n const path = paths.find((p) =>\n !matched.has(p) && !!p.Condition?.trim()\n && UUIDsEqual(p.OriginStepID, dependency.tempId) && UUIDsEqual(p.DestinationStepID, task.tempId));\n if (!path) continue;\n matched.add(path);\n probes.push({\n Path: path,\n Compiled: dependency.condition,\n Task: TaskNode.Human({\n tempId: `${PROBE_PREFIX}${path.ID}`,\n name: task.name,\n description: '',\n dependsOn: [{ tempId: dependency.tempId, condition: dependency.condition }]\n })\n });\n }\n }\n return probes;\n}\n\n/**\n * Replaces each step ID in a runtime message with the step's name, as the agent does when it refuses a\n * flow. One pass, so a name is never itself rewritten.\n */\nfunction stepNamer(spec: TaskGraphSpec): (message: string) => string {\n const nameByID = new Map(spec.tasks.filter((task) => task.tempId && task.name).map((task) => [task.tempId, task.name]));\n if (nameByID.size === 0) return (message) => message;\n const ids = new RegExp([...nameByID.keys()].sort((a, b) => b.length - a.length).map(escapeRegExp).join('|'), 'g');\n return (message) => message.replace(ids, (id) => nameByID.get(id) ?? id);\n}\n\nfunction escapeRegExp(text: string): string {\n return text.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n"]}
|
|
1
|
+
{"version":3,"file":"flow-run-check.js","sourceRoot":"","sources":["../../../src/lib/agent-editor/flow-run-check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,QAAQ,EACR,qBAAqB,EAOtB,MAAM,8BAA8B,CAAC;AActC;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAA0C,CAAC,qBAAqB,EAAE,qBAAqB,CAAC,CAAC;AAE9H,+FAA+F;AAC/F,MAAM,UAAU,eAAe,CAAC,QAAmC,EAAE,MAAiC;IACpG,OAAO,MAAM;QACX,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACjH,CAAC,CAAC,EAAE,CAAC;AACT,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,eAAe,CAAC,QAAmC,EAAE,MAAiC;IACpG,OAAO,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC5E,CAAC;AAUD,sEAAsE;AACtE,MAAM,YAAY,GAAG,aAAa,CAAC;AAEnC;;;;;;;;GAQG;AACH,4GAA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K,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACxH,IAAI,QAAQ,CAAC,IAAI,KAAK,CAAC;QAAE,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC;IACrD,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IAClH,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS,YAAY,CAAC,IAAY;IAChC,OAAO,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC","sourcesContent":["/**\n * @fileoverview Whether a Flow agent would run as it stands, asked of the runtime itself.\n *\n * The editor keeps no rules of its own about what a flow may say. It compiles the flow with the\n * runtime's compiler (`CompileFlowToTaskGraph`) and checks the result with the runtime's validator\n * (`ValidateTaskGraphSpec`) — the two calls the dispatcher makes before it runs a flow, and refuses\n * the whole flow on — and places each refusal on the step or path it is about. So a path that reads\n * a question the step no longer asks, or a field its kind does not have (`.value` of a Likelihood),\n * is flagged while the author can still see why, not when a run fails. That includes a path that\n * tests a Choice answer against a value the question does not offer — a typo, or an option renamed\n * outside this editor — which the validator refuses on any edge.\n */\nimport { UUIDsEqual } from '@memberjunction/global';\nimport {\n CompileFlowToTaskGraph,\n NormalizeDependency,\n TaskNode,\n ValidateTaskGraphSpec,\n type FlowCompileError,\n type FlowCompilerPath,\n type FlowCompilerStep,\n type TaskGraphSpec,\n type TaskGraphSpecNode,\n type TaskGraphValidationError\n} from '@memberjunction/ai-core-plus';\n\n/** Why the flow would not run as it stands, placed where its author will look for it. */\nexport type FlowRunProblem = {\n /** The runtime's code for the problem. */\n Code: FlowCompileError['Code'] | TaskGraphValidationError['Code'];\n /** The runtime's message, naming steps by name and quoting conditions as the author wrote them. */\n Message: string;\n /** The step the problem is on, when it is on one. */\n StepID?: string;\n /** The path whose condition is at fault, when it is one path's. */\n PathID?: string;\n};\n\n/**\n * Codes a step already reports through its own configuration warning — the Decision reader's message,\n * or \"No action selected\" — so a view of the step does not say them twice. They stay in the full list.\n */\nexport const STEP_CONFIGURATION_CODES: ReadonlyArray<FlowRunProblem['Code']> = ['InvalidDecisionStep', 'UnresolvedReference'];\n\n/** The problems on a step itself, less those its own configuration warning already reports. */\nexport function StepRunProblems(problems: readonly FlowRunProblem[], stepID: string | null | undefined): FlowRunProblem[] {\n return stepID\n ? problems.filter((p) => !p.PathID && UUIDsEqual(p.StepID, stepID) && !STEP_CONFIGURATION_CODES.includes(p.Code))\n : [];\n}\n\n/** The problems with one path's condition. */\nexport function PathRunProblems(problems: readonly FlowRunProblem[], pathID: string | null | undefined): FlowRunProblem[] {\n return pathID ? problems.filter((p) => UUIDsEqual(p.PathID, pathID)) : [];\n}\n\n/** A path's condition, checked on its own task so a problem lands on the path rather than its destination. */\ntype PathProbe = {\n Path: FlowCompilerPath;\n Task: TaskGraphSpecNode;\n /** The condition as compiled, naming Decision steps by step ID. */\n Compiled: string;\n};\n\n/** Prefixes a probe task's ID, so it cannot collide with a step's. */\nconst PROBE_PREFIX = 'path-check:';\n\n/**\n * Every reason the flow would not run as it stands. Empty when the dispatcher would accept it.\n *\n * Compile problems come first and, like the dispatcher, stop there: a flow that does not compile has\n * no graph to validate.\n *\n * @param steps the flow's steps (`MJAIAgentStepEntity` satisfies the shape as-is)\n * @param paths the flow's paths (`MJAIAgentStepPathEntity` satisfies the shape as-is)\n */\n/** Projects a step (including prototype-getter-backed BaseEntity objects) onto a plain FlowCompilerStep. */\nfunction projectCompilerStep(step: FlowCompilerStep, overrideAsExternalPlaceholder = false): FlowCompilerStep {\n return {\n ID: step.ID,\n Name: step.Name,\n Description: step.Description,\n StepType: overrideAsExternalPlaceholder ? 'External' : step.StepType,\n StartingStep: step.StartingStep === true,\n Status: step.Status,\n ActionID: step.ActionID,\n SubAgentID: step.SubAgentID,\n PromptID: step.PromptID,\n LoopBodyType: step.LoopBodyType,\n Configuration: overrideAsExternalPlaceholder\n ? JSON.stringify({ domain: 'custom-step-placeholder' })\n : step.Configuration,\n ActionInputMapping: step.ActionInputMapping,\n ActionOutputMapping: step.ActionOutputMapping,\n TimeoutSeconds: step.TimeoutSeconds,\n RetryCount: step.RetryCount,\n OnErrorBehavior: step.OnErrorBehavior,\n PositionX: step.PositionX,\n PositionY: step.PositionY,\n Width: step.Width,\n Height: step.Height,\n };\n}\n\nexport function CheckFlowRun(steps: readonly FlowCompilerStep[], paths: readonly FlowCompilerPath[]): FlowRunProblem[] {\n const activeCustomSteps = steps.filter((s) => s.Status === 'Active' && s.StepType === 'Custom');\n if (activeCustomSteps.length > 0) {\n const dispatcherOnlySteps = steps.filter((s) => {\n if (s.Status !== 'Active') return false;\n if (s.StepType === 'Human' || s.StepType === 'Wait' || s.StepType === 'External') return true;\n if (s.StepType === 'ForEach' && typeof s.Configuration === 'string' && s.Configuration.trim().length > 0) {\n try {\n const parsed = JSON.parse(s.Configuration) as Record<string, unknown>;\n return Boolean(parsed && typeof parsed === 'object' && parsed['enqueue'] && typeof parsed['enqueue'] === 'object');\n } catch {\n return false;\n }\n }\n return false;\n });\n if (dispatcherOnlySteps.length > 0) {\n return dispatcherOnlySteps.map((step) => ({\n Code: 'UnsupportedStepType' as const,\n Message:\n `Step \"${step.Name}\" requires the task-graph dispatcher and cannot be combined in the same ` +\n `workflow as in-process Custom step(s) (${activeCustomSteps.map((c) => `\"${c.Name}\"`).join(', ')}).`,\n StepID: step.ID,\n }));\n }\n }\n\n // Mirror FlowAgentType's in-run pre-flight check (R5 Follow-up #3 & R6-1): explicitly project named\n // fields (never spread a BaseEntity, whose columns are prototype getters) and substitute active\n // Custom steps with synthetic External placeholders so valid Custom flows are validated accurately.\n const stepsForCompile: readonly FlowCompilerStep[] =\n activeCustomSteps.length > 0\n ? steps.map((step) => projectCompilerStep(step, step.StepType === 'Custom'))\n : steps;\n\n const compiled = CompileFlowToTaskGraph(stepsForCompile, paths, {\n WorkflowName: 'Flow',\n // Whether a referenced action, prompt or agent still exists is the server's to say — the editor's\n // pickers need not list every row the runtime can run — so names resolve to the IDs here and only\n // the flow's own shape is checked. A reference that was never set is still reported.\n ResolveAgentName: (id) => id,\n ResolveActionName: (id) => id,\n ResolvePromptName: (id) => id,\n // What the dispatcher compiles a flow with (`CompileFlowAgentToTaskGraph`).\n TraversalMode: 'sequential'\n });\n return compiled.Success && compiled.Spec\n ? validationProblems(compiled.Spec, paths)\n : compiled.Errors.map((error) => compileProblem(error, paths));\n}\n\n/** A compile error, on the path it quotes when it is about one path's condition. */\nfunction compileProblem(error: FlowCompileError, paths: readonly FlowCompilerPath[]): FlowRunProblem {\n const path = error.Code === 'UnknownDecisionKey'\n ? paths.find((p) => UUIDsEqual(p.OriginStepID, error.StepID) && !!p.Condition?.trim() && error.Message.endsWith(p.Condition))\n : undefined;\n return { Code: error.Code, Message: error.Message, StepID: error.StepID, PathID: path?.ID };\n}\n\n/**\n * The validator's refusals of the compiled flow.\n *\n * The validator names the task a condition guards, not the edge that carries it, so conditions are\n * validated again on probes (see {@link conditionProblems}); every other refusal comes from validating\n * the compiled graph as the dispatcher does.\n */\nfunction validationProblems(spec: TaskGraphSpec, paths: readonly FlowCompilerPath[]): FlowRunProblem[] {\n const named = stepNamer(spec);\n const graph = ValidateTaskGraphSpec(spec).Errors\n .filter((error) => error.Code !== 'InvalidCondition')\n .map((error): FlowRunProblem => ({ Code: error.Code, Message: named(error.Message), StepID: error.TempId }));\n return [...graph, ...conditionProblems(spec, paths, named)];\n}\n\n/**\n * Every condition's refusals, each on the path it belongs to.\n *\n * Validates the compiled graph's tasks without their edges, plus one probe task per conditional path\n * that waits on the path's origin under the path's compiled condition. It is the same validator over\n * the same conditions and the same Decision steps; only where each refusal lands differs. A While\n * step's loop condition stays on its own task, and is reported on that step.\n */\nfunction conditionProblems(\n spec: TaskGraphSpec,\n paths: readonly FlowCompilerPath[],\n named: (message: string) => string\n): FlowRunProblem[] {\n const probes = pathProbes(spec, paths);\n const probed: TaskGraphSpec = {\n ...spec,\n tasks: [...spec.tasks.map((task) => ({ ...task, dependsOn: [] })), ...probes.map((probe) => probe.Task)]\n };\n return ValidateTaskGraphSpec(probed).Errors\n .filter((error) => error.Code === 'InvalidCondition')\n .map((error): FlowRunProblem => {\n const probe = probes.find((p) => p.Task.tempId === error.TempId);\n if (!probe) return { Code: error.Code, Message: named(error.Message), StepID: error.TempId };\n // The condition is quoted as the author wrote it — keys, not step IDs — and left untouched by the naming.\n const message = error.Message.split(probe.Compiled).map(named).join(probe.Path.Condition ?? '');\n return { Code: error.Code, Message: message, StepID: probe.Path.OriginStepID, PathID: probe.Path.ID };\n });\n}\n\n/** One probe per conditional path, matched to the dependency the compiler emitted for it. */\nfunction pathProbes(spec: TaskGraphSpec, paths: readonly FlowCompilerPath[]): PathProbe[] {\n const probes: PathProbe[] = [];\n const matched = new Set<FlowCompilerPath>();\n for (const task of spec.tasks) {\n for (const dependency of (task.dependsOn ?? []).map(NormalizeDependency)) {\n if (!dependency.condition) continue;\n // The compiler emits one dependency per path, in path order, so each is the first unmatched path\n // between the same two steps.\n const path = paths.find((p) =>\n !matched.has(p) && !!p.Condition?.trim()\n && UUIDsEqual(p.OriginStepID, dependency.tempId) && UUIDsEqual(p.DestinationStepID, task.tempId));\n if (!path) continue;\n matched.add(path);\n probes.push({\n Path: path,\n Compiled: dependency.condition,\n Task: TaskNode.Human({\n tempId: `${PROBE_PREFIX}${path.ID}`,\n name: task.name,\n description: '',\n dependsOn: [{ tempId: dependency.tempId, condition: dependency.condition }]\n })\n });\n }\n }\n return probes;\n}\n\n/**\n * Replaces each step ID in a runtime message with the step's name, as the agent does when it refuses a\n * flow. One pass, so a name is never itself rewritten.\n */\nfunction stepNamer(spec: TaskGraphSpec): (message: string) => string {\n const nameByID = new Map(spec.tasks.filter((task) => task.tempId && task.name).map((task) => [task.tempId, task.name]));\n if (nameByID.size === 0) return (message) => message;\n const ids = new RegExp([...nameByID.keys()].sort((a, b) => b.length - a.length).map(escapeRegExp).join('|'), 'g');\n return (message) => message.replace(ids, (id) => nameByID.get(id) ?? id);\n}\n\nfunction escapeRegExp(text: string): string {\n return text.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ng-flow-editor",
|
|
3
|
-
"version": "6.3.0-edge.
|
|
3
|
+
"version": "6.3.0-edge.3",
|
|
4
4
|
"description": "MemberJunction: Generic visual flow editor component powered by Foblex Flow, with an agent-specific Flow Agent Editor",
|
|
5
5
|
"main": "./dist/public-api.js",
|
|
6
6
|
"typings": "./dist/public-api.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@angular/compiler": "21.2.22",
|
|
23
23
|
"@angular/compiler-cli": "21.2.22",
|
|
24
|
-
"@memberjunction/ng-test-utils": "6.3.0-edge.
|
|
24
|
+
"@memberjunction/ng-test-utils": "6.3.0-edge.3",
|
|
25
25
|
"sass": "^1.97.3",
|
|
26
26
|
"vitest": "^4.0.18"
|
|
27
27
|
},
|
|
@@ -38,14 +38,14 @@
|
|
|
38
38
|
"@foblex/mediator": "1.1.3",
|
|
39
39
|
"@foblex/platform": "1.0.4",
|
|
40
40
|
"@foblex/utils": "1.1.1",
|
|
41
|
-
"@memberjunction/ai-core-plus": "6.3.0-edge.
|
|
42
|
-
"@memberjunction/core": "6.3.0-edge.
|
|
43
|
-
"@memberjunction/core-entities": "6.3.0-edge.
|
|
44
|
-
"@memberjunction/global": "6.3.0-edge.
|
|
45
|
-
"@memberjunction/ng-base-types": "6.3.0-edge.
|
|
46
|
-
"@memberjunction/ng-code-editor": "6.3.0-edge.
|
|
47
|
-
"@memberjunction/ng-shared-generic": "6.3.0-edge.
|
|
48
|
-
"@memberjunction/ng-ui-components": "6.3.0-edge.
|
|
41
|
+
"@memberjunction/ai-core-plus": "6.3.0-edge.3",
|
|
42
|
+
"@memberjunction/core": "6.3.0-edge.3",
|
|
43
|
+
"@memberjunction/core-entities": "6.3.0-edge.3",
|
|
44
|
+
"@memberjunction/global": "6.3.0-edge.3",
|
|
45
|
+
"@memberjunction/ng-base-types": "6.3.0-edge.3",
|
|
46
|
+
"@memberjunction/ng-code-editor": "6.3.0-edge.3",
|
|
47
|
+
"@memberjunction/ng-shared-generic": "6.3.0-edge.3",
|
|
48
|
+
"@memberjunction/ng-ui-components": "6.3.0-edge.3",
|
|
49
49
|
"rxjs": "^7.8.2",
|
|
50
50
|
"tslib": "^2.8.1"
|
|
51
51
|
},
|