@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
|
@@ -12,7 +12,9 @@ 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");
|
|
17
|
+
const pricing_1 = require("../../lib/pricing");
|
|
16
18
|
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
17
19
|
const show = (resource, operation) => ({ show: { resource: [resource], operation } });
|
|
18
20
|
const stepParam = (operations) => ({
|
|
@@ -55,6 +57,7 @@ const properties = [
|
|
|
55
57
|
{ name: 'Get Context', value: 'getContext', action: 'Get the context of an agent', description: 'Identity, roles and guardrails of one agent' },
|
|
56
58
|
{ name: 'Get Context Version', value: 'getContextVersion', action: 'Get the context version of an agent', description: 'Change check; cheap and not audited with agent keys' },
|
|
57
59
|
{ name: 'List Agents', value: 'listAgents', action: 'List agents', description: 'One item per agent of the organisation (MCP) or per key in the credential' },
|
|
60
|
+
{ name: 'Report Usage', value: 'reportUsage', action: 'Report the usage of a run', description: 'Reports what this run consumed (tokens, model, cost) with the function account, for the agent\'s budget in roleALPHA. The cost comes from your price rows; roleALPHA does not price runs.' },
|
|
58
61
|
{ name: 'Start Run', value: 'startRun', action: 'Start a run as an agent', description: 'Swaps the function account token for a run token of the agent (agent:run). A refusal comes back as data with its code.' },
|
|
59
62
|
],
|
|
60
63
|
default: 'getContext',
|
|
@@ -145,7 +148,7 @@ const properties = [
|
|
|
145
148
|
name: 'connectAs',
|
|
146
149
|
type: 'options',
|
|
147
150
|
noDataExpression: true,
|
|
148
|
-
displayOptions: { show: { resource: ['agent', 'responsibility', 'tool'] }, hide: { source: ['agentKey'], operation: ['startRun', 'listAgents'] } },
|
|
151
|
+
displayOptions: { show: { resource: ['agent', 'responsibility', 'tool'] }, hide: { source: ['agentKey'], operation: ['startRun', 'reportUsage', 'listAgents'] } },
|
|
149
152
|
options: [
|
|
150
153
|
{ name: 'Function Account', value: 'account', description: 'The view of the connection itself' },
|
|
151
154
|
{ name: 'Agent (Run Token)', value: 'agent', description: 'Exactly the view of the agent of this run (needs agent:run and a function account with client credentials)' },
|
|
@@ -159,7 +162,7 @@ const properties = [
|
|
|
159
162
|
default: '',
|
|
160
163
|
required: true,
|
|
161
164
|
description: 'The agent this run acts as',
|
|
162
|
-
displayOptions: { show: { resource: ['agent', 'responsibility', 'tool'], connectAs: ['agent'] }, hide: { source: ['agentKey'], operation: ['startRun', 'listAgents'] } },
|
|
165
|
+
displayOptions: { show: { resource: ['agent', 'responsibility', 'tool'], connectAs: ['agent'] }, hide: { source: ['agentKey'], operation: ['startRun', 'reportUsage', 'listAgents'] } },
|
|
163
166
|
},
|
|
164
167
|
{
|
|
165
168
|
displayName: 'Run Agent UUID',
|
|
@@ -168,7 +171,7 @@ const properties = [
|
|
|
168
171
|
default: '',
|
|
169
172
|
required: true,
|
|
170
173
|
description: 'The agent this run acts as',
|
|
171
|
-
displayOptions: show('agent', ['startRun']),
|
|
174
|
+
displayOptions: show('agent', ['startRun', 'reportUsage']),
|
|
172
175
|
},
|
|
173
176
|
{
|
|
174
177
|
displayName: 'Run ID',
|
|
@@ -176,7 +179,7 @@ const properties = [
|
|
|
176
179
|
type: 'string',
|
|
177
180
|
default: '={{ $execution.id }}',
|
|
178
181
|
description: 'Names the run in every audit entry; 1-128 characters of A-Z a-z 0-9 . _ : -. Sub-workflows of the run pass the same ID.',
|
|
179
|
-
displayOptions: { show: { resource: ['agent', 'responsibility', 'tool'], connectAs: ['agent'] }, hide: { source: ['agentKey'], operation: ['startRun', 'listAgents'] } },
|
|
182
|
+
displayOptions: { show: { resource: ['agent', 'responsibility', 'tool'], connectAs: ['agent'] }, hide: { source: ['agentKey'], operation: ['startRun', 'reportUsage', 'listAgents'] } },
|
|
180
183
|
},
|
|
181
184
|
{
|
|
182
185
|
displayName: 'Run ID',
|
|
@@ -184,7 +187,70 @@ const properties = [
|
|
|
184
187
|
type: 'string',
|
|
185
188
|
default: '={{ $execution.id }}',
|
|
186
189
|
description: 'Names the run in every audit entry; 1-128 characters of A-Z a-z 0-9 . _ : -. Sub-workflows of the run pass the same ID.',
|
|
187
|
-
displayOptions: show('agent', ['startRun']),
|
|
190
|
+
displayOptions: show('agent', ['startRun', 'reportUsage']),
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
displayName: 'Model',
|
|
194
|
+
name: 'usageModel',
|
|
195
|
+
type: 'string',
|
|
196
|
+
default: '',
|
|
197
|
+
description: 'The model the run used, e.g. from the chat model node. Looked up in the price rows.',
|
|
198
|
+
displayOptions: show('agent', ['reportUsage']),
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
displayName: 'Input Tokens',
|
|
202
|
+
name: 'usageInputTokens',
|
|
203
|
+
type: 'string',
|
|
204
|
+
default: '',
|
|
205
|
+
description: 'Uncached input tokens of the whole run',
|
|
206
|
+
displayOptions: show('agent', ['reportUsage']),
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
displayName: 'Output Tokens',
|
|
210
|
+
name: 'usageOutputTokens',
|
|
211
|
+
type: 'string',
|
|
212
|
+
default: '',
|
|
213
|
+
description: 'Output tokens of the whole run',
|
|
214
|
+
displayOptions: show('agent', ['reportUsage']),
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
displayName: 'Cache Read Tokens',
|
|
218
|
+
name: 'usageCacheReadTokens',
|
|
219
|
+
type: 'string',
|
|
220
|
+
default: '',
|
|
221
|
+
displayOptions: show('agent', ['reportUsage']),
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
displayName: 'Cache Write Tokens',
|
|
225
|
+
name: 'usageCacheWriteTokens',
|
|
226
|
+
type: 'string',
|
|
227
|
+
default: '',
|
|
228
|
+
displayOptions: show('agent', ['reportUsage']),
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
displayName: 'Price Rows',
|
|
232
|
+
name: 'priceRows',
|
|
233
|
+
type: 'json',
|
|
234
|
+
default: '',
|
|
235
|
+
placeholder: '[{"model":"claude-opus-5-5","input":4,"cacheRead":0.4,"cacheWrite":5,"output":20,"currency":"USD","asOf":"2026-11-20"}]',
|
|
236
|
+
description: 'Your prices per million tokens, one row per model (e.g. all rows of a data table). With your own AI key only you know them; roleALPHA does not price runs. Without a matching row the run is reported with tokens only and counts as "without a price".',
|
|
237
|
+
displayOptions: show('agent', ['reportUsage']),
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
displayName: 'Cost',
|
|
241
|
+
name: 'usageCost',
|
|
242
|
+
type: 'string',
|
|
243
|
+
default: '',
|
|
244
|
+
description: 'Optional: the cost of the run if the workflow already knows it. Overrides the price rows.',
|
|
245
|
+
displayOptions: show('agent', ['reportUsage']),
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
displayName: 'Currency',
|
|
249
|
+
name: 'usageCurrency',
|
|
250
|
+
type: 'string',
|
|
251
|
+
default: 'USD',
|
|
252
|
+
description: 'ISO code of Cost, e.g. USD',
|
|
253
|
+
displayOptions: show('agent', ['reportUsage']),
|
|
188
254
|
},
|
|
189
255
|
{
|
|
190
256
|
displayName: 'MCP Endpoint URL',
|
|
@@ -358,6 +424,14 @@ const properties = [
|
|
|
358
424
|
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
425
|
displayOptions: show('prompt', ['buildSystemPrompt']),
|
|
360
426
|
},
|
|
427
|
+
{
|
|
428
|
+
displayName: 'Knowledge',
|
|
429
|
+
name: 'knowledge',
|
|
430
|
+
type: 'json',
|
|
431
|
+
default: '',
|
|
432
|
+
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.',
|
|
433
|
+
displayOptions: show('prompt', ['buildSystemPrompt']),
|
|
434
|
+
},
|
|
361
435
|
{
|
|
362
436
|
displayName: 'Additional Rules',
|
|
363
437
|
name: 'extraRules',
|
|
@@ -471,6 +545,12 @@ const properties = [
|
|
|
471
545
|
{ 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
546
|
{ 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
547
|
{ name: 'Consolidate', value: 'consolidate', action: 'Clean up the memory', description: 'For a scheduler: rows to delete (expired, replaced, forgotten, over the limit per role)' },
|
|
548
|
+
{ 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' },
|
|
549
|
+
{ 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' },
|
|
550
|
+
{ 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' },
|
|
551
|
+
{ 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' },
|
|
552
|
+
{ 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' },
|
|
553
|
+
{ 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
554
|
],
|
|
475
555
|
default: 'checkWrite',
|
|
476
556
|
},
|
|
@@ -489,7 +569,66 @@ const properties = [
|
|
|
489
569
|
default: '',
|
|
490
570
|
required: true,
|
|
491
571
|
description: 'Output of Agent → Get Context of this run. Only the roles the agent fills there count.',
|
|
492
|
-
displayOptions: show('memory', ['checkWrite', 'select']),
|
|
572
|
+
displayOptions: show('memory', ['checkWrite', 'select', 'locatePages', 'selectPages', 'curationPrompt']),
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
displayName: 'Pages',
|
|
576
|
+
name: 'pages',
|
|
577
|
+
type: 'json',
|
|
578
|
+
default: '={{ $input.all().map(item => item.json) }}',
|
|
579
|
+
description: 'Pages read from your store, each with path, content (Markdown) and version (a Git SHA, a counter, …)',
|
|
580
|
+
displayOptions: show('memory', ['selectPages', 'lintPages']),
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
displayName: 'Circles',
|
|
584
|
+
name: 'circles',
|
|
585
|
+
type: 'json',
|
|
586
|
+
default: '',
|
|
587
|
+
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.',
|
|
588
|
+
displayOptions: show('memory', ['checkWrite', 'locatePages', 'selectPages', 'curationPrompt']),
|
|
589
|
+
},
|
|
590
|
+
{
|
|
591
|
+
displayName: 'Knowledge Pages',
|
|
592
|
+
name: 'knowledgePages',
|
|
593
|
+
type: 'boolean',
|
|
594
|
+
default: false,
|
|
595
|
+
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.',
|
|
596
|
+
displayOptions: show('memory', ['checkWrite']),
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
displayName: 'Write',
|
|
600
|
+
name: 'write',
|
|
601
|
+
type: 'json',
|
|
602
|
+
default: '',
|
|
603
|
+
required: true,
|
|
604
|
+
description: 'Output of Memory → Check Write with target "page"',
|
|
605
|
+
displayOptions: show('memory', ['writePage']),
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
displayName: 'Page',
|
|
609
|
+
name: 'page',
|
|
610
|
+
type: 'json',
|
|
611
|
+
default: '',
|
|
612
|
+
description: 'The page as read from your store: path, content, version. Empty when it does not exist yet.',
|
|
613
|
+
displayOptions: show('memory', ['writePage', 'curationPrompt', 'checkCuration']),
|
|
614
|
+
},
|
|
615
|
+
{
|
|
616
|
+
displayName: 'Answer',
|
|
617
|
+
name: 'answer',
|
|
618
|
+
type: 'string',
|
|
619
|
+
typeOptions: { rows: 6 },
|
|
620
|
+
default: '',
|
|
621
|
+
required: true,
|
|
622
|
+
description: 'What the model answered to Build Curation Prompt: the whole page in a markdown block',
|
|
623
|
+
displayOptions: show('memory', ['checkCuration']),
|
|
624
|
+
},
|
|
625
|
+
{
|
|
626
|
+
displayName: 'Existing Pages',
|
|
627
|
+
name: 'existingPages',
|
|
628
|
+
type: 'json',
|
|
629
|
+
default: '',
|
|
630
|
+
description: 'Optional: all pages of the store as path and name, so a curation may only link to pages that exist',
|
|
631
|
+
displayOptions: show('memory', ['curationPrompt', 'checkCuration']),
|
|
493
632
|
},
|
|
494
633
|
{
|
|
495
634
|
displayName: 'Step',
|
|
@@ -529,15 +668,15 @@ const properties = [
|
|
|
529
668
|
name: 'knownRoles',
|
|
530
669
|
type: 'string',
|
|
531
670
|
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']),
|
|
671
|
+
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.',
|
|
672
|
+
displayOptions: show('memory', ['consolidate', 'lintPages']),
|
|
534
673
|
},
|
|
535
674
|
{
|
|
536
675
|
displayName: 'Settings Rows',
|
|
537
676
|
name: 'settingRows',
|
|
538
677
|
type: 'json',
|
|
539
678
|
default: '',
|
|
540
|
-
description: 'Optional rows of the settings table: maxMemoryFacts, maxMemoryChars, memoryTtlDays, keepMemoryFacts (global < step < agent)',
|
|
679
|
+
description: 'Optional rows of the settings table: maxMemoryFacts, maxMemoryChars, memoryTtlDays, keepMemoryFacts, and for pages maxKnowledgeChars, maxPageChars, maxNewEntries, knowledgeCurateDays, maxCurationDeletePct, knowledgeLinkDepth (global < step < agent)',
|
|
541
680
|
displayOptions: { show: { resource: ['memory'] } },
|
|
542
681
|
},
|
|
543
682
|
{
|
|
@@ -547,7 +686,7 @@ const properties = [
|
|
|
547
686
|
placeholder: 'Add Option',
|
|
548
687
|
default: {},
|
|
549
688
|
description: 'Your company decides. Secrets are always refused.',
|
|
550
|
-
displayOptions: show('memory', ['checkWrite']),
|
|
689
|
+
displayOptions: show('memory', ['checkWrite', 'checkCuration']),
|
|
551
690
|
options: [
|
|
552
691
|
{ displayName: 'Block E-Mail Addresses', name: 'blockEmails', type: 'boolean', default: true },
|
|
553
692
|
{ displayName: 'Block UUIDs', name: 'blockUuids', type: 'boolean', default: true },
|
|
@@ -557,6 +696,22 @@ const properties = [
|
|
|
557
696
|
{ displayName: 'Blocked Patterns', name: 'blockedPatterns', type: 'string', typeOptions: { rows: 3 }, default: '', description: 'One regular expression per line, e.g. for an IBAN' },
|
|
558
697
|
],
|
|
559
698
|
},
|
|
699
|
+
{
|
|
700
|
+
displayName: 'Knowledge Options',
|
|
701
|
+
name: 'knowledgeOptions',
|
|
702
|
+
type: 'collection',
|
|
703
|
+
placeholder: 'Add Option',
|
|
704
|
+
default: {},
|
|
705
|
+
description: 'Use the same values in every node of your knowledge workflows',
|
|
706
|
+
displayOptions: show('memory', ['checkWrite', 'locatePages', 'selectPages', 'writePage', 'curationPrompt', 'checkCuration']),
|
|
707
|
+
options: [
|
|
708
|
+
{ 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.' },
|
|
709
|
+
{ 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' },
|
|
710
|
+
{ 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.' },
|
|
711
|
+
{ displayName: 'Allow Rules in Curation', name: 'allowNormativeCuration', type: 'boolean', default: false, description: 'Whether a curation may add normative statements outside the proposals' },
|
|
712
|
+
{ displayName: 'Curating Role', name: 'curatingRole', type: 'string', default: '', description: 'Role (UUID or name) whose holders curate circle pages. Empty: any role of the circle.' },
|
|
713
|
+
],
|
|
714
|
+
},
|
|
560
715
|
// ---------------------------------------------------------------- settings
|
|
561
716
|
{
|
|
562
717
|
displayName: 'Operation',
|
|
@@ -697,6 +852,66 @@ function stepParamJson(ctx, i) {
|
|
|
697
852
|
const step = (raw && typeof raw.step === 'object' ? raw.step : raw);
|
|
698
853
|
return step && typeof step === 'object' && step.uuid ? step : null;
|
|
699
854
|
}
|
|
855
|
+
function knowledgeLimits(rows, agentUuid) {
|
|
856
|
+
const s = (0, settings_1.resolveSettings)(rows, { agentUuid }).settings;
|
|
857
|
+
return {
|
|
858
|
+
maxChars: s.maxKnowledgeChars,
|
|
859
|
+
maxPageChars: s.maxPageChars,
|
|
860
|
+
maxNewEntries: s.maxNewEntries,
|
|
861
|
+
curateAfterDays: s.knowledgeCurateDays,
|
|
862
|
+
maxDeletePct: s.maxCurationDeletePct,
|
|
863
|
+
linkDepth: s.knowledgeLinkDepth,
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
function knowledgeOptions(ctx, i) {
|
|
867
|
+
const o = ctx.getNodeParameter('knowledgeOptions', i, {});
|
|
868
|
+
const terms = String(o.normativeTerms ?? '')
|
|
869
|
+
.split(/\r?\n|,/)
|
|
870
|
+
.map((t) => t.trim())
|
|
871
|
+
.filter(Boolean);
|
|
872
|
+
return {
|
|
873
|
+
pathTemplate: String(o.pathTemplate ?? '').trim() || undefined,
|
|
874
|
+
language: o.language === 'en' ? 'en' : 'de',
|
|
875
|
+
normativeTerms: terms.length ? terms : undefined,
|
|
876
|
+
allowNormativeCuration: o.allowNormativeCuration === true,
|
|
877
|
+
curatingRole: String(o.curatingRole ?? '').trim() || undefined,
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
function listParam(ctx, name, i) {
|
|
881
|
+
const raw = parseJsonParam(ctx, name, i);
|
|
882
|
+
if (Array.isArray(raw))
|
|
883
|
+
return raw;
|
|
884
|
+
if (raw && typeof raw === 'object')
|
|
885
|
+
return [raw];
|
|
886
|
+
return [];
|
|
887
|
+
}
|
|
888
|
+
function pageParam(ctx, i) {
|
|
889
|
+
const raw = parseJsonParam(ctx, 'page', i);
|
|
890
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
891
|
+
return null;
|
|
892
|
+
if (typeof raw.content !== 'string')
|
|
893
|
+
return null;
|
|
894
|
+
return { path: String(raw.path ?? ''), content: raw.content, version: raw.version ?? null };
|
|
895
|
+
}
|
|
896
|
+
function memoryPolicyParam(ctx, i) {
|
|
897
|
+
const opts = ctx.getNodeParameter('memoryPolicy', i, {});
|
|
898
|
+
const lines = (v, split) => String(v ?? '').split(split).map((t) => t.trim()).filter(Boolean);
|
|
899
|
+
const policy = {
|
|
900
|
+
blockEmails: opts.blockEmails !== false,
|
|
901
|
+
blockUuids: opts.blockUuids !== false,
|
|
902
|
+
blockPhoneNumbers: opts.blockPhoneNumbers !== false,
|
|
903
|
+
blockPersonNames: opts.blockPersonNames !== false,
|
|
904
|
+
blockedTerms: lines(opts.blockedTerms, /\r?\n|,/),
|
|
905
|
+
blockedPatterns: lines(opts.blockedPatterns, /\r?\n/),
|
|
906
|
+
};
|
|
907
|
+
try {
|
|
908
|
+
(0, memory_1.compilePatterns)(policy.blockedPatterns);
|
|
909
|
+
}
|
|
910
|
+
catch (error) {
|
|
911
|
+
throw new n8n_workflow_1.NodeOperationError(ctx.getNode(), error.message, { itemIndex: i });
|
|
912
|
+
}
|
|
913
|
+
return policy;
|
|
914
|
+
}
|
|
700
915
|
function memoryLimits(rows, bundle, step) {
|
|
701
916
|
const s = (0, settings_1.resolveSettings)(rows, { agentUuid: bundle.agent?.uuid ?? '', stepUuid: step?.uuid ?? '', stepCustomId: step?.customId ?? '' }).settings;
|
|
702
917
|
return { maxFacts: s.maxMemoryFacts, maxChars: s.maxMemoryChars, ttlDays: s.memoryTtlDays, keepFacts: s.keepMemoryFacts };
|
|
@@ -860,6 +1075,60 @@ class RoleAlpha {
|
|
|
860
1075
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `roleALPHA Agent Keys: ${error.message}`);
|
|
861
1076
|
}
|
|
862
1077
|
}
|
|
1078
|
+
// Reporting a run's usage: with the function account, never the run token (agentRun.ts).
|
|
1079
|
+
if (resource === 'agent' && operation === 'reportUsage') {
|
|
1080
|
+
if (source === 'agentKey')
|
|
1081
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Report Usage needs a function account (source MCP), not agent keys');
|
|
1082
|
+
const tokens = new agentRun_1.AgentRunTokens(formPost(this));
|
|
1083
|
+
const account = await functionAccount(this);
|
|
1084
|
+
for (let i = 0; i < items.length; i++) {
|
|
1085
|
+
const count = (name) => {
|
|
1086
|
+
const v = String(this.getNodeParameter(name, i, '') ?? '').trim();
|
|
1087
|
+
if (v === '')
|
|
1088
|
+
return undefined;
|
|
1089
|
+
const n = Number(v.replace(',', '.'));
|
|
1090
|
+
if (!Number.isFinite(n) || n < 0)
|
|
1091
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `"${name}" is not a number ≥ 0`, { itemIndex: i });
|
|
1092
|
+
return n;
|
|
1093
|
+
};
|
|
1094
|
+
const agentUuid = String(this.getNodeParameter('runAgentUuid', i, '') ?? '').trim().toLowerCase();
|
|
1095
|
+
const runId = String(this.getNodeParameter('runId', i, '') ?? '').trim();
|
|
1096
|
+
const model = String(this.getNodeParameter('usageModel', i, '') ?? '').trim() || undefined;
|
|
1097
|
+
const usage = {
|
|
1098
|
+
inputTokens: count('usageInputTokens'),
|
|
1099
|
+
cacheReadTokens: count('usageCacheReadTokens'),
|
|
1100
|
+
cacheWriteTokens: count('usageCacheWriteTokens'),
|
|
1101
|
+
outputTokens: count('usageOutputTokens'),
|
|
1102
|
+
};
|
|
1103
|
+
const cost = count('usageCost');
|
|
1104
|
+
let priced = null;
|
|
1105
|
+
if (cost !== undefined) {
|
|
1106
|
+
priced = { cost, currency: String(this.getNodeParameter('usageCurrency', i, 'USD') ?? 'USD').trim().toUpperCase(), priceKind: 'tabelle', priceSource: 'workflow' };
|
|
1107
|
+
}
|
|
1108
|
+
else {
|
|
1109
|
+
const rows = parseJsonParam(this, 'priceRows', i);
|
|
1110
|
+
if (Array.isArray(rows) && rows.length > 0) {
|
|
1111
|
+
try {
|
|
1112
|
+
priced = (0, pricing_1.costOf)(usage, model, (0, pricing_1.priceTableFromRows)(rows));
|
|
1113
|
+
}
|
|
1114
|
+
catch (error) {
|
|
1115
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), error.message, { itemIndex: i });
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
try {
|
|
1120
|
+
const receipt = await tokens.reportUsage(account, { agentUuid, runId, model, ...usage, ...(priced ?? {}) }, tokens.usageUrlFor(account, agentUuid, runId));
|
|
1121
|
+
out.push({ json: { ...items[i].json, usage: { reported: true, ...receipt, cost: priced?.cost ?? null, currency: priced?.currency ?? null } }, pairedItem: { item: i } });
|
|
1122
|
+
}
|
|
1123
|
+
catch (error) {
|
|
1124
|
+
if (!(error instanceof agentRun_1.AgentRunError))
|
|
1125
|
+
throw error;
|
|
1126
|
+
// A refusal comes back as data: reporting must never break the run it reports.
|
|
1127
|
+
out.push({ json: { ...items[i].json, usage: { reported: false, code: error.code, reaction: error.reaction, reason: error.description } }, pairedItem: { item: i } });
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
return [out];
|
|
1131
|
+
}
|
|
863
1132
|
// Acting as an agent: every MCP call of this node runs under the run token of that agent.
|
|
864
1133
|
const startRun = resource === 'agent' && operation === 'startRun';
|
|
865
1134
|
const usesMcp = ['agent', 'responsibility', 'tool'].includes(resource) && source !== 'agentKey';
|
|
@@ -985,8 +1254,33 @@ class RoleAlpha {
|
|
|
985
1254
|
const plan = (0, waits_1.planAfterRun)(rows, run, waitOpts);
|
|
986
1255
|
return [[{ json: plan }]];
|
|
987
1256
|
}
|
|
1257
|
+
// Pages: Locate, Select and Lint look at all pages (or none) at once.
|
|
1258
|
+
if (resource === 'memory' && ['locatePages', 'selectPages', 'lintPages'].includes(operation)) {
|
|
1259
|
+
const settingRowsRaw = parseJsonParam(this, 'settingRows', 0);
|
|
1260
|
+
const settingRows = (Array.isArray(settingRowsRaw) ? settingRowsRaw : []);
|
|
1261
|
+
if (operation === 'lintPages') {
|
|
1262
|
+
const knownRaw = this.getNodeParameter('knownRoles', 0, '');
|
|
1263
|
+
const known = (Array.isArray(knownRaw) ? knownRaw : String(knownRaw ?? '').split(',')).map((v) => String(v).trim()).filter(Boolean);
|
|
1264
|
+
const res = (0, knowledge_1.lintPages)(parseJsonParam(this, 'pages', 0), { knownUuids: known, limits: knowledgeLimits(settingRows, '') });
|
|
1265
|
+
return [[{ json: res }]];
|
|
1266
|
+
}
|
|
1267
|
+
const bundle = bundleParam(this, 0);
|
|
1268
|
+
const circles = listParam(this, 'circles', 0);
|
|
1269
|
+
const opts = knowledgeOptions(this, 0);
|
|
1270
|
+
let refs;
|
|
1271
|
+
try {
|
|
1272
|
+
refs = (0, knowledge_1.locatePages)(bundle, circles, opts);
|
|
1273
|
+
}
|
|
1274
|
+
catch (error) {
|
|
1275
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), error.message);
|
|
1276
|
+
}
|
|
1277
|
+
if (operation === 'locatePages')
|
|
1278
|
+
return [refs.map((r) => ({ json: r }))];
|
|
1279
|
+
const res = (0, knowledge_1.selectKnowledge)(parseJsonParam(this, 'pages', 0), { bundle, circles, opts, limits: knowledgeLimits(settingRows, bundle.agent?.uuid ?? '') });
|
|
1280
|
+
return [[{ json: res }]];
|
|
1281
|
+
}
|
|
988
1282
|
// Memory: Select and Consolidate look at all stored rows at once.
|
|
989
|
-
if (resource === 'memory' && operation
|
|
1283
|
+
if (resource === 'memory' && (operation === 'select' || operation === 'consolidate')) {
|
|
990
1284
|
const rows = parseJsonParam(this, 'rows', 0);
|
|
991
1285
|
const settingRowsRaw = parseJsonParam(this, 'settingRows', 0);
|
|
992
1286
|
const settingRows = (Array.isArray(settingRowsRaw) ? settingRowsRaw : []);
|
|
@@ -1005,6 +1299,44 @@ class RoleAlpha {
|
|
|
1005
1299
|
}
|
|
1006
1300
|
for (let i = 0; i < items.length; i++) {
|
|
1007
1301
|
try {
|
|
1302
|
+
if (resource === 'memory' && operation !== 'checkWrite') {
|
|
1303
|
+
const settingRowsRaw = parseJsonParam(this, 'settingRows', i);
|
|
1304
|
+
const settingRows = (Array.isArray(settingRowsRaw) ? settingRowsRaw : []);
|
|
1305
|
+
const opts = knowledgeOptions(this, i);
|
|
1306
|
+
const page = pageParam(this, i);
|
|
1307
|
+
let res;
|
|
1308
|
+
if (operation === 'writePage') {
|
|
1309
|
+
const write = parseJsonParam(this, 'write', i);
|
|
1310
|
+
res = (0, knowledge_1.writeEntry)(write, page, opts, knowledgeLimits(settingRows, String(write?.entry?.agent ?? '')));
|
|
1311
|
+
}
|
|
1312
|
+
else if (operation === 'curationPrompt') {
|
|
1313
|
+
if (!page)
|
|
1314
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Page is empty: there is nothing to curate', { itemIndex: i });
|
|
1315
|
+
const bundle = bundleParam(this, i);
|
|
1316
|
+
res = (0, knowledge_1.buildCurationPrompt)({
|
|
1317
|
+
page,
|
|
1318
|
+
bundle,
|
|
1319
|
+
circles: listParam(this, 'circles', i),
|
|
1320
|
+
existing: listParam(this, 'existingPages', i),
|
|
1321
|
+
opts,
|
|
1322
|
+
limits: knowledgeLimits(settingRows, bundle.agent?.uuid ?? ''),
|
|
1323
|
+
});
|
|
1324
|
+
}
|
|
1325
|
+
else {
|
|
1326
|
+
if (!page)
|
|
1327
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Page is empty: give the page that was curated', { itemIndex: i });
|
|
1328
|
+
const existing = listParam(this, 'existingPages', i).map((p) => String(p?.path ?? '')).filter(Boolean);
|
|
1329
|
+
res = (0, knowledge_1.checkCuration)(page, String(this.getNodeParameter('answer', i, '') ?? ''), {
|
|
1330
|
+
policy: memoryPolicyParam(this, i),
|
|
1331
|
+
opts,
|
|
1332
|
+
limits: knowledgeLimits(settingRows, ''),
|
|
1333
|
+
existingPaths: existing,
|
|
1334
|
+
});
|
|
1335
|
+
}
|
|
1336
|
+
// A refusal is data, so the workflow can retry, report or leave the page as it is.
|
|
1337
|
+
out.push({ json: res, pairedItem: { item: i } });
|
|
1338
|
+
continue;
|
|
1339
|
+
}
|
|
1008
1340
|
if (resource === 'memory') {
|
|
1009
1341
|
const bundle = bundleParam(this, i);
|
|
1010
1342
|
const step = stepParamJson(this, i);
|
|
@@ -1012,22 +1344,8 @@ class RoleAlpha {
|
|
|
1012
1344
|
const limits = memoryLimits((Array.isArray(settingRowsRaw) ? settingRowsRaw : []), bundle, step);
|
|
1013
1345
|
const raw = parseJsonParam(this, 'request', i);
|
|
1014
1346
|
const request = (raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : {});
|
|
1015
|
-
const
|
|
1016
|
-
const
|
|
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
|
-
}
|
|
1347
|
+
const policy = memoryPolicyParam(this, i);
|
|
1348
|
+
const knowledgeOn = this.getNodeParameter('knowledgePages', i, false) === true;
|
|
1031
1349
|
const res = (0, memory_1.checkWrite)(request, {
|
|
1032
1350
|
bundle,
|
|
1033
1351
|
step,
|
|
@@ -1035,6 +1353,7 @@ class RoleAlpha {
|
|
|
1035
1353
|
runId: String(this.getNodeParameter('memoryRunId', i, '') ?? ''),
|
|
1036
1354
|
ttlDays: limits.ttlDays,
|
|
1037
1355
|
policy,
|
|
1356
|
+
knowledge: knowledgeOn ? { enabled: true, circles: listParam(this, 'circles', i), opts: knowledgeOptions(this, i) } : null,
|
|
1038
1357
|
});
|
|
1039
1358
|
// A refusal is data, so the model can shorten or rephrase the fact.
|
|
1040
1359
|
out.push({ json: res, pairedItem: { item: i } });
|
|
@@ -1142,6 +1461,12 @@ class RoleAlpha {
|
|
|
1142
1461
|
: memoryRaw && typeof memoryRaw === 'object' && Array.isArray(memoryRaw.memory)
|
|
1143
1462
|
? memoryRaw.memory
|
|
1144
1463
|
: null;
|
|
1464
|
+
const knowledgeRaw = parseJsonParam(this, 'knowledge', i);
|
|
1465
|
+
const knowledge = Array.isArray(knowledgeRaw)
|
|
1466
|
+
? knowledgeRaw
|
|
1467
|
+
: knowledgeRaw && typeof knowledgeRaw === 'object' && Array.isArray(knowledgeRaw.knowledge)
|
|
1468
|
+
? knowledgeRaw.knowledge
|
|
1469
|
+
: null;
|
|
1145
1470
|
const rules = String(this.getNodeParameter('extraRules', i, '') ?? '')
|
|
1146
1471
|
.split(/\r?\n/)
|
|
1147
1472
|
.map((r) => r.trim())
|
|
@@ -1154,6 +1479,7 @@ class RoleAlpha {
|
|
|
1154
1479
|
extraRules: rules,
|
|
1155
1480
|
share,
|
|
1156
1481
|
memory,
|
|
1482
|
+
knowledge,
|
|
1157
1483
|
});
|
|
1158
1484
|
const json = { ...items[i].json, systemPrompt };
|
|
1159
1485
|
if (share && step)
|