@rolealpha/n8n-nodes-rolealpha 0.10.0 → 0.11.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.
@@ -12,6 +12,7 @@ const share_1 = require("../../lib/share");
12
12
  const waits_1 = require("../../lib/waits");
13
13
  const settings_1 = require("../../lib/settings");
14
14
  const memory_1 = require("../../lib/memory");
15
+ const knowledge_1 = require("../../lib/knowledge");
15
16
  const agentRun_1 = require("../../lib/agentRun");
16
17
  const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
17
18
  const show = (resource, operation) => ({ show: { resource: [resource], operation } });
@@ -358,6 +359,14 @@ const properties = [
358
359
  description: 'Output of Memory → Select (optional). Set it, even empty, when the agent has the remember tool: it adds the rules for remembering and what the roles remember.',
359
360
  displayOptions: show('prompt', ['buildSystemPrompt']),
360
361
  },
362
+ {
363
+ displayName: 'Knowledge',
364
+ name: 'knowledge',
365
+ type: 'json',
366
+ default: '',
367
+ description: 'Output of Memory → Select Pages (optional). Set it, even empty, when knowledge pages are on: it adds what the pages of the roles and circles hold and the rules that keep knowledge apart from policies.',
368
+ displayOptions: show('prompt', ['buildSystemPrompt']),
369
+ },
361
370
  {
362
371
  displayName: 'Additional Rules',
363
372
  name: 'extraRules',
@@ -471,6 +480,12 @@ const properties = [
471
480
  { name: 'Check Write', value: 'checkWrite', action: 'Check a fact to remember', description: 'Checks a remember call of the agent and returns the row to add, or the reason it is not kept' },
472
481
  { name: 'Select', value: 'select', action: 'Pick what the roles remember', description: 'The facts of the roles the agent fills now, for this step and these records, within the limits' },
473
482
  { name: 'Consolidate', value: 'consolidate', action: 'Clean up the memory', description: 'For a scheduler: rows to delete (expired, replaced, forgotten, over the limit per role)' },
483
+ { name: 'Locate Pages', value: 'locatePages', action: 'Locate the knowledge pages', description: 'Paths of the pages of the roles the agent fills and of their circles, to read from your store' },
484
+ { name: 'Select Pages', value: 'selectPages', action: 'Pick the knowledge for the prompt', description: 'What the pages of the agent\'s roles and circles hold, within the size limit; proposals for roleALPHA stay out' },
485
+ { name: 'Write Page', value: 'writePage', action: 'Add a fact to its page', description: 'The new content of the page for a fact Check Write sent to a page; your store writes it if the page still has the base version' },
486
+ { name: 'Build Curation Prompt', value: 'curationPrompt', action: 'Build the prompt to curate a page', description: 'Sort new entries in, merge, link, drop what is outdated or contradicts a policy' },
487
+ { name: 'Check Curation', value: 'checkCuration', action: 'Check a curated page', description: 'Frontmatter kept, nothing about persons or secrets added, no rules, within the deletion limit' },
488
+ { name: 'Lint Pages', value: 'lintPages', action: 'Find pages to curate or repair', description: 'For a scheduler: pages due for curation, of roles that are gone, without UUID, with broken links' },
474
489
  ],
475
490
  default: 'checkWrite',
476
491
  },
@@ -489,7 +504,66 @@ const properties = [
489
504
  default: '',
490
505
  required: true,
491
506
  description: 'Output of Agent → Get Context of this run. Only the roles the agent fills there count.',
492
- displayOptions: show('memory', ['checkWrite', 'select']),
507
+ displayOptions: show('memory', ['checkWrite', 'select', 'locatePages', 'selectPages', 'curationPrompt']),
508
+ },
509
+ {
510
+ displayName: 'Pages',
511
+ name: 'pages',
512
+ type: 'json',
513
+ default: '={{ $input.all().map(item => item.json) }}',
514
+ description: 'Pages read from your store, each with path, content (Markdown) and version (a Git SHA, a counter, …)',
515
+ displayOptions: show('memory', ['selectPages', 'lintPages']),
516
+ },
517
+ {
518
+ displayName: 'Circles',
519
+ name: 'circles',
520
+ type: 'json',
521
+ default: '',
522
+ description: 'Output of Responsibility → Get Circle Lead for the agent (all items), e.g. {{ $(\'Get Circle Lead\').all().map(i => i.json) }}. Circles the bundle reaches count as well.',
523
+ displayOptions: show('memory', ['checkWrite', 'locatePages', 'selectPages', 'curationPrompt']),
524
+ },
525
+ {
526
+ displayName: 'Knowledge Pages',
527
+ name: 'knowledgePages',
528
+ type: 'boolean',
529
+ default: false,
530
+ description: 'Whether lasting facts of a role (scope role) and of a circle (scope circle) go to its page instead of a row. Notes on a step or records stay rows.',
531
+ displayOptions: show('memory', ['checkWrite']),
532
+ },
533
+ {
534
+ displayName: 'Write',
535
+ name: 'write',
536
+ type: 'json',
537
+ default: '',
538
+ required: true,
539
+ description: 'Output of Memory → Check Write with target "page"',
540
+ displayOptions: show('memory', ['writePage']),
541
+ },
542
+ {
543
+ displayName: 'Page',
544
+ name: 'page',
545
+ type: 'json',
546
+ default: '',
547
+ description: 'The page as read from your store: path, content, version. Empty when it does not exist yet.',
548
+ displayOptions: show('memory', ['writePage', 'curationPrompt', 'checkCuration']),
549
+ },
550
+ {
551
+ displayName: 'Answer',
552
+ name: 'answer',
553
+ type: 'string',
554
+ typeOptions: { rows: 6 },
555
+ default: '',
556
+ required: true,
557
+ description: 'What the model answered to Build Curation Prompt: the whole page in a markdown block',
558
+ displayOptions: show('memory', ['checkCuration']),
559
+ },
560
+ {
561
+ displayName: 'Existing Pages',
562
+ name: 'existingPages',
563
+ type: 'json',
564
+ default: '',
565
+ description: 'Optional: all pages of the store as path and name, so a curation may only link to pages that exist',
566
+ displayOptions: show('memory', ['curationPrompt', 'checkCuration']),
493
567
  },
494
568
  {
495
569
  displayName: 'Step',
@@ -529,15 +603,15 @@ const properties = [
529
603
  name: 'knownRoles',
530
604
  type: 'string',
531
605
  default: '',
532
- description: 'Optional: the roles that still exist (comma-separated or an array). Facts of other roles are removed.',
533
- displayOptions: show('memory', ['consolidate']),
606
+ description: 'Optional: the roles (and, for pages, circles) that still exist (comma-separated or an array). Facts of other roles are removed; their pages are reported as orphaned.',
607
+ displayOptions: show('memory', ['consolidate', 'lintPages']),
534
608
  },
535
609
  {
536
610
  displayName: 'Settings Rows',
537
611
  name: 'settingRows',
538
612
  type: 'json',
539
613
  default: '',
540
- description: 'Optional rows of the settings table: maxMemoryFacts, maxMemoryChars, memoryTtlDays, keepMemoryFacts (global < step < agent)',
614
+ description: 'Optional rows of the settings table: maxMemoryFacts, maxMemoryChars, memoryTtlDays, keepMemoryFacts, and for pages maxKnowledgeChars, maxPageChars, maxNewEntries, knowledgeCurateDays, maxCurationDeletePct, knowledgeLinkDepth (global < step < agent)',
541
615
  displayOptions: { show: { resource: ['memory'] } },
542
616
  },
543
617
  {
@@ -547,7 +621,7 @@ const properties = [
547
621
  placeholder: 'Add Option',
548
622
  default: {},
549
623
  description: 'Your company decides. Secrets are always refused.',
550
- displayOptions: show('memory', ['checkWrite']),
624
+ displayOptions: show('memory', ['checkWrite', 'checkCuration']),
551
625
  options: [
552
626
  { displayName: 'Block E-Mail Addresses', name: 'blockEmails', type: 'boolean', default: true },
553
627
  { displayName: 'Block UUIDs', name: 'blockUuids', type: 'boolean', default: true },
@@ -557,6 +631,22 @@ const properties = [
557
631
  { displayName: 'Blocked Patterns', name: 'blockedPatterns', type: 'string', typeOptions: { rows: 3 }, default: '', description: 'One regular expression per line, e.g. for an IBAN' },
558
632
  ],
559
633
  },
634
+ {
635
+ displayName: 'Knowledge Options',
636
+ name: 'knowledgeOptions',
637
+ type: 'collection',
638
+ placeholder: 'Add Option',
639
+ default: {},
640
+ description: 'Use the same values in every node of your knowledge workflows',
641
+ displayOptions: show('memory', ['checkWrite', 'locatePages', 'selectPages', 'writePage', 'curationPrompt', 'checkCuration']),
642
+ options: [
643
+ { displayName: 'Path Template', name: 'pathTemplate', type: 'string', default: '{entity}s/{uuid}.md', description: 'Where the page of a role or circle lives. Placeholders: {entity} (role, circle), {uuid}, {slug}. The UUID keeps a page when the role is renamed.' },
644
+ { displayName: 'Language', name: 'language', type: 'options', options: [{ name: 'German', value: 'de' }, { name: 'English', value: 'en' }], default: 'de', description: 'Headings and type names of new pages; pages in either language are read' },
645
+ { displayName: 'Normative Terms', name: 'normativeTerms', type: 'string', typeOptions: { rows: 3 }, default: '', description: 'Words that make a statement a rule (one per line or comma-separated). Empty: muss, darf nicht, verboten, must, must not, shall, not allowed, … A fact with one of them goes to the proposals for roleALPHA, not into the prompt.' },
646
+ { displayName: 'Allow Rules in Curation', name: 'allowNormativeCuration', type: 'boolean', default: false, description: 'Whether a curation may add normative statements outside the proposals' },
647
+ { displayName: 'Curating Role', name: 'curatingRole', type: 'string', default: '', description: 'Role (UUID or name) whose holders curate circle pages. Empty: any role of the circle.' },
648
+ ],
649
+ },
560
650
  // ---------------------------------------------------------------- settings
561
651
  {
562
652
  displayName: 'Operation',
@@ -697,6 +787,66 @@ function stepParamJson(ctx, i) {
697
787
  const step = (raw && typeof raw.step === 'object' ? raw.step : raw);
698
788
  return step && typeof step === 'object' && step.uuid ? step : null;
699
789
  }
790
+ function knowledgeLimits(rows, agentUuid) {
791
+ const s = (0, settings_1.resolveSettings)(rows, { agentUuid }).settings;
792
+ return {
793
+ maxChars: s.maxKnowledgeChars,
794
+ maxPageChars: s.maxPageChars,
795
+ maxNewEntries: s.maxNewEntries,
796
+ curateAfterDays: s.knowledgeCurateDays,
797
+ maxDeletePct: s.maxCurationDeletePct,
798
+ linkDepth: s.knowledgeLinkDepth,
799
+ };
800
+ }
801
+ function knowledgeOptions(ctx, i) {
802
+ const o = ctx.getNodeParameter('knowledgeOptions', i, {});
803
+ const terms = String(o.normativeTerms ?? '')
804
+ .split(/\r?\n|,/)
805
+ .map((t) => t.trim())
806
+ .filter(Boolean);
807
+ return {
808
+ pathTemplate: String(o.pathTemplate ?? '').trim() || undefined,
809
+ language: o.language === 'en' ? 'en' : 'de',
810
+ normativeTerms: terms.length ? terms : undefined,
811
+ allowNormativeCuration: o.allowNormativeCuration === true,
812
+ curatingRole: String(o.curatingRole ?? '').trim() || undefined,
813
+ };
814
+ }
815
+ function listParam(ctx, name, i) {
816
+ const raw = parseJsonParam(ctx, name, i);
817
+ if (Array.isArray(raw))
818
+ return raw;
819
+ if (raw && typeof raw === 'object')
820
+ return [raw];
821
+ return [];
822
+ }
823
+ function pageParam(ctx, i) {
824
+ const raw = parseJsonParam(ctx, 'page', i);
825
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
826
+ return null;
827
+ if (typeof raw.content !== 'string')
828
+ return null;
829
+ return { path: String(raw.path ?? ''), content: raw.content, version: raw.version ?? null };
830
+ }
831
+ function memoryPolicyParam(ctx, i) {
832
+ const opts = ctx.getNodeParameter('memoryPolicy', i, {});
833
+ const lines = (v, split) => String(v ?? '').split(split).map((t) => t.trim()).filter(Boolean);
834
+ const policy = {
835
+ blockEmails: opts.blockEmails !== false,
836
+ blockUuids: opts.blockUuids !== false,
837
+ blockPhoneNumbers: opts.blockPhoneNumbers !== false,
838
+ blockPersonNames: opts.blockPersonNames !== false,
839
+ blockedTerms: lines(opts.blockedTerms, /\r?\n|,/),
840
+ blockedPatterns: lines(opts.blockedPatterns, /\r?\n/),
841
+ };
842
+ try {
843
+ (0, memory_1.compilePatterns)(policy.blockedPatterns);
844
+ }
845
+ catch (error) {
846
+ throw new n8n_workflow_1.NodeOperationError(ctx.getNode(), error.message, { itemIndex: i });
847
+ }
848
+ return policy;
849
+ }
700
850
  function memoryLimits(rows, bundle, step) {
701
851
  const s = (0, settings_1.resolveSettings)(rows, { agentUuid: bundle.agent?.uuid ?? '', stepUuid: step?.uuid ?? '', stepCustomId: step?.customId ?? '' }).settings;
702
852
  return { maxFacts: s.maxMemoryFacts, maxChars: s.maxMemoryChars, ttlDays: s.memoryTtlDays, keepFacts: s.keepMemoryFacts };
@@ -985,8 +1135,33 @@ class RoleAlpha {
985
1135
  const plan = (0, waits_1.planAfterRun)(rows, run, waitOpts);
986
1136
  return [[{ json: plan }]];
987
1137
  }
1138
+ // Pages: Locate, Select and Lint look at all pages (or none) at once.
1139
+ if (resource === 'memory' && ['locatePages', 'selectPages', 'lintPages'].includes(operation)) {
1140
+ const settingRowsRaw = parseJsonParam(this, 'settingRows', 0);
1141
+ const settingRows = (Array.isArray(settingRowsRaw) ? settingRowsRaw : []);
1142
+ if (operation === 'lintPages') {
1143
+ const knownRaw = this.getNodeParameter('knownRoles', 0, '');
1144
+ const known = (Array.isArray(knownRaw) ? knownRaw : String(knownRaw ?? '').split(',')).map((v) => String(v).trim()).filter(Boolean);
1145
+ const res = (0, knowledge_1.lintPages)(parseJsonParam(this, 'pages', 0), { knownUuids: known, limits: knowledgeLimits(settingRows, '') });
1146
+ return [[{ json: res }]];
1147
+ }
1148
+ const bundle = bundleParam(this, 0);
1149
+ const circles = listParam(this, 'circles', 0);
1150
+ const opts = knowledgeOptions(this, 0);
1151
+ let refs;
1152
+ try {
1153
+ refs = (0, knowledge_1.locatePages)(bundle, circles, opts);
1154
+ }
1155
+ catch (error) {
1156
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error.message);
1157
+ }
1158
+ if (operation === 'locatePages')
1159
+ return [refs.map((r) => ({ json: r }))];
1160
+ const res = (0, knowledge_1.selectKnowledge)(parseJsonParam(this, 'pages', 0), { bundle, circles, opts, limits: knowledgeLimits(settingRows, bundle.agent?.uuid ?? '') });
1161
+ return [[{ json: res }]];
1162
+ }
988
1163
  // Memory: Select and Consolidate look at all stored rows at once.
989
- if (resource === 'memory' && operation !== 'checkWrite') {
1164
+ if (resource === 'memory' && (operation === 'select' || operation === 'consolidate')) {
990
1165
  const rows = parseJsonParam(this, 'rows', 0);
991
1166
  const settingRowsRaw = parseJsonParam(this, 'settingRows', 0);
992
1167
  const settingRows = (Array.isArray(settingRowsRaw) ? settingRowsRaw : []);
@@ -1005,6 +1180,44 @@ class RoleAlpha {
1005
1180
  }
1006
1181
  for (let i = 0; i < items.length; i++) {
1007
1182
  try {
1183
+ if (resource === 'memory' && operation !== 'checkWrite') {
1184
+ const settingRowsRaw = parseJsonParam(this, 'settingRows', i);
1185
+ const settingRows = (Array.isArray(settingRowsRaw) ? settingRowsRaw : []);
1186
+ const opts = knowledgeOptions(this, i);
1187
+ const page = pageParam(this, i);
1188
+ let res;
1189
+ if (operation === 'writePage') {
1190
+ const write = parseJsonParam(this, 'write', i);
1191
+ res = (0, knowledge_1.writeEntry)(write, page, opts, knowledgeLimits(settingRows, String(write?.entry?.agent ?? '')));
1192
+ }
1193
+ else if (operation === 'curationPrompt') {
1194
+ if (!page)
1195
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Page is empty: there is nothing to curate', { itemIndex: i });
1196
+ const bundle = bundleParam(this, i);
1197
+ res = (0, knowledge_1.buildCurationPrompt)({
1198
+ page,
1199
+ bundle,
1200
+ circles: listParam(this, 'circles', i),
1201
+ existing: listParam(this, 'existingPages', i),
1202
+ opts,
1203
+ limits: knowledgeLimits(settingRows, bundle.agent?.uuid ?? ''),
1204
+ });
1205
+ }
1206
+ else {
1207
+ if (!page)
1208
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Page is empty: give the page that was curated', { itemIndex: i });
1209
+ const existing = listParam(this, 'existingPages', i).map((p) => String(p?.path ?? '')).filter(Boolean);
1210
+ res = (0, knowledge_1.checkCuration)(page, String(this.getNodeParameter('answer', i, '') ?? ''), {
1211
+ policy: memoryPolicyParam(this, i),
1212
+ opts,
1213
+ limits: knowledgeLimits(settingRows, ''),
1214
+ existingPaths: existing,
1215
+ });
1216
+ }
1217
+ // A refusal is data, so the workflow can retry, report or leave the page as it is.
1218
+ out.push({ json: res, pairedItem: { item: i } });
1219
+ continue;
1220
+ }
1008
1221
  if (resource === 'memory') {
1009
1222
  const bundle = bundleParam(this, i);
1010
1223
  const step = stepParamJson(this, i);
@@ -1012,22 +1225,8 @@ class RoleAlpha {
1012
1225
  const limits = memoryLimits((Array.isArray(settingRowsRaw) ? settingRowsRaw : []), bundle, step);
1013
1226
  const raw = parseJsonParam(this, 'request', i);
1014
1227
  const request = (raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : {});
1015
- const opts = this.getNodeParameter('memoryPolicy', i, {});
1016
- const lines = (v, split) => String(v ?? '').split(split).map((t) => t.trim()).filter(Boolean);
1017
- const policy = {
1018
- blockEmails: opts.blockEmails !== false,
1019
- blockUuids: opts.blockUuids !== false,
1020
- blockPhoneNumbers: opts.blockPhoneNumbers !== false,
1021
- blockPersonNames: opts.blockPersonNames !== false,
1022
- blockedTerms: lines(opts.blockedTerms, /\r?\n|,/),
1023
- blockedPatterns: lines(opts.blockedPatterns, /\r?\n/),
1024
- };
1025
- try {
1026
- (0, memory_1.compilePatterns)(policy.blockedPatterns);
1027
- }
1028
- catch (error) {
1029
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), error.message, { itemIndex: i });
1030
- }
1228
+ const policy = memoryPolicyParam(this, i);
1229
+ const knowledgeOn = this.getNodeParameter('knowledgePages', i, false) === true;
1031
1230
  const res = (0, memory_1.checkWrite)(request, {
1032
1231
  bundle,
1033
1232
  step,
@@ -1035,6 +1234,7 @@ class RoleAlpha {
1035
1234
  runId: String(this.getNodeParameter('memoryRunId', i, '') ?? ''),
1036
1235
  ttlDays: limits.ttlDays,
1037
1236
  policy,
1237
+ knowledge: knowledgeOn ? { enabled: true, circles: listParam(this, 'circles', i), opts: knowledgeOptions(this, i) } : null,
1038
1238
  });
1039
1239
  // A refusal is data, so the model can shorten or rephrase the fact.
1040
1240
  out.push({ json: res, pairedItem: { item: i } });
@@ -1142,6 +1342,12 @@ class RoleAlpha {
1142
1342
  : memoryRaw && typeof memoryRaw === 'object' && Array.isArray(memoryRaw.memory)
1143
1343
  ? memoryRaw.memory
1144
1344
  : null;
1345
+ const knowledgeRaw = parseJsonParam(this, 'knowledge', i);
1346
+ const knowledge = Array.isArray(knowledgeRaw)
1347
+ ? knowledgeRaw
1348
+ : knowledgeRaw && typeof knowledgeRaw === 'object' && Array.isArray(knowledgeRaw.knowledge)
1349
+ ? knowledgeRaw.knowledge
1350
+ : null;
1145
1351
  const rules = String(this.getNodeParameter('extraRules', i, '') ?? '')
1146
1352
  .split(/\r?\n/)
1147
1353
  .map((r) => r.trim())
@@ -1154,6 +1360,7 @@ class RoleAlpha {
1154
1360
  extraRules: rules,
1155
1361
  share,
1156
1362
  memory,
1363
+ knowledge,
1157
1364
  });
1158
1365
  const json = { ...items[i].json, systemPrompt };
1159
1366
  if (share && step)