@rolealpha/n8n-nodes-rolealpha 0.5.1 → 0.7.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,170 @@
1
+ /**
2
+ * Workflows that follow the organisation. When a step, role or agent is created or changed
3
+ * in roleALPHA, a model proposes to create, update or deactivate an n8n workflow. The
4
+ * proposal never goes live by itself: it becomes an inactive draft, a person filling the
5
+ * deciding role approves it, and only then is it applied.
6
+ *
7
+ * The model call stays outside: buildPlanInput prepares it, checkPlan checks the answer.
8
+ * The model can neither pick node types outside the allow list, nor bring in credentials
9
+ * it has not seen, nor bake persons, addresses or UUIDs into a workflow, nor touch a
10
+ * workflow that is not managed.
11
+ */
12
+ import type { EntityChange } from './changes';
13
+ import { type GraphSource } from './graph';
14
+ export declare const MANAGED_TAG = "rolealpha-managed";
15
+ export declare const DRAFT_TAG = "rolealpha-draft";
16
+ export declare const MARKER_NAME = "roleALPHA binding";
17
+ export declare const DRAFT_PREFIX = "Draft: ";
18
+ export declare const DEFAULT_NODE_TYPES: string[];
19
+ export interface N8nNode {
20
+ id?: string;
21
+ name: string;
22
+ type: string;
23
+ typeVersion: number;
24
+ position: [number, number];
25
+ parameters: Record<string, unknown>;
26
+ credentials?: Record<string, {
27
+ id: string;
28
+ name: string;
29
+ }>;
30
+ webhookId?: string;
31
+ disabled?: boolean;
32
+ }
33
+ export type N8nConnections = Record<string, Record<string, Array<Array<{
34
+ node: string;
35
+ type: string;
36
+ index: number;
37
+ }>>>>;
38
+ export interface N8nWorkflow {
39
+ id?: string;
40
+ name: string;
41
+ active?: boolean;
42
+ nodes: N8nNode[];
43
+ connections: N8nConnections;
44
+ settings?: Record<string, unknown>;
45
+ tags?: Array<{
46
+ id?: string;
47
+ name: string;
48
+ }>;
49
+ versionId?: string;
50
+ updatedAt?: string;
51
+ }
52
+ /** What a draft carries about itself, so Apply needs nothing but the draft. */
53
+ export interface DraftInfo {
54
+ action: 'create' | 'update' | 'deactivate';
55
+ targetWorkflowId: string | null;
56
+ /** versionId (or updatedAt) of the target when the draft was made; Apply refuses if it moved on. */
57
+ targetVersion: string | null;
58
+ entityUuid: string;
59
+ change: string;
60
+ contentHash: string;
61
+ reason: string;
62
+ }
63
+ export interface Binding {
64
+ managed: true;
65
+ entities: string[];
66
+ draft?: DraftInfo;
67
+ }
68
+ export interface KnownCredential {
69
+ id: string;
70
+ name: string;
71
+ type: string;
72
+ }
73
+ export interface ManagedWorkflow {
74
+ id: string;
75
+ name: string;
76
+ active: boolean;
77
+ entities: string[];
78
+ isDraft: boolean;
79
+ versionId: string | null;
80
+ nodes: Array<{
81
+ name: string;
82
+ type: string;
83
+ parameters: string;
84
+ credentials: string[];
85
+ }>;
86
+ connections: string[];
87
+ }
88
+ export declare function readBinding(wf: Pick<N8nWorkflow, 'nodes'>): Binding | null;
89
+ export declare function markerNode(binding: Binding, position?: [number, number]): N8nNode;
90
+ /** Hash of exactly what runs: names, types, versions, parameters, credentials and connections. */
91
+ export declare function contentHash(wf: Pick<N8nWorkflow, 'nodes' | 'connections'>): string;
92
+ export declare function summarizeWorkflows(raw: unknown[]): {
93
+ workflows: ManagedWorkflow[];
94
+ credentials: KnownCredential[];
95
+ };
96
+ export interface PlanContext {
97
+ change: EntityChange;
98
+ /** What roleALPHA says about the entity now: details, step, relationships. Never persons. */
99
+ entity: unknown;
100
+ workflows: ManagedWorkflow[];
101
+ credentials: KnownCredential[];
102
+ nodeTypes: string[];
103
+ extraRules?: string[];
104
+ }
105
+ export interface PlanInput {
106
+ systemMessage: string;
107
+ prompt: string;
108
+ schema: Record<string, unknown>;
109
+ }
110
+ export declare const PLAN_SCHEMA: Record<string, unknown>;
111
+ export declare function buildPlanInput(ctx: PlanContext): PlanInput;
112
+ /** Takes the JSON object out of a model answer (plain, fenced, or with text around it). */
113
+ export declare function parseAnswer(answer: unknown): unknown;
114
+ export interface PlanCheck {
115
+ ok: boolean;
116
+ action: 'create' | 'update' | 'deactivate' | 'none';
117
+ reason: string;
118
+ targetWorkflowId: string | null;
119
+ targetVersion: string | null;
120
+ entityUuid: string;
121
+ /** Blocking: the proposal is not used. */
122
+ problems: string[];
123
+ /** Not blocking, for the person who approves (e.g. a credential to set). */
124
+ notes: string[];
125
+ workflow: N8nWorkflow | null;
126
+ contentHash: string | null;
127
+ }
128
+ export declare function checkPlan(ctx: PlanContext, answerRaw: unknown, existing?: N8nWorkflow | null): PlanCheck;
129
+ export declare function draftWorkflow(plan: PlanCheck, change: EntityChange, target?: N8nWorkflow | null): N8nWorkflow;
130
+ /** The hash a draft stands for: its content, or for a deactivation the target and its version. */
131
+ export declare function draftHash(draft: N8nWorkflow): {
132
+ info: DraftInfo;
133
+ hash: string;
134
+ };
135
+ export type N8nRequest = (method: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, body?: unknown, qs?: Record<string, string | number>) => Promise<unknown>;
136
+ export declare class N8nApi {
137
+ private readonly request;
138
+ constructor(request: N8nRequest);
139
+ listWorkflows(tag: string): Promise<N8nWorkflow[]>;
140
+ get(id: string): Promise<N8nWorkflow>;
141
+ create(wf: N8nWorkflow): Promise<N8nWorkflow>;
142
+ update(id: string, wf: N8nWorkflow): Promise<N8nWorkflow>;
143
+ remove(id: string): Promise<void>;
144
+ activate(id: string): Promise<void>;
145
+ deactivate(id: string): Promise<void>;
146
+ /** Sets the tags of a workflow by name, creating tags that do not exist yet. */
147
+ setTags(id: string, names: string[]): Promise<void>;
148
+ }
149
+ export interface ApplyResult {
150
+ applied: boolean;
151
+ action: DraftInfo['action'];
152
+ workflowId: string;
153
+ draftId: string;
154
+ activated: boolean;
155
+ reason: string;
156
+ }
157
+ /**
158
+ * Applies an approved draft. Fail-closed: the draft must still hash to what was approved,
159
+ * and the target must still be the version the draft was made from.
160
+ */
161
+ export declare function applyDraft(api: N8nApi, draftId: string, approvedHash: string, opts?: {
162
+ activate?: boolean;
163
+ }): Promise<ApplyResult>;
164
+ /** Deletes a rejected draft. Refuses anything that is not a draft. */
165
+ export declare function discardDraft(api: N8nApi, draftId: string): Promise<{
166
+ discarded: boolean;
167
+ draftId: string;
168
+ }>;
169
+ /** The entity as roleALPHA shows it now, without persons: a step with its roles, anything else with its edges. */
170
+ export declare function entityContext(src: GraphSource, change: EntityChange): Promise<unknown>;