@rolealpha/n8n-nodes-rolealpha 0.13.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ /**
3
+ * Release by risk. How far the Workflow Builder may act without a click is not set in n8n but
4
+ * in roleALPHA: a policy with the custom ID `automation:autonomie-<1..4>` that APPLIES_TO a
5
+ * process (a value stream, a step) sets the level for it and, down HAS_SUBPROCESS, for all its
6
+ * steps. The levels follow the company's autonomy levels for AI:
7
+ *
8
+ * 1 assistance the system proposes, a person decides and acts
9
+ * 2 preparation the system prepares, a person checks and approves (the default)
10
+ * 3 limited the system carries out clearly defined actions, a person watches
11
+ * 4 extensive the system decides and acts within set limits, a person sets the limits
12
+ *
13
+ * Each checked proposal gets a risk class, and each class a level from which it is applied
14
+ * without asking first. Code and credentials still to be set never are. Fail-closed: whatever
15
+ * cannot be read counts as "no policy", and then every change waits for approval as before.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.DEFAULT_MAX_AUTO_PER_PASS = exports.AUTO_FROM_LEVEL = exports.AUTONOMY_PREFIX = void 0;
19
+ exports.levelOf = levelOf;
20
+ exports.autonomyFor = autonomyFor;
21
+ exports.autonomyForAll = autonomyForAll;
22
+ exports.autonomyEntities = autonomyEntities;
23
+ exports.classifyRisk = classifyRisk;
24
+ exports.decideAuto = decideAuto;
25
+ exports.limitPass = limitPass;
26
+ exports.AUTONOMY_PREFIX = 'automation:autonomie-';
27
+ /** From which level a class is applied without asking; null: never. */
28
+ exports.AUTO_FROM_LEVEL = {
29
+ narrowing: 3,
30
+ template: 3,
31
+ model: 4,
32
+ code: null,
33
+ new_credential: null,
34
+ };
35
+ exports.DEFAULT_MAX_AUTO_PER_PASS = 3;
36
+ const NOT_IN_FORCE = /^(draft|entwurf|retired|archived|archiviert|inactive|inaktiv|withdrawn|zurückgezogen)$/i;
37
+ const MAX_DEPTH = 12;
38
+ /** The level a custom ID names, if it is an autonomy policy of this prefix. */
39
+ function levelOf(customId, prefix = exports.AUTONOMY_PREFIX) {
40
+ if (typeof customId !== 'string' || prefix === '' || !customId.toLowerCase().startsWith(prefix.toLowerCase()))
41
+ return null;
42
+ const rest = customId.slice(prefix.length).trim();
43
+ return /^[1-4]$/.test(rest) ? Number(rest) : null;
44
+ }
45
+ const none = (reason, readFailed = false) => ({ level: null, policy: null, appliesTo: null, reason, ...(readFailed ? { readFailed } : {}) });
46
+ /**
47
+ * The autonomy level of one entity: the nearest policy on the entity or on a process above it
48
+ * (HAS_SUBPROCESS, upwards). Two policies at the same distance: the lower level wins.
49
+ */
50
+ async function autonomyFor(src, entityUuid, opts = {}) {
51
+ const prefix = opts.prefix ?? exports.AUTONOMY_PREFIX;
52
+ const seen = new Set([entityUuid]);
53
+ let frontier = [entityUuid];
54
+ try {
55
+ for (let depth = 0; depth <= MAX_DEPTH && frontier.length > 0; depth++) {
56
+ const found = [];
57
+ const next = [];
58
+ for (const uuid of frontier) {
59
+ const rels = await src.relationships(uuid);
60
+ for (const r of rels) {
61
+ if (r.type === 'APPLIES_TO' && r.direction === 'incoming') {
62
+ const p = await src.details(r.uuid);
63
+ const level = levelOf(p.customId, prefix);
64
+ if (level === null || NOT_IN_FORCE.test(String(p.data.status ?? '')))
65
+ continue;
66
+ const holder = await src.details(uuid);
67
+ const at = uuid === entityUuid ? `"${holder.name}" itself` : `"${holder.name}" above it`;
68
+ found.push({ level, policy: { uuid: p.uuid, name: p.name, customId: p.customId }, appliesTo: { uuid, name: holder.name }, reason: `Policy "${p.name}" (${p.customId}) applies to ${at}` });
69
+ }
70
+ if (r.type === 'HAS_SUBPROCESS' && r.direction === 'incoming' && !seen.has(r.uuid)) {
71
+ seen.add(r.uuid);
72
+ next.push(r.uuid);
73
+ }
74
+ }
75
+ }
76
+ if (found.length > 0)
77
+ return found.reduce((a, b) => (b.level < a.level ? b : a));
78
+ frontier = next;
79
+ }
80
+ }
81
+ catch (error) {
82
+ return none(`roleALPHA could not be read for the autonomy level: ${error.message}`, true);
83
+ }
84
+ return none('No autonomy policy applies; every change waits for approval');
85
+ }
86
+ /** The level for a change that touches several entities: the lowest of them, and none if one has none. */
87
+ async function autonomyForAll(src, entityUuids, opts = {}) {
88
+ const uuids = [...new Set(entityUuids.filter(Boolean))];
89
+ if (uuids.length === 0)
90
+ return none('No existing entity to read the autonomy level from; the change waits for approval');
91
+ let lowest = null;
92
+ for (const uuid of uuids) {
93
+ const a = await autonomyFor(src, uuid, opts);
94
+ if (a.level === null)
95
+ return a;
96
+ if (!lowest || a.level < lowest.level)
97
+ lowest = a;
98
+ }
99
+ return lowest;
100
+ }
101
+ /**
102
+ * The entities whose level counts for a proposal: what the workflow is and will be bound to.
103
+ * A removed entity no longer exists, so it cannot count.
104
+ */
105
+ function autonomyEntities(plan, change, workflows) {
106
+ const target = plan.targetWorkflowId ? workflows.find((w) => w.id === plan.targetWorkflowId) : undefined;
107
+ const set = new Set((target?.entities ?? []).map((e) => e.toLowerCase()));
108
+ if (plan.action === 'create' || plan.bindEntity !== false)
109
+ set.add(change.uuid.toLowerCase());
110
+ if (change.change === 'removed')
111
+ set.delete(change.uuid.toLowerCase());
112
+ return [...set];
113
+ }
114
+ /** The risk class of a checked proposal; null when it changes nothing. */
115
+ function classifyRisk(plan) {
116
+ if (!plan.ok || plan.action === 'none')
117
+ return null;
118
+ if (plan.action === 'deactivate')
119
+ return 'narrowing';
120
+ if ((plan.code ?? []).length > 0)
121
+ return 'code';
122
+ if ((plan.missingCredentials ?? []).length > 0)
123
+ return 'new_credential';
124
+ return plan.template ? 'template' : 'model';
125
+ }
126
+ /** Whether a proposal of this class may be applied without asking at this level. */
127
+ function decideAuto(risk, autonomy) {
128
+ if (risk === null)
129
+ return { autoApply: false, autoReason: 'Nothing to apply' };
130
+ const from = exports.AUTO_FROM_LEVEL[risk];
131
+ if (from === null)
132
+ return { autoApply: false, autoReason: `A change of class "${risk}" always waits for approval` };
133
+ if (autonomy.level === null)
134
+ return { autoApply: false, autoReason: autonomy.reason };
135
+ if (autonomy.level < from)
136
+ return { autoApply: false, autoReason: `Autonomy level ${autonomy.level}; a change of class "${risk}" runs by itself from level ${from}` };
137
+ return { autoApply: true, autoReason: `Autonomy level ${autonomy.level} (${autonomy.reason}); class "${risk}" runs by itself from level ${from}` };
138
+ }
139
+ /**
140
+ * The limits of one pass, after all its proposals are known: a pass in which anything failed
141
+ * to read applies nothing by itself, and at most `max` changes are applied by themselves; the
142
+ * rest wait for approval.
143
+ */
144
+ function limitPass(results, max = exports.DEFAULT_MAX_AUTO_PER_PASS) {
145
+ const failed = results.some((r) => r.decidedBy === 'failed' || r.error !== undefined || r.autonomy?.readFailed === true);
146
+ let used = 0;
147
+ return results.map((r) => {
148
+ if (!r.autoApply)
149
+ return r;
150
+ if (failed)
151
+ return { ...r, autoApply: false, autoReason: 'Something could not be read in this run, so nothing is applied by itself; it waits for approval' };
152
+ if (used >= Math.max(0, max))
153
+ return { ...r, autoApply: false, autoReason: `Already ${used} changes applied by themselves in this run (limit ${max}); this one waits for approval` };
154
+ used++;
155
+ return r;
156
+ });
157
+ }
158
+ //# sourceMappingURL=autonomy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autonomy.js","sourceRoot":"","sources":["../../lib/autonomy.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAsCH,0BAIC;AAQD,kCAgCC;AAGD,wCAUC;AAMD,4CAMC;AAGD,oCAMC;AAQD,gCAOC;AAOD,8BAUC;AA9IY,QAAA,eAAe,GAAG,uBAAuB,CAAC;AAMvD,uEAAuE;AAC1D,QAAA,eAAe,GAA4C;IACvE,SAAS,EAAE,CAAC;IACZ,QAAQ,EAAE,CAAC;IACX,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,IAAI;IACV,cAAc,EAAE,IAAI;CACpB,CAAC;AAEW,QAAA,yBAAyB,GAAG,CAAC,CAAC;AAa3C,MAAM,YAAY,GAAG,yFAAyF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C,CAAC,SAAS,KAAK,QAAQ,IAAI,CAAC,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,CAAC,QAAQ,EAAE,UAAU,KAAK,IAAI,CAAC,CAAC;IACzH,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACxB,IAAI,CAAC,CAAC,CAAC,SAAS;YAAE,OAAO,CAAC,CAAC;QAC3B,IAAI,MAAM;YAAE,OAAO,EAAE,GAAG,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,iGAAiG,EAAE,CAAC;QAC7J,IAAI,IAAI,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC;YAAE,OAAO,EAAE,GAAG,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,IAAI,qDAAqD,GAAG,gCAAgC,EAAE,CAAC;QACrL,IAAI,EAAE,CAAC;QACP,OAAO,CAAC,CAAC;IACV,CAAC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,155 @@
1
+ /**
2
+ * The chain of a value stream, and whether n8n can run all of it.
3
+ *
4
+ * A value stream in roleALPHA is a tree of steps (HAS_SUBPROCESS) in an order (DEPENDS_ON). For
5
+ * every step the chain needs four things: something that starts it (entry), someone who does it
6
+ * (executor), the end it leaves, and the step that comes next. roleALPHA holds who and in which
7
+ * order; what starts a step lives in n8n: a frequency the scheduler covers, a route from an event
8
+ * of a system to the step, a workflow bound to it. The check compares the two and names every
9
+ * gap per step, without a model and the same way every time.
10
+ *
11
+ * Nothing here knows a system or a tenant. A system is an EA application the step is
12
+ * SUPPORTED_BY; an event is `<object>:<state>` in whatever notation the tenant uses; routes come
13
+ * from any store. Directus, Odoo, Zammad or a mailbox are all the same to the check.
14
+ */
15
+ import { type GraphSource } from './graph';
16
+ import { type N8nWorkflow } from './workflows';
17
+ export interface ChainHolder {
18
+ uuid: string;
19
+ name: string;
20
+ kind: 'agent' | 'person';
21
+ /** An agent that is active; a person with an address. */
22
+ available: boolean;
23
+ }
24
+ export interface ChainRole {
25
+ uuid: string;
26
+ name: string;
27
+ holders: ChainHolder[];
28
+ }
29
+ export interface ChainEdge {
30
+ uuid: string;
31
+ name: string;
32
+ /** For an edge out of a gate: the outcome it stands for (DEPENDS_ON.ausgang). */
33
+ outcome: string | null;
34
+ }
35
+ export interface ChainSystem {
36
+ uuid: string;
37
+ name: string;
38
+ /** The event of this system that starts the step (SUPPORTED_BY.eingang), if modelled. */
39
+ entry: string | null;
40
+ /** What the step leaves in this system when done (SUPPORTED_BY.ausgang), if modelled. */
41
+ exit: string | null;
42
+ }
43
+ export interface ChainStep {
44
+ uuid: string;
45
+ name: string;
46
+ customId: string | null;
47
+ subtype: string | null;
48
+ status: string | null;
49
+ frequency: string | null;
50
+ parentUuid: string | null;
51
+ depth: number;
52
+ isGate: boolean;
53
+ isGrouping: boolean;
54
+ retired: boolean;
55
+ predecessors: ChainEdge[];
56
+ successors: ChainEdge[];
57
+ responsible: ChainRole[];
58
+ deciding: ChainRole[];
59
+ systems: ChainSystem[];
60
+ }
61
+ export interface ValueStream {
62
+ root: {
63
+ uuid: string;
64
+ name: string;
65
+ customId: string | null;
66
+ subtype: string | null;
67
+ };
68
+ steps: ChainStep[];
69
+ /** More steps than the limit; the rest was not read. */
70
+ truncated: boolean;
71
+ }
72
+ /** Reads a value stream from roleALPHA: its steps in order, with roles, holders, gates and systems. */
73
+ export declare function getValueStream(src: GraphSource, rootUuid: string, opts?: {
74
+ maxSteps?: number;
75
+ maxDepth?: number;
76
+ }): Promise<ValueStream>;
77
+ /** The value streams of a tenant: processes of subtype `process`, else the value chains. */
78
+ export declare function listValueStreams(src: GraphSource): Promise<{
79
+ roots: Array<{
80
+ uuid: string;
81
+ name: string;
82
+ customId: string | null;
83
+ }>;
84
+ notice: string | null;
85
+ }>;
86
+ /** Value streams above the given steps (up HAS_SUBPROCESS to the nearest `process`, else the top). */
87
+ export declare function valueStreamsOf(src: GraphSource, uuids: string[]): Promise<string[]>;
88
+ /** One row of a route table in any store: an event of a system starts a step, to run it or to have it decided. */
89
+ export interface RouteRow {
90
+ event: string;
91
+ step: string;
92
+ action: 'run' | 'decide';
93
+ }
94
+ /**
95
+ * Route rows from any store. Accepted columns: `event`, or `source`/`collection`/`object` plus
96
+ * `state`/`status`; `step`/`step_custom_id`/`stepCustomId`; `action` (`run`, empty = run;
97
+ * `decide`, `card`, `approval` = decide). Rows without a step only notify and are left out.
98
+ */
99
+ export declare function normalizeRoutes(rows: unknown): RouteRow[];
100
+ export interface ServingWorkflow {
101
+ id: string;
102
+ name: string;
103
+ active: boolean;
104
+ /** Bound to the step by the Workflow Builder; a change in roleALPHA reaches it. */
105
+ managed: boolean;
106
+ draft: boolean;
107
+ /** UUIDs of the steps it serves. */
108
+ steps: string[];
109
+ }
110
+ /** Which workflows serve which steps: bound to them, or naming their custom ID. Undo records never. */
111
+ export declare function servingWorkflows(raw: N8nWorkflow[], steps: Array<Pick<ChainStep, 'uuid' | 'customId'>>): ServingWorkflow[];
112
+ export type GapCode = 'no_entry' | 'handover_unverified' | 'event_not_routed' | 'unbound_workflow' | 'inactive_workflow' | 'draft_waiting' | 'no_custom_id' | 'no_responsible_role' | 'no_executor' | 'route_without_agent' | 'on_demand_without_person' | 'no_decider' | 'no_deciding_person' | 'gate_not_requested' | 'outcomes_not_modelled' | 'route_to_retired' | 'workflow_for_retired' | 'no_steps' | 'truncated';
113
+ export type Severity = 'error' | 'warning' | 'info';
114
+ export interface ChainGap {
115
+ code: GapCode;
116
+ severity: Severity;
117
+ stepUuid: string | null;
118
+ stepName: string | null;
119
+ message: string;
120
+ }
121
+ export interface EntryKind {
122
+ kind: 'schedule' | 'route' | 'decision' | 'workflow' | 'handover' | 'on_demand';
123
+ detail: string;
124
+ }
125
+ export interface StepCoverage {
126
+ uuid: string;
127
+ name: string;
128
+ customId: string | null;
129
+ kind: 'step' | 'gate' | 'group' | 'retired';
130
+ entries: EntryKind[];
131
+ executors: string[];
132
+ next: string[];
133
+ gaps: ChainGap[];
134
+ }
135
+ export interface ChainCheck {
136
+ valueStream: ValueStream['root'];
137
+ ok: boolean;
138
+ errors: number;
139
+ warnings: number;
140
+ steps: StepCoverage[];
141
+ gaps: ChainGap[];
142
+ report: string;
143
+ }
144
+ export type Language = 'en' | 'de';
145
+ export interface CheckOptions {
146
+ routes?: RouteRow[];
147
+ workflows?: ServingWorkflow[];
148
+ /** Whether a generic scheduler starts every step with a frequency (default true). */
149
+ schedulerCoversFrequency?: boolean;
150
+ language?: Language;
151
+ }
152
+ /** Compares the chain in roleALPHA with what n8n runs; the same answer every time. */
153
+ export declare function checkChain(stream: ValueStream, opts?: CheckOptions): ChainCheck;
154
+ /** The check as Markdown: a task text for whoever builds the workflows, and a report for the owner. */
155
+ export declare function chainReport(check: ChainCheck, lang?: Language): string;