@valerypopoff/rivet2-core 2.1.5 → 2.1.6

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.
Files changed (65) hide show
  1. package/dist/cjs/bundle.cjs +3154 -289
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/cjs/webAppRuntime.cjs +129 -4
  4. package/dist/cjs/webAppRuntime.cjs.map +2 -2
  5. package/dist/esm/api/createProcessor.js +1 -0
  6. package/dist/esm/exports.js +4 -0
  7. package/dist/esm/integrations/KnowledgeStore.js +1 -0
  8. package/dist/esm/integrations/KnowledgeStoreProvider.js +292 -0
  9. package/dist/esm/integrations/KnowledgeStoreValidation.js +428 -0
  10. package/dist/esm/integrations/ManagedKnowledgeStore.js +539 -0
  11. package/dist/esm/model/DataValue.js +22 -2
  12. package/dist/esm/model/GraphProcessor.js +14 -0
  13. package/dist/esm/model/Nodes.js +18 -0
  14. package/dist/esm/model/UiGraph.js +2 -2
  15. package/dist/esm/model/UiGraphBrowserRuntime.js +112 -1
  16. package/dist/esm/model/UiGraphRendererStyles.js +111 -9
  17. package/dist/esm/model/UiGraphRuntimeModel.js +26 -2
  18. package/dist/esm/model/chat/openAIChatRequest.js +8 -2
  19. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +8 -8
  20. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +3 -1
  21. package/dist/esm/model/chat-v2/parallelToolCalls.js +38 -0
  22. package/dist/esm/model/chat-v2/toolContinuation.js +39 -0
  23. package/dist/esm/model/nodes/BuildKnowledgeContextNode.js +157 -0
  24. package/dist/esm/model/nodes/GetKnowledgeSourceStatusNode.js +79 -0
  25. package/dist/esm/model/nodes/KnowledgeDocumentNode.js +88 -0
  26. package/dist/esm/model/nodes/KnowledgeSourceNode.js +94 -0
  27. package/dist/esm/model/nodes/SearchKnowledgeNode.js +127 -0
  28. package/dist/esm/model/nodes/StoredValueNodeUtils.js +10 -0
  29. package/dist/esm/model/nodes/SyncKnowledgeSourceNode.js +149 -0
  30. package/dist/esm/model/nodes/ToolNode.js +14 -0
  31. package/dist/esm/plugins/pinecone/PineconeKnowledgeStore.js +553 -0
  32. package/dist/esm/plugins/pinecone/plugin.js +32 -0
  33. package/dist/esm/utils/coerceType.js +24 -2
  34. package/dist/esm/utils/getPluginConfig.js +12 -6
  35. package/dist/esm/utils/serialization/serialization.js +4 -1
  36. package/dist/esm/utils/serialization/serializationUtils.js +59 -1
  37. package/dist/esm/webAppRuntime.js +1 -1
  38. package/dist/types/api/createProcessor.d.ts +2 -0
  39. package/dist/types/exports.d.ts +4 -0
  40. package/dist/types/integrations/KnowledgeStore.d.ts +131 -0
  41. package/dist/types/integrations/KnowledgeStoreProvider.d.ts +46 -0
  42. package/dist/types/integrations/KnowledgeStoreValidation.d.ts +16 -0
  43. package/dist/types/integrations/ManagedKnowledgeStore.d.ts +57 -0
  44. package/dist/types/model/DataValue.d.ts +10 -3
  45. package/dist/types/model/EditorDefinition.d.ts +7 -1
  46. package/dist/types/model/GraphProcessor.d.ts +2 -0
  47. package/dist/types/model/Nodes.d.ts +8 -2
  48. package/dist/types/model/ProcessContext.d.ts +3 -0
  49. package/dist/types/model/Project.d.ts +11 -0
  50. package/dist/types/model/UiGraph.d.ts +3 -1
  51. package/dist/types/model/UiGraphBrowserRuntime.d.ts +25 -1
  52. package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
  53. package/dist/types/model/chat-v2/parallelToolCalls.d.ts +9 -0
  54. package/dist/types/model/nodes/BuildKnowledgeContextNode.d.ts +23 -0
  55. package/dist/types/model/nodes/GetKnowledgeSourceStatusNode.d.ts +19 -0
  56. package/dist/types/model/nodes/KnowledgeDocumentNode.d.ts +26 -0
  57. package/dist/types/model/nodes/KnowledgeSourceNode.d.ts +25 -0
  58. package/dist/types/model/nodes/SearchKnowledgeNode.d.ts +25 -0
  59. package/dist/types/model/nodes/StoredValueNodeUtils.d.ts +1 -1
  60. package/dist/types/model/nodes/SyncKnowledgeSourceNode.d.ts +27 -0
  61. package/dist/types/model/nodes/ToolNode.d.ts +2 -0
  62. package/dist/types/plugins/pinecone/PineconeKnowledgeStore.d.ts +11 -0
  63. package/dist/types/utils/serialization/serializationUtils.d.ts +4 -0
  64. package/dist/types/webAppRuntime.d.ts +2 -1
  65. package/package.json +1 -1
@@ -0,0 +1,157 @@
1
+ import { nanoid } from 'nanoid/non-secure';
2
+ import { dedent } from 'ts-dedent';
3
+ import { normalizeKnowledgeEvidence } from '../../integrations/KnowledgeStoreValidation.js';
4
+ import { nodeDefinition } from '../NodeDefinition.js';
5
+ import { NodeImpl } from '../NodeImpl.js';
6
+ export class BuildKnowledgeContextNodeImpl extends NodeImpl {
7
+ static create() {
8
+ return {
9
+ id: nanoid(),
10
+ type: 'buildKnowledgeContext',
11
+ title: 'Build Knowledge Context',
12
+ visualData: { x: 0, y: 0, width: 280 },
13
+ data: {
14
+ budgetUnit: 'tokens',
15
+ budget: 6000,
16
+ maxItems: 20,
17
+ citationPrefix: 'K',
18
+ metadataFields: ['title'],
19
+ },
20
+ };
21
+ }
22
+ getInputDefinitions() {
23
+ return [
24
+ {
25
+ id: 'evidence',
26
+ title: 'Evidence',
27
+ dataType: ['knowledge-evidence', 'knowledge-evidence[]'],
28
+ required: true,
29
+ },
30
+ ];
31
+ }
32
+ getOutputDefinitions() {
33
+ return [
34
+ { id: 'context', title: 'Context', dataType: 'string' },
35
+ { id: 'included-evidence', title: 'Included Evidence', dataType: 'knowledge-evidence[]' },
36
+ { id: 'citation-map', title: 'Citation Map', dataType: 'object' },
37
+ { id: 'excluded-count', title: 'Excluded Count', dataType: 'number' },
38
+ ];
39
+ }
40
+ getEditors() {
41
+ return [
42
+ {
43
+ type: 'dropdown',
44
+ dataKey: 'budgetUnit',
45
+ label: 'Budget Unit',
46
+ options: [
47
+ { value: 'characters', label: 'Characters' },
48
+ { value: 'tokens', label: 'Tokens' },
49
+ ],
50
+ },
51
+ { type: 'number', dataKey: 'budget', label: 'Context Budget', min: 1, max: 1000000 },
52
+ { type: 'number', dataKey: 'maxItems', label: 'Maximum Evidence Items', min: 1, max: 500 },
53
+ { type: 'string', dataKey: 'citationPrefix', label: 'Citation Prefix', maxLength: 16 },
54
+ {
55
+ type: 'stringList',
56
+ dataKey: 'metadataFields',
57
+ label: 'Metadata Fields To Include',
58
+ placeholder: 'chapter_title',
59
+ },
60
+ ];
61
+ }
62
+ getBody() {
63
+ return dedent `
64
+ ${this.data.budget} ${this.data.budgetUnit}
65
+ Up to ${this.data.maxItems} items
66
+ Citations: [${this.data.citationPrefix || 'K'}1]
67
+ `;
68
+ }
69
+ static getUIData() {
70
+ return {
71
+ contextMenuTitle: 'Build Knowledge Context',
72
+ infoBoxTitle: 'Build Knowledge Context Node',
73
+ infoBoxBody: 'Packs structured evidence into a bounded LLM context with stable citation labels.',
74
+ group: 'Knowledge',
75
+ };
76
+ }
77
+ async process(inputs, context) {
78
+ const value = inputs['evidence'];
79
+ const evidence = value?.type === 'knowledge-evidence[]'
80
+ ? value.value.map(normalizeKnowledgeEvidence)
81
+ : value?.type === 'knowledge-evidence'
82
+ ? [normalizeKnowledgeEvidence(value.value)]
83
+ : [];
84
+ if (!value)
85
+ throw new Error('Build Knowledge Context is missing its Evidence input.');
86
+ if (value.type !== 'knowledge-evidence' && value.type !== 'knowledge-evidence[]') {
87
+ throw new Error(`Build Knowledge Context cannot use ${value.type} as Evidence.`);
88
+ }
89
+ if (!Number.isInteger(this.data.budget) || this.data.budget < 1 || this.data.budget > 1_000_000) {
90
+ throw new Error('Build Knowledge Context budget must be an integer between 1 and 1000000.');
91
+ }
92
+ if (!Number.isInteger(this.data.maxItems) || this.data.maxItems < 1 || this.data.maxItems > 500) {
93
+ throw new Error('Build Knowledge Context maximum evidence items must be an integer between 1 and 500.');
94
+ }
95
+ if (this.data.budgetUnit !== 'characters' && this.data.budgetUnit !== 'tokens') {
96
+ throw new Error('Build Knowledge Context budget unit must be characters or tokens.');
97
+ }
98
+ if (!Array.isArray(this.data.metadataFields) ||
99
+ this.data.metadataFields.some((field) => typeof field !== 'string')) {
100
+ throw new Error('Build Knowledge Context metadata fields must be a string array.');
101
+ }
102
+ const included = [];
103
+ const sections = [];
104
+ const citationMap = {};
105
+ if (typeof this.data.citationPrefix !== 'string') {
106
+ throw new Error('Build Knowledge Context citation prefix must be a string.');
107
+ }
108
+ const prefix = this.data.citationPrefix.trim() || 'K';
109
+ if (prefix.length > 16)
110
+ throw new Error('Build Knowledge Context citation prefix cannot exceed 16 characters.');
111
+ for (const item of evidence.slice(0, this.data.maxItems)) {
112
+ const label = `${prefix}${included.length + 1}`;
113
+ const metadata = buildMetadataLine(item, this.data.metadataFields);
114
+ const section = `[${label}]${metadata ? ` ${metadata}` : ''}\n${item.text}`;
115
+ const candidateContext = [...sections, section].join('\n\n---\n\n');
116
+ const size = this.data.budgetUnit === 'tokens'
117
+ ? await context.tokenizer.getTokenCountForString(candidateContext, { node: context.node })
118
+ : candidateContext.length;
119
+ if (size > this.data.budget)
120
+ continue;
121
+ included.push(item);
122
+ sections.push(section);
123
+ citationMap[label] = {
124
+ evidenceId: item.id,
125
+ source: item.source,
126
+ documentId: item.documentId,
127
+ ...(item.title ? { title: item.title } : {}),
128
+ ...(item.chunkIndex == null ? {} : { chunkIndex: item.chunkIndex }),
129
+ ...(item.metadata ? { metadata: item.metadata } : {}),
130
+ };
131
+ }
132
+ return {
133
+ ['context']: { type: 'string', value: sections.join('\n\n---\n\n') },
134
+ ['included-evidence']: { type: 'knowledge-evidence[]', value: included },
135
+ ['citation-map']: { type: 'object', value: citationMap },
136
+ ['excluded-count']: { type: 'number', value: Math.max(0, evidence.length - included.length) },
137
+ };
138
+ }
139
+ }
140
+ function buildMetadataLine(evidence, fields) {
141
+ const values = [];
142
+ for (const field of fields) {
143
+ const normalizedField = field.trim();
144
+ if (!normalizedField)
145
+ continue;
146
+ const value = normalizedField === 'title'
147
+ ? evidence.title
148
+ : evidence.metadata && Object.prototype.hasOwnProperty.call(evidence.metadata, normalizedField)
149
+ ? evidence.metadata[normalizedField]
150
+ : undefined;
151
+ if (value == null || (Array.isArray(value) && value.length === 0))
152
+ continue;
153
+ values.push(`${normalizedField}: ${Array.isArray(value) ? value.join(', ') : String(value)}`);
154
+ }
155
+ return values.join(' | ');
156
+ }
157
+ export const buildKnowledgeContextNode = nodeDefinition(BuildKnowledgeContextNodeImpl, 'Build Knowledge Context');
@@ -0,0 +1,79 @@
1
+ import { nanoid } from 'nanoid/non-secure';
2
+ import { nodeDefinition } from '../NodeDefinition.js';
3
+ import { NodeImpl } from '../NodeImpl.js';
4
+ import { coerceType } from '../../utils/coerceType.js';
5
+ import { normalizeKnowledgeSourceReference, normalizeKnowledgeSourceStatusResult, } from '../../integrations/KnowledgeStoreValidation.js';
6
+ export class GetKnowledgeSourceStatusNodeImpl extends NodeImpl {
7
+ static create() {
8
+ return {
9
+ id: nanoid(),
10
+ type: 'getKnowledgeSourceStatus',
11
+ title: 'Get Knowledge Source Status',
12
+ visualData: { x: 0, y: 0, width: 300 },
13
+ data: { expectedVersion: '', useExpectedVersionInput: false },
14
+ };
15
+ }
16
+ getInputDefinitions() {
17
+ const inputs = [
18
+ { id: 'source', title: 'Source', dataType: 'knowledge-source', required: true },
19
+ ];
20
+ if (this.data.useExpectedVersionInput) {
21
+ inputs.push({ id: 'expected-version', title: 'Expected Version', dataType: 'string' });
22
+ }
23
+ return inputs;
24
+ }
25
+ getOutputDefinitions() {
26
+ return [
27
+ { id: 'source', title: 'Resolved Source', dataType: 'knowledge-source' },
28
+ { id: 'exists', title: 'Exists', dataType: 'boolean' },
29
+ { id: 'active-version', title: 'Active Version', dataType: 'string' },
30
+ { id: 'matches-expected-version', title: 'Matches Expected Version', dataType: 'boolean' },
31
+ { id: 'document-count', title: 'Document Count', dataType: 'number' },
32
+ { id: 'chunk-count', title: 'Chunk Count', dataType: 'number' },
33
+ { id: 'updated-at', title: 'Updated At', dataType: 'datetime' },
34
+ { id: 'metadata', title: 'Metadata', dataType: 'object' },
35
+ { id: 'message', title: 'Status Message', dataType: 'string' },
36
+ ];
37
+ }
38
+ getEditors() {
39
+ return [
40
+ {
41
+ type: 'string',
42
+ dataKey: 'expectedVersion',
43
+ useInputToggleDataKey: 'useExpectedVersionInput',
44
+ label: 'Expected Version',
45
+ },
46
+ ];
47
+ }
48
+ static getUIData() {
49
+ return {
50
+ contextMenuTitle: 'Get Knowledge Source Status',
51
+ infoBoxTitle: 'Get Knowledge Source Status Node',
52
+ infoBoxBody: 'Reads the durable active source manifest. A missing source is returned as normal output.',
53
+ group: 'Knowledge',
54
+ };
55
+ }
56
+ async process(inputs, context) {
57
+ const source = normalizeKnowledgeSourceReference(coerceType(inputs['source'], 'knowledge-source'));
58
+ const expectedVersion = (this.data.useExpectedVersionInput
59
+ ? coerceType(inputs['expected-version'], 'string')
60
+ : this.data.expectedVersion).trim();
61
+ const normalizedExpectedVersion = expectedVersion
62
+ ? normalizeKnowledgeSourceReference({ ...source, version: expectedVersion }).version
63
+ : undefined;
64
+ const store = await context.getKnowledgeStore(source.connectionId);
65
+ const result = normalizeKnowledgeSourceStatusResult(await store.getSourceStatus({ source, ...(normalizedExpectedVersion ? { expectedVersion: normalizedExpectedVersion } : {}) }, { signal: context.signal, reportProgress: context.reportProgress }), source, normalizedExpectedVersion);
66
+ return {
67
+ ['source']: { type: 'knowledge-source', value: result.source },
68
+ ['exists']: { type: 'boolean', value: result.exists },
69
+ ['active-version']: { type: 'string', value: result.activeVersion ?? '' },
70
+ ['matches-expected-version']: { type: 'boolean', value: result.matchesExpectedVersion ?? false },
71
+ ['document-count']: { type: 'number', value: result.documentCount ?? 0 },
72
+ ['chunk-count']: { type: 'number', value: result.chunkCount ?? 0 },
73
+ ['updated-at']: { type: 'datetime', value: result.updatedAt ?? '' },
74
+ ['metadata']: { type: 'object', value: result.metadata ?? {} },
75
+ ['message']: { type: 'string', value: result.message },
76
+ };
77
+ }
78
+ }
79
+ export const getKnowledgeSourceStatusNode = nodeDefinition(GetKnowledgeSourceStatusNodeImpl, 'Get Knowledge Source Status');
@@ -0,0 +1,88 @@
1
+ import { nanoid } from 'nanoid/non-secure';
2
+ import { dedent } from 'ts-dedent';
3
+ import { nodeDefinition } from '../NodeDefinition.js';
4
+ import { NodeImpl } from '../NodeImpl.js';
5
+ import { coerceType } from '../../utils/coerceType.js';
6
+ import { normalizeKnowledgeDocument, normalizeKnowledgeMetadata } from '../../integrations/KnowledgeStoreValidation.js';
7
+ export class KnowledgeDocumentNodeImpl extends NodeImpl {
8
+ static create() {
9
+ return {
10
+ id: nanoid(),
11
+ type: 'knowledgeDocument',
12
+ title: 'Knowledge Document',
13
+ visualData: { x: 0, y: 0, width: 250 },
14
+ data: {
15
+ text: '',
16
+ useTextInput: true,
17
+ documentId: '',
18
+ useDocumentIdInput: false,
19
+ title: '',
20
+ useTitleInput: false,
21
+ metadata: {},
22
+ useMetadataInput: false,
23
+ },
24
+ };
25
+ }
26
+ getInputDefinitions() {
27
+ const inputs = [];
28
+ if (this.data.useTextInput)
29
+ inputs.push({ id: 'text', title: 'Text', dataType: 'string', required: true });
30
+ if (this.data.useDocumentIdInput)
31
+ inputs.push({ id: 'document-id', title: 'Document ID', dataType: 'string' });
32
+ if (this.data.useTitleInput)
33
+ inputs.push({ id: 'title', title: 'Title', dataType: 'string' });
34
+ if (this.data.useMetadataInput)
35
+ inputs.push({ id: 'metadata', title: 'Metadata', dataType: 'object' });
36
+ return inputs;
37
+ }
38
+ getOutputDefinitions() {
39
+ return [{ id: 'document', title: 'Document', dataType: 'knowledge-document' }];
40
+ }
41
+ getEditors() {
42
+ return [
43
+ {
44
+ type: 'code',
45
+ language: 'text',
46
+ dataKey: 'text',
47
+ useInputToggleDataKey: 'useTextInput',
48
+ label: 'Text',
49
+ height: 160,
50
+ },
51
+ { type: 'string', dataKey: 'documentId', useInputToggleDataKey: 'useDocumentIdInput', label: 'Document ID' },
52
+ { type: 'string', dataKey: 'title', useInputToggleDataKey: 'useTitleInput', label: 'Title' },
53
+ {
54
+ type: 'jsonObject',
55
+ dataKey: 'metadata',
56
+ useInputToggleDataKey: 'useMetadataInput',
57
+ label: 'Metadata',
58
+ helperMessage: 'Enter a flat JSON object, or leave {} when the document has no metadata.',
59
+ },
60
+ ];
61
+ }
62
+ getBody() {
63
+ return dedent `
64
+ ${this.data.useTextInput ? 'Text from input' : `${this.data.text.length} characters`}
65
+ ${this.data.useDocumentIdInput ? 'ID from input' : this.data.documentId ? `ID: ${this.data.documentId}` : 'ID generated from content'}
66
+ `;
67
+ }
68
+ static getUIData() {
69
+ return {
70
+ contextMenuTitle: 'Knowledge Document',
71
+ infoBoxTitle: 'Knowledge Document Node',
72
+ infoBoxBody: 'Creates a typed text document with a stable ID, title, and portable searchable metadata.',
73
+ group: 'Knowledge',
74
+ };
75
+ }
76
+ async process(inputs, _context) {
77
+ const text = this.data.useTextInput ? coerceType(inputs['text'], 'string') : this.data.text;
78
+ const id = (this.data.useDocumentIdInput ? coerceType(inputs['document-id'], 'string') : this.data.documentId).trim();
79
+ const title = (this.data.useTitleInput ? coerceType(inputs['title'], 'string') : this.data.title).trim();
80
+ const metadataRaw = this.data.useMetadataInput
81
+ ? coerceType(inputs['metadata'], 'object')
82
+ : this.data.metadata;
83
+ const metadata = normalizeKnowledgeMetadata(metadataRaw);
84
+ const document = normalizeKnowledgeDocument({ text, ...(id ? { id } : {}), ...(title ? { title } : {}), metadata });
85
+ return { ['document']: { type: 'knowledge-document', value: document } };
86
+ }
87
+ }
88
+ export const knowledgeDocumentNode = nodeDefinition(KnowledgeDocumentNodeImpl, 'Knowledge Document');
@@ -0,0 +1,94 @@
1
+ import { nanoid } from 'nanoid/non-secure';
2
+ import { dedent } from 'ts-dedent';
3
+ import { nodeDefinition } from '../NodeDefinition.js';
4
+ import { NodeImpl } from '../NodeImpl.js';
5
+ import { coerceType } from '../../utils/coerceType.js';
6
+ import { normalizeKnowledgeConnectionId, normalizeKnowledgeSourceId, normalizeKnowledgeSourceReference, } from '../../integrations/KnowledgeStoreValidation.js';
7
+ export class KnowledgeSourceNodeImpl extends NodeImpl {
8
+ static create() {
9
+ return {
10
+ id: nanoid(),
11
+ type: 'knowledgeSource',
12
+ title: 'Knowledge Source',
13
+ visualData: { x: 0, y: 0, width: 250 },
14
+ data: {
15
+ connectionId: '',
16
+ useConnectionIdInput: false,
17
+ sourceId: '',
18
+ useSourceIdInput: true,
19
+ version: '',
20
+ useVersionInput: false,
21
+ },
22
+ };
23
+ }
24
+ getInputDefinitions() {
25
+ const inputs = [];
26
+ if (this.data.useConnectionIdInput) {
27
+ inputs.push({ id: 'connection-id', title: 'Connection ID', dataType: 'string', required: true });
28
+ }
29
+ if (this.data.useSourceIdInput) {
30
+ inputs.push({ id: 'source-id', title: 'Source ID', dataType: 'string', required: true });
31
+ }
32
+ if (this.data.useVersionInput) {
33
+ inputs.push({ id: 'version', title: 'Exact Version', dataType: 'string', required: false });
34
+ }
35
+ return inputs;
36
+ }
37
+ getOutputDefinitions() {
38
+ return [{ id: 'source', title: 'Source', dataType: 'knowledge-source' }];
39
+ }
40
+ getEditors() {
41
+ return [
42
+ {
43
+ type: 'custom',
44
+ customEditorId: 'KnowledgeStoreSelector',
45
+ dataKey: 'connectionId',
46
+ useInputToggleDataKey: 'useConnectionIdInput',
47
+ label: 'Knowledge Store',
48
+ includeInGraphSearch: true,
49
+ },
50
+ {
51
+ type: 'string',
52
+ dataKey: 'sourceId',
53
+ useInputToggleDataKey: 'useSourceIdInput',
54
+ label: 'Source ID',
55
+ includeInGraphSearch: true,
56
+ },
57
+ {
58
+ type: 'string',
59
+ dataKey: 'version',
60
+ useInputToggleDataKey: 'useVersionInput',
61
+ label: 'Exact Version',
62
+ helperMessage: 'Leave blank to resolve the active committed version when the source is used.',
63
+ },
64
+ ];
65
+ }
66
+ getBody(context) {
67
+ const connection = context.project.metadata.knowledgeStores?.[this.data.connectionId];
68
+ return dedent `
69
+ Store: ${this.data.useConnectionIdInput ? '(from input)' : (connection?.displayName ?? this.data.connectionId) || '(not selected)'}
70
+ Source: ${this.data.useSourceIdInput ? '(from input)' : this.data.sourceId || '(not set)'}
71
+ ${this.data.useVersionInput || this.data.version ? 'Exact version configured' : 'Uses active version'}
72
+ `;
73
+ }
74
+ static getUIData() {
75
+ return {
76
+ contextMenuTitle: 'Knowledge Source',
77
+ infoBoxTitle: 'Knowledge Source Node',
78
+ infoBoxBody: 'Creates a portable reference to one logical source in a named project knowledge store.',
79
+ group: 'Knowledge',
80
+ };
81
+ }
82
+ async process(inputs, _context) {
83
+ const connectionId = normalizeKnowledgeConnectionId(this.data.useConnectionIdInput ? coerceType(inputs['connection-id'], 'string') : this.data.connectionId);
84
+ const sourceId = normalizeKnowledgeSourceId(this.data.useSourceIdInput ? coerceType(inputs['source-id'], 'string') : this.data.sourceId);
85
+ const version = (this.data.useVersionInput ? coerceType(inputs['version'], 'string') : this.data.version).trim();
86
+ return {
87
+ ['source']: {
88
+ type: 'knowledge-source',
89
+ value: normalizeKnowledgeSourceReference({ connectionId, sourceId, ...(version ? { version } : {}) }),
90
+ },
91
+ };
92
+ }
93
+ }
94
+ export const knowledgeSourceNode = nodeDefinition(KnowledgeSourceNodeImpl, 'Knowledge Source');
@@ -0,0 +1,127 @@
1
+ import { nanoid } from 'nanoid/non-secure';
2
+ import { dedent } from 'ts-dedent';
3
+ import { nodeDefinition } from '../NodeDefinition.js';
4
+ import { NodeImpl } from '../NodeImpl.js';
5
+ import { coerceType } from '../../utils/coerceType.js';
6
+ import { normalizeKnowledgeFilter, normalizeKnowledgeQueries, normalizeSearchKnowledgeSourceResult, normalizeKnowledgeSourceReference, } from '../../integrations/KnowledgeStoreValidation.js';
7
+ export class SearchKnowledgeNodeImpl extends NodeImpl {
8
+ static create() {
9
+ return {
10
+ id: nanoid(),
11
+ type: 'searchKnowledge',
12
+ title: 'Search Knowledge',
13
+ visualData: { x: 0, y: 0, width: 270 },
14
+ data: {
15
+ filter: {},
16
+ useFilterInput: false,
17
+ topK: 10,
18
+ maxConcurrency: 3,
19
+ finalResultCount: 10,
20
+ rerankMode: 'off',
21
+ rerankTopN: 7,
22
+ },
23
+ };
24
+ }
25
+ getInputDefinitions() {
26
+ const inputs = [
27
+ { id: 'source', title: 'Source', dataType: 'knowledge-source', required: true },
28
+ { id: 'query', title: 'Query', dataType: ['string', 'string[]'], required: true },
29
+ ];
30
+ if (this.data.useFilterInput)
31
+ inputs.push({ id: 'filter', title: 'Metadata Filter', dataType: 'object' });
32
+ return inputs;
33
+ }
34
+ getOutputDefinitions() {
35
+ return [
36
+ { id: 'evidence', title: 'Evidence', dataType: 'knowledge-evidence[]' },
37
+ { id: 'source', title: 'Resolved Source', dataType: 'knowledge-source' },
38
+ { id: 'source-found', title: 'Source Found', dataType: 'boolean' },
39
+ { id: 'query-results', title: 'Query Results', dataType: 'object[]' },
40
+ { id: 'message', title: 'Status Message', dataType: 'string' },
41
+ ];
42
+ }
43
+ getEditors() {
44
+ return [
45
+ {
46
+ type: 'jsonObject',
47
+ dataKey: 'filter',
48
+ useInputToggleDataKey: 'useFilterInput',
49
+ label: 'Metadata Filter',
50
+ helperMessage: 'Enter a JSON filter expression, or leave {} to search without a metadata filter.',
51
+ },
52
+ { type: 'number', dataKey: 'topK', label: 'Results Per Query', min: 1, max: 100 },
53
+ { type: 'number', dataKey: 'maxConcurrency', label: 'Query Concurrency', min: 1, max: 32 },
54
+ { type: 'number', dataKey: 'finalResultCount', label: 'Final Result Count', min: 1, max: 500 },
55
+ {
56
+ type: 'dropdown',
57
+ dataKey: 'rerankMode',
58
+ label: 'Provider Reranking',
59
+ options: [
60
+ { value: 'off', label: 'Off' },
61
+ { value: 'connection-default', label: 'Connection Default' },
62
+ { value: 'required', label: 'Required' },
63
+ ],
64
+ },
65
+ {
66
+ type: 'number',
67
+ dataKey: 'rerankTopN',
68
+ label: 'Rerank Result Count',
69
+ min: 1,
70
+ max: 100,
71
+ hideIf: (data) => data.rerankMode === 'off',
72
+ },
73
+ ];
74
+ }
75
+ getBody() {
76
+ return dedent `
77
+ ${this.data.topK} per query -> ${this.data.finalResultCount} final
78
+ Reranking: ${this.data.rerankMode}
79
+ `;
80
+ }
81
+ static getUIData() {
82
+ return {
83
+ contextMenuTitle: 'Search Knowledge',
84
+ infoBoxTitle: 'Search Knowledge Node',
85
+ infoBoxBody: 'Searches the active durable source version and returns normalized, deduplicated evidence.',
86
+ group: 'Knowledge',
87
+ };
88
+ }
89
+ async process(inputs, context) {
90
+ const source = normalizeKnowledgeSourceReference(coerceType(inputs['source'], 'knowledge-source'));
91
+ const queryInput = inputs['query'];
92
+ const queries = normalizeKnowledgeQueries(queryInput?.type === 'string[]'
93
+ ? queryInput.value
94
+ : queryInput?.type === 'any' && Array.isArray(queryInput.value)
95
+ ? queryInput.value
96
+ : [coerceType(queryInput, 'string')]);
97
+ const rawFilter = this.data.useFilterInput ? coerceType(inputs['filter'], 'object') : this.data.filter;
98
+ const filter = Object.keys(rawFilter).length ? normalizeKnowledgeFilter(rawFilter) : undefined;
99
+ const rerank = this.data.rerankMode === 'off'
100
+ ? undefined
101
+ : { mode: this.data.rerankMode, topN: this.data.rerankTopN };
102
+ const store = await context.getKnowledgeStore(source.connectionId);
103
+ const result = normalizeSearchKnowledgeSourceResult(await store.search({
104
+ source,
105
+ queries,
106
+ topK: this.data.topK,
107
+ maxConcurrency: this.data.maxConcurrency,
108
+ finalResultCount: this.data.finalResultCount,
109
+ filter,
110
+ rerank,
111
+ }, { signal: context.signal, reportProgress: context.reportProgress }), source, queries);
112
+ return {
113
+ ['evidence']: { type: 'knowledge-evidence[]', value: result.evidence },
114
+ ['source']: { type: 'knowledge-source', value: result.source },
115
+ ['source-found']: { type: 'boolean', value: result.sourceFound },
116
+ ['query-results']: {
117
+ type: 'object[]',
118
+ value: result.queryResults.map((queryResult) => ({
119
+ query: queryResult.query,
120
+ evidence: queryResult.evidence,
121
+ })),
122
+ },
123
+ ['message']: { type: 'string', value: result.message },
124
+ };
125
+ }
126
+ }
127
+ export const searchKnowledgeNode = nodeDefinition(SearchKnowledgeNodeImpl, 'Search Knowledge');
@@ -1,4 +1,5 @@
1
1
  import { getDefaultValue, getScalarTypeOf, isArrayDataType, } from '../DataValue.js';
2
+ import { isKnowledgeDocument, isKnowledgeEvidence, isKnowledgeSourceReference, } from '../../integrations/KnowledgeStoreValidation.js';
2
3
  export const portableStoredValueScalarTypes = [
3
4
  'any',
4
5
  'boolean',
@@ -9,6 +10,9 @@ export const portableStoredValueScalarTypes = [
9
10
  'datetime',
10
11
  'object',
11
12
  'vector',
13
+ 'knowledge-source',
14
+ 'knowledge-document',
15
+ 'knowledge-evidence',
12
16
  ];
13
17
  export function storedValueToDataValue(value, dataType) {
14
18
  const outputValue = isStoredValueCompatibleWithDataType(value, dataType) ? value : getDefaultValue(dataType);
@@ -41,6 +45,12 @@ function isStoredValueCompatibleWithScalarType(value, dataType) {
41
45
  return typeof value === 'object' && value !== null && !Array.isArray(value);
42
46
  case 'vector':
43
47
  return Array.isArray(value) && value.every((item) => typeof item === 'number' && Number.isFinite(item));
48
+ case 'knowledge-source':
49
+ return isKnowledgeSourceReference(value);
50
+ case 'knowledge-document':
51
+ return isKnowledgeDocument(value);
52
+ case 'knowledge-evidence':
53
+ return isKnowledgeEvidence(value);
44
54
  default:
45
55
  return false;
46
56
  }