@rolealpha/n8n-nodes-rolealpha 0.10.0 → 0.12.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.
- package/README.md +165 -1
- package/dist/lib/agentRun.d.ts +38 -1
- package/dist/lib/agentRun.js +66 -1
- package/dist/lib/agentRun.js.map +1 -1
- package/dist/lib/knowledge.d.ts +261 -0
- package/dist/lib/knowledge.js +615 -0
- package/dist/lib/knowledge.js.map +1 -0
- package/dist/lib/memory.d.ts +15 -1
- package/dist/lib/memory.js +62 -5
- package/dist/lib/memory.js.map +1 -1
- package/dist/lib/pricing.d.ts +53 -0
- package/dist/lib/pricing.js +112 -0
- package/dist/lib/pricing.js.map +1 -0
- package/dist/lib/prompt.d.ts +9 -2
- package/dist/lib/prompt.js +37 -4
- package/dist/lib/prompt.js.map +1 -1
- package/dist/lib/settings.d.ts +12 -0
- package/dist/lib/settings.js +12 -0
- package/dist/lib/settings.js.map +1 -1
- package/dist/nodes/RoleAlpha/RoleAlpha.node.js +353 -27
- package/dist/nodes/RoleAlpha/RoleAlpha.node.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge of roles and circles: lasting experience kept as Markdown pages with YAML
|
|
3
|
+
* frontmatter, one page per role and per circle, a small wiki the organisation owns. It
|
|
4
|
+
* belongs to the role or the circle, never to the agent, and people can read, link and
|
|
5
|
+
* correct it in any editor.
|
|
6
|
+
*
|
|
7
|
+
* As with the memory rows, these functions only decide; where the pages live is up to the
|
|
8
|
+
* workflow: an n8n data table on the company's own n8n, a Git repository through its
|
|
9
|
+
* contents API, a folder. The functions see a page only as { path, content, version }.
|
|
10
|
+
*
|
|
11
|
+
* Knowledge is not a rule. What is binding (policies, accountabilities, steps) lives in
|
|
12
|
+
* roleALPHA and changes only by an approved draft. Knowledge says how a role does its work
|
|
13
|
+
* well: experience, observations, what worked. A normative statement ("must", "never
|
|
14
|
+
* allowed") written by an agent goes to the section of proposals for roleALPHA, which is not
|
|
15
|
+
* part of the prompt, until it is rephrased as experience or proposed as a draft.
|
|
16
|
+
*
|
|
17
|
+
* Page layout (headings in German or English, both are read):
|
|
18
|
+
*
|
|
19
|
+
* ---
|
|
20
|
+
* type: Rollenwissen (Kreiswissen for a circle)
|
|
21
|
+
* schema: rolealpha-knowledge/1
|
|
22
|
+
* entity: role (circle)
|
|
23
|
+
* uuid: <uuid of the role or circle>
|
|
24
|
+
* name: <its name, refreshed on every write>
|
|
25
|
+
* updated: <ISO date>
|
|
26
|
+
* ---
|
|
27
|
+
* # <name> – Wissen
|
|
28
|
+
* > note that this is experience, not rules
|
|
29
|
+
* ## Neu entries of agents, not yet curated
|
|
30
|
+
* - fact <!-- ra:{"at":"…","topic":"…","run":"…","agent":"…"} -->
|
|
31
|
+
* ## <any topic> curated by the curation run or by people
|
|
32
|
+
* ## Vorschläge für roleALPHA normative statements, not in the prompt
|
|
33
|
+
* ## Siehe auch links to other pages
|
|
34
|
+
*/
|
|
35
|
+
import type { ContextBundle } from './prompt';
|
|
36
|
+
import { type MemoryPolicy } from './memory';
|
|
37
|
+
export declare const KNOWLEDGE_SCHEMA = "rolealpha-knowledge/1";
|
|
38
|
+
export type PageEntity = 'role' | 'circle';
|
|
39
|
+
export type KnowledgeLanguage = 'de' | 'en';
|
|
40
|
+
/** A page as the store hands it over. `version` is whatever the store uses to detect a concurrent change (a Git SHA, a counter, a timestamp). */
|
|
41
|
+
export interface Page {
|
|
42
|
+
path: string;
|
|
43
|
+
content: string;
|
|
44
|
+
version?: string | number | null;
|
|
45
|
+
}
|
|
46
|
+
/** Which page belongs to which role or circle. */
|
|
47
|
+
export interface PageRef {
|
|
48
|
+
path: string;
|
|
49
|
+
entity: PageEntity;
|
|
50
|
+
uuid: string;
|
|
51
|
+
name: string;
|
|
52
|
+
}
|
|
53
|
+
export interface KnowledgeOptions {
|
|
54
|
+
/** Where the page of a role or circle lives. Placeholders: {entity} (role, circle), {uuid}, {slug}. Default "{entity}s/{uuid}.md". */
|
|
55
|
+
pathTemplate?: string;
|
|
56
|
+
/** Language of headings and type names written to new pages. Pages in either language are read. */
|
|
57
|
+
language?: KnowledgeLanguage;
|
|
58
|
+
/** Words that make a statement a rule rather than experience. Default: a short list in German and English. */
|
|
59
|
+
normativeTerms?: string[];
|
|
60
|
+
/** Whether a curation may add normative statements outside the proposals. Default false. */
|
|
61
|
+
allowNormativeCuration?: boolean;
|
|
62
|
+
/** Role (UUID or name) whose holders curate circle pages. Empty: any role of the circle. */
|
|
63
|
+
curatingRole?: string;
|
|
64
|
+
}
|
|
65
|
+
export interface KnowledgeLimits {
|
|
66
|
+
/** Characters of all pages in one prompt. */
|
|
67
|
+
maxChars?: number;
|
|
68
|
+
/** Size of a page before it has to be curated; a write is refused beyond twice this size. */
|
|
69
|
+
maxPageChars?: number;
|
|
70
|
+
/** Entries under "new" from which a page counts as due for curation. */
|
|
71
|
+
maxNewEntries?: number;
|
|
72
|
+
/** Share (percent) of the curated text a curation may delete. Entries under "new" do not count. */
|
|
73
|
+
maxDeletePct?: number;
|
|
74
|
+
/** 0: only the own pages; 1: also pages they link to. */
|
|
75
|
+
linkDepth?: number;
|
|
76
|
+
/** Days after which a page with new entries is curated even below maxNewEntries. */
|
|
77
|
+
curateAfterDays?: number;
|
|
78
|
+
}
|
|
79
|
+
export declare const DEFAULT_KNOWLEDGE_LIMITS: Required<KnowledgeLimits>;
|
|
80
|
+
/** A circle as Responsibility → Get Circle Lead returns it: the circle and the agent's roles in it. */
|
|
81
|
+
export interface CircleInfo {
|
|
82
|
+
circle: {
|
|
83
|
+
uuid: string;
|
|
84
|
+
name: string;
|
|
85
|
+
};
|
|
86
|
+
roles?: Array<{
|
|
87
|
+
uuid: string;
|
|
88
|
+
name?: string;
|
|
89
|
+
}>;
|
|
90
|
+
}
|
|
91
|
+
/** What Memory → Check Write hands over when a fact goes to a page. */
|
|
92
|
+
export interface PageWrite {
|
|
93
|
+
ok: true;
|
|
94
|
+
target: 'page';
|
|
95
|
+
page: PageRef;
|
|
96
|
+
entry: KnowledgeEntry;
|
|
97
|
+
}
|
|
98
|
+
export interface KnowledgeEntry {
|
|
99
|
+
text: string;
|
|
100
|
+
topic: string;
|
|
101
|
+
at: string;
|
|
102
|
+
run: string;
|
|
103
|
+
agent: string;
|
|
104
|
+
/** Forget the topic instead of adding to it. */
|
|
105
|
+
forget: boolean;
|
|
106
|
+
/** The statement reads as a rule; it goes to the proposals for roleALPHA. */
|
|
107
|
+
normative: boolean;
|
|
108
|
+
}
|
|
109
|
+
export interface KnowledgePage {
|
|
110
|
+
path: string;
|
|
111
|
+
entity: PageEntity;
|
|
112
|
+
uuid: string;
|
|
113
|
+
name: string;
|
|
114
|
+
/** Own page of a role the agent fills or of its circle, or a page linked from one. */
|
|
115
|
+
via: 'own' | 'linked';
|
|
116
|
+
text: string;
|
|
117
|
+
truncated: boolean;
|
|
118
|
+
}
|
|
119
|
+
/** Deontic words: a statement with one of them says what has to be, not what was learned. */
|
|
120
|
+
export declare const DEFAULT_NORMATIVE_TERMS: string[];
|
|
121
|
+
/** Whether a statement reads as a rule. */
|
|
122
|
+
export declare function isNormative(text: string, terms?: string[]): boolean;
|
|
123
|
+
export declare function slugOf(name: string): string;
|
|
124
|
+
export declare function pagePath(entity: PageEntity, uuid: string, name: string, template?: string): string;
|
|
125
|
+
/** The circles of the agent's roles: from Get Circle Lead, and circles the bundle itself reaches through a role. */
|
|
126
|
+
export declare function ownCircles(bundle: ContextBundle, circles: CircleInfo[] | null | undefined): Array<{
|
|
127
|
+
uuid: string;
|
|
128
|
+
name: string;
|
|
129
|
+
roles: string[];
|
|
130
|
+
}>;
|
|
131
|
+
/** The pages that belong to the agent in this run: one per role it fills, one per circle of these roles. */
|
|
132
|
+
export declare function locatePages(bundle: ContextBundle, circles: CircleInfo[] | null | undefined, opts?: KnowledgeOptions): PageRef[];
|
|
133
|
+
interface Section {
|
|
134
|
+
heading: string;
|
|
135
|
+
lines: string[];
|
|
136
|
+
}
|
|
137
|
+
export interface ParsedPage {
|
|
138
|
+
/** Frontmatter lines without the fences; kept as written so human additions survive. */
|
|
139
|
+
frontmatter: string[];
|
|
140
|
+
data: Record<string, string>;
|
|
141
|
+
title: string;
|
|
142
|
+
/** Lines between the title and the first section (the note). */
|
|
143
|
+
intro: string[];
|
|
144
|
+
sections: Section[];
|
|
145
|
+
}
|
|
146
|
+
export declare function parsePage(content: string): ParsedPage;
|
|
147
|
+
export declare function renderPage(p: ParsedPage): string;
|
|
148
|
+
/** Metadata of an entry written by an agent, or null for text written by people. */
|
|
149
|
+
export declare function entryMeta(line: string): {
|
|
150
|
+
topic?: string;
|
|
151
|
+
at?: string;
|
|
152
|
+
run?: string;
|
|
153
|
+
agent?: string;
|
|
154
|
+
} | null;
|
|
155
|
+
export declare function newPage(ref: PageRef, opts?: KnowledgeOptions, now?: Date): ParsedPage;
|
|
156
|
+
export type PageWriteResult = {
|
|
157
|
+
ok: true;
|
|
158
|
+
path: string;
|
|
159
|
+
content: string;
|
|
160
|
+
baseVersion: string | number | null;
|
|
161
|
+
nextVersion: number;
|
|
162
|
+
created: boolean;
|
|
163
|
+
section: 'fresh' | 'proposals' | 'forgotten';
|
|
164
|
+
removed: number;
|
|
165
|
+
} | {
|
|
166
|
+
ok: false;
|
|
167
|
+
error: string;
|
|
168
|
+
problems: string[];
|
|
169
|
+
};
|
|
170
|
+
/** Adds an entry checked by Memory → Check Write to its page (or makes the page). The store writes `content` only if the page still has `baseVersion`. */
|
|
171
|
+
export declare function writeEntry(write: PageWrite, page: Page | null | undefined, opts?: KnowledgeOptions, limits?: KnowledgeLimits, now?: Date): PageWriteResult;
|
|
172
|
+
/** Wiki links of a page: [[target]] or [[target|label]]; the target without ".md". */
|
|
173
|
+
export declare function linksOf(text: string): string[];
|
|
174
|
+
/** What goes into the prompt: the pages of the agent's roles and circles (and, with linkDepth 1, pages they link to), within the size limit. */
|
|
175
|
+
export declare function selectKnowledge(pagesIn: unknown, ctx: {
|
|
176
|
+
bundle: ContextBundle;
|
|
177
|
+
circles?: CircleInfo[] | null;
|
|
178
|
+
opts?: KnowledgeOptions;
|
|
179
|
+
limits?: KnowledgeLimits;
|
|
180
|
+
}): {
|
|
181
|
+
knowledge: KnowledgePage[];
|
|
182
|
+
linked: string[];
|
|
183
|
+
missing: PageRef[];
|
|
184
|
+
omitted: number;
|
|
185
|
+
};
|
|
186
|
+
/** Whether the agent of this bundle may curate the page: its own role's page, or a page of its circle (with Curating Role, only that role). */
|
|
187
|
+
export declare function mayCurate(bundle: ContextBundle, ref: Pick<PageRef, 'entity' | 'uuid'>, circles: CircleInfo[] | null | undefined, opts?: KnowledgeOptions): {
|
|
188
|
+
ok: boolean;
|
|
189
|
+
reason: string;
|
|
190
|
+
};
|
|
191
|
+
/** The prompt for the curation of one page: sort the new entries in, merge, link, drop what is outdated or a rule. */
|
|
192
|
+
export declare function buildCurationPrompt(input: {
|
|
193
|
+
page: Page;
|
|
194
|
+
bundle: ContextBundle;
|
|
195
|
+
circles?: CircleInfo[] | null;
|
|
196
|
+
existing?: Array<{
|
|
197
|
+
path: string;
|
|
198
|
+
name?: string;
|
|
199
|
+
}> | null;
|
|
200
|
+
opts?: KnowledgeOptions;
|
|
201
|
+
limits?: KnowledgeLimits;
|
|
202
|
+
}): {
|
|
203
|
+
ok: true;
|
|
204
|
+
systemPrompt: string;
|
|
205
|
+
task: string;
|
|
206
|
+
ref: PageRef;
|
|
207
|
+
} | {
|
|
208
|
+
ok: false;
|
|
209
|
+
error: string;
|
|
210
|
+
};
|
|
211
|
+
export type CurationResult = {
|
|
212
|
+
ok: true;
|
|
213
|
+
path: string;
|
|
214
|
+
content: string;
|
|
215
|
+
baseVersion: string | number | null;
|
|
216
|
+
nextVersion: number;
|
|
217
|
+
added: number;
|
|
218
|
+
deleted: number;
|
|
219
|
+
deletedPct: number;
|
|
220
|
+
} | {
|
|
221
|
+
ok: false;
|
|
222
|
+
error: string;
|
|
223
|
+
problems: string[];
|
|
224
|
+
};
|
|
225
|
+
/** Checks the page a model returned from a curation; only what it adds is checked for persons, secrets and the company's terms. */
|
|
226
|
+
export declare function checkCuration(old: Page, answer: string, ctx: {
|
|
227
|
+
policy?: MemoryPolicy;
|
|
228
|
+
opts?: KnowledgeOptions;
|
|
229
|
+
limits?: KnowledgeLimits;
|
|
230
|
+
existingPaths?: string[] | null;
|
|
231
|
+
now?: Date;
|
|
232
|
+
}): CurationResult;
|
|
233
|
+
export interface LintResult {
|
|
234
|
+
/** Pages due for curation: too many new entries, new entries older than curateAfterDays, or too big. */
|
|
235
|
+
curate: Array<{
|
|
236
|
+
path: string;
|
|
237
|
+
entity: PageEntity;
|
|
238
|
+
uuid: string;
|
|
239
|
+
name: string;
|
|
240
|
+
fresh: number;
|
|
241
|
+
proposals: number;
|
|
242
|
+
chars: number;
|
|
243
|
+
}>;
|
|
244
|
+
/** Pages of roles or circles that no longer exist (with Known UUIDs). */
|
|
245
|
+
orphaned: string[];
|
|
246
|
+
/** Pages without a uuid in their frontmatter. */
|
|
247
|
+
invalid: string[];
|
|
248
|
+
brokenLinks: Array<{
|
|
249
|
+
path: string;
|
|
250
|
+
link: string;
|
|
251
|
+
}>;
|
|
252
|
+
/** Rows of the same path (two writers made the page at once); keep the highest version. */
|
|
253
|
+
duplicates: string[];
|
|
254
|
+
}
|
|
255
|
+
/** For a scheduler: which pages to curate, archive or repair. */
|
|
256
|
+
export declare function lintPages(pagesIn: unknown, ctx?: {
|
|
257
|
+
knownUuids?: string[] | null;
|
|
258
|
+
limits?: KnowledgeLimits;
|
|
259
|
+
now?: Date;
|
|
260
|
+
}): LintResult;
|
|
261
|
+
export {};
|