@valerypopoff/rivet2-core 2.1.6 → 2.1.8

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 (79) hide show
  1. package/dist/cjs/bundle.cjs +3436 -1831
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/esm/api/createProcessor.js +45 -4
  4. package/dist/esm/exports.js +2 -0
  5. package/dist/esm/integrations/KnowledgeStoreFieldPolicy.js +216 -0
  6. package/dist/esm/integrations/KnowledgeStoreProvider.js +14 -90
  7. package/dist/esm/integrations/ManagedKnowledgeStore.js +0 -8
  8. package/dist/esm/model/DataBusPorts.js +26 -0
  9. package/dist/esm/model/DataBusTopology.js +207 -0
  10. package/dist/esm/model/DataValue.js +22 -7
  11. package/dist/esm/model/GraphPreprocessor.js +9 -3
  12. package/dist/esm/model/GraphProcessor.js +163 -366
  13. package/dist/esm/model/NodeIO.js +1 -0
  14. package/dist/esm/model/NodePrefabResolver.js +16 -0
  15. package/dist/esm/model/Nodes.js +7 -0
  16. package/dist/esm/model/ToolCallContinuationBranchPlanner.js +165 -0
  17. package/dist/esm/model/ToolCallContinuationCoordinator.js +201 -0
  18. package/dist/esm/model/chat-v2/chatV2CallObserver.js +140 -0
  19. package/dist/esm/model/chat-v2/chatV2Errors.js +23 -6
  20. package/dist/esm/model/chat-v2/chatV2Pipeline.js +47 -14
  21. package/dist/esm/model/chat-v2/chatV2ProviderTypes.js +1 -0
  22. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +2 -2
  23. package/dist/esm/model/chat-v2/index.js +1 -0
  24. package/dist/esm/model/chat-v2/llmChatV2NodeData.js +52 -0
  25. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +38 -13
  26. package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +42 -34
  27. package/dist/esm/model/chat-v2/llmProfile.js +191 -0
  28. package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +73 -0
  29. package/dist/esm/model/chat-v2/llmProfileTypes.js +45 -0
  30. package/dist/esm/model/nodes/DataBusNode.js +81 -0
  31. package/dist/esm/model/nodes/GetGlobalNode.js +7 -11
  32. package/dist/esm/model/nodes/GetKnowledgeSourceStatusNode.js +1 -1
  33. package/dist/esm/model/nodes/LLMChatV2Node.js +44 -10
  34. package/dist/esm/model/nodes/LLMProfileNode.js +132 -0
  35. package/dist/esm/model/nodes/PassthroughNode.js +26 -8
  36. package/dist/esm/model/nodes/SearchKnowledgeNode.js +1 -1
  37. package/dist/esm/model/nodes/SetGlobalNode.js +6 -6
  38. package/dist/esm/model/nodes/SyncKnowledgeSourceNode.js +0 -1
  39. package/dist/esm/model/nodes/toolCallDelegation.js +13 -2
  40. package/dist/esm/plugins/pinecone/PineconeKnowledgeStore.js +0 -4
  41. package/dist/esm/plugins/pinecone/plugin.js +1 -1
  42. package/dist/esm/utils/coerceType.js +84 -41
  43. package/dist/esm/utils/expectType.js +45 -8
  44. package/dist/esm/utils/fetchEventSource.js +18 -0
  45. package/dist/esm/utils/serialization/serialization.js +18 -7
  46. package/dist/esm/vendor/fnv1a.js +6 -3
  47. package/dist/types/api/createProcessor.d.ts +2 -0
  48. package/dist/types/exports.d.ts +2 -0
  49. package/dist/types/integrations/KnowledgeStore.d.ts +0 -2
  50. package/dist/types/integrations/KnowledgeStoreFieldPolicy.d.ts +38 -0
  51. package/dist/types/integrations/KnowledgeStoreProvider.d.ts +6 -3
  52. package/dist/types/model/DataBusPorts.d.ts +6 -0
  53. package/dist/types/model/DataBusTopology.d.ts +16 -0
  54. package/dist/types/model/DataValue.d.ts +15 -5
  55. package/dist/types/model/GraphPreprocessor.d.ts +2 -1
  56. package/dist/types/model/GraphProcessor.d.ts +4 -3
  57. package/dist/types/model/NodeIO.d.ts +5 -0
  58. package/dist/types/model/NodePrefabResolver.d.ts +9 -0
  59. package/dist/types/model/Nodes.d.ts +5 -2
  60. package/dist/types/model/ProcessContext.d.ts +60 -0
  61. package/dist/types/model/ToolCallContinuationBranchPlanner.d.ts +43 -0
  62. package/dist/types/model/ToolCallContinuationCoordinator.d.ts +70 -0
  63. package/dist/types/model/chat-v2/chatV2CallObserver.d.ts +10 -0
  64. package/dist/types/model/chat-v2/chatV2ProviderTypes.d.ts +1 -0
  65. package/dist/types/model/chat-v2/chatV2RuntimeOptions.d.ts +8 -0
  66. package/dist/types/model/chat-v2/chatV2Types.d.ts +3 -3
  67. package/dist/types/model/chat-v2/index.d.ts +1 -0
  68. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +6 -0
  69. package/dist/types/model/chat-v2/llmChatV2NodeEditors.d.ts +5 -1
  70. package/dist/types/model/chat-v2/llmProfile.d.ts +3 -0
  71. package/dist/types/model/chat-v2/llmProfileNodeRuntime.d.ts +9 -0
  72. package/dist/types/model/chat-v2/llmProfileTypes.d.ts +18 -0
  73. package/dist/types/model/nodes/DataBusNode.d.ts +19 -0
  74. package/dist/types/model/nodes/LLMProfileNode.d.ts +20 -0
  75. package/dist/types/model/nodes/PassthroughNode.d.ts +3 -2
  76. package/dist/types/model/nodes/SetGlobalNode.d.ts +2 -2
  77. package/dist/types/model/nodes/toolCallDelegation.d.ts +9 -0
  78. package/dist/types/vendor/fnv1a.d.ts +5 -5
  79. package/package.json +1 -1
@@ -89,9 +89,27 @@ export function coreCreateProcessor(project, options, internalOptions = {}) {
89
89
  processor.onUserEvent(name, fn);
90
90
  }
91
91
  }
92
- options.abortSignal?.addEventListener('abort', () => {
92
+ const abortSignal = options.abortSignal;
93
+ let abortSignalAttached = false;
94
+ const abortProcessor = () => {
95
+ abortSignalAttached = false;
93
96
  void processor.abort();
94
- });
97
+ };
98
+ const attachAbortSignal = () => {
99
+ if (!abortSignal || abortSignal.aborted || abortSignalAttached) {
100
+ return;
101
+ }
102
+ abortSignal.addEventListener('abort', abortProcessor, { once: true });
103
+ abortSignalAttached = true;
104
+ };
105
+ const detachAbortSignal = () => {
106
+ if (!abortSignal || !abortSignalAttached) {
107
+ return;
108
+ }
109
+ abortSignal.removeEventListener('abort', abortProcessor);
110
+ abortSignalAttached = false;
111
+ };
112
+ attachAbortSignal();
95
113
  const resolvedInputs = looseDataValuesToDataValues(inputs);
96
114
  const resolvedContextValues = looseDataValuesToDataValues(context);
97
115
  return {
@@ -101,8 +119,13 @@ export function coreCreateProcessor(project, options, internalOptions = {}) {
101
119
  getEvents: (spec) => getProcessorEvents(processor, spec),
102
120
  getSSEStream: (spec) => getProcessorSSEStream(processor, spec),
103
121
  streamNode: (nodeIdOrTitle) => getSingleNodeStream(processor, nodeIdOrTitle),
122
+ dispose() {
123
+ detachAbortSignal();
124
+ },
104
125
  async run() {
105
- const outputs = await processor.processGraph({
126
+ abortSignal?.throwIfAborted();
127
+ attachAbortSignal();
128
+ const outputsPromise = processor.processGraph({
106
129
  nativeApi: options.nativeApi,
107
130
  datasetProvider: options.datasetProvider,
108
131
  audioProvider: options.audioProvider,
@@ -114,12 +137,30 @@ export function coreCreateProcessor(project, options, internalOptions = {}) {
114
137
  editorExecutionCache: options.editorExecutionCache,
115
138
  settings: resolveProcessSettings(options),
116
139
  getChatNodeEndpoint: options.getChatNodeEndpoint,
140
+ onChatV2CallFinished: options.onChatV2CallFinished,
117
141
  }, resolvedInputs, resolvedContextValues, { returnWhenGraphOutputsReady: options.returnWhenGraphOutputsReady });
118
- return outputs;
142
+ if (abortSignal?.aborted) {
143
+ void processor.abort();
144
+ }
145
+ try {
146
+ return await outputsPromise;
147
+ }
148
+ finally {
149
+ if (processor.isRunning) {
150
+ void processor
151
+ .waitForRunCompletion()
152
+ .catch(() => undefined)
153
+ .finally(detachAbortSignal);
154
+ }
155
+ else {
156
+ detachAbortSignal();
157
+ }
158
+ }
119
159
  },
120
160
  };
121
161
  }
122
162
  export async function coreRunGraph(project, options) {
163
+ options.abortSignal?.throwIfAborted();
123
164
  const processorInfo = coreCreateProcessor(project, options);
124
165
  return processorInfo.run();
125
166
  }
@@ -34,6 +34,7 @@ export * from './integrations/integrations.js';
34
34
  import './integrations/enableIntegrations.js';
35
35
  export * from './integrations/VectorDatabase.js';
36
36
  export * from './integrations/KnowledgeStore.js';
37
+ export * from './integrations/KnowledgeStoreFieldPolicy.js';
37
38
  export * from './integrations/KnowledgeStoreProvider.js';
38
39
  export * from './integrations/KnowledgeStoreValidation.js';
39
40
  export * from './integrations/ManagedKnowledgeStore.js';
@@ -61,6 +62,7 @@ export * from './integrations/CodeRunner.js';
61
62
  export * from './integrations/Tokenizer.js';
62
63
  export * from './integrations/GptTokenizerTokenizer.js';
63
64
  export { JS_LIST_CALLBACK_LOCAL_NAMES, interpolateJSListCallbackBody } from './model/nodes/jsListCallbackHelpers.js';
65
+ export { findAutoDelegateGraphCandidate } from './model/nodes/toolCallDelegation.js';
64
66
  export { extractInterpolationVariables, findInterpolationTokenSpans, getInterpolationTokenName, interpolate, protectEscapedInterpolationTokens, restoreEscapedInterpolationTokens, } from './utils/interpolation.js';
65
67
  export { WarningsPort } from './utils/symbols.js';
66
68
  import * as openai from './utils/openai.js';
@@ -0,0 +1,216 @@
1
+ export function createKnowledgeStoreFieldDraftDefaults(fields) {
2
+ return Object.fromEntries(fields.map((field) => [field.key, field.default ?? (field.type === 'boolean' ? false : '')]));
3
+ }
4
+ /** Normalizes one declared provider field at an explicit editor or runtime boundary. */
5
+ export function normalizeKnowledgeStoreProviderFieldValue(field, value, mode) {
6
+ if (mode === 'credential-draft') {
7
+ if (typeof value !== 'string')
8
+ return fieldIssue(field, 'expected-string');
9
+ if (field.required && !value.trim())
10
+ return fieldIssue(field, 'required');
11
+ return value === '' ? { ok: true, value: { present: false } } : { ok: true, value: { present: true, value } };
12
+ }
13
+ if (mode === 'credential-runtime') {
14
+ if (value === undefined || value === '') {
15
+ return field.required ? fieldIssue(field, 'required') : { ok: true, value: { present: false } };
16
+ }
17
+ if (typeof value !== 'string')
18
+ return fieldIssue(field, 'expected-string');
19
+ if (field.required && !value.trim())
20
+ return fieldIssue(field, 'required');
21
+ return { ok: true, value: { present: true, value } };
22
+ }
23
+ if (mode !== 'connection-draft' && mode !== 'connection-runtime') {
24
+ throw new Error('Unsupported Knowledge Store field normalization mode.');
25
+ }
26
+ const missingRequired = mode === 'connection-draft'
27
+ ? field.required && (value == null || String(value).trim() === '')
28
+ : field.required && (value == null || (typeof value === 'string' && !value.trim()));
29
+ if (missingRequired)
30
+ return fieldIssue(field, 'required');
31
+ if (value === undefined || value === '') {
32
+ return { ok: true, value: { present: false } };
33
+ }
34
+ if (field.type === 'boolean') {
35
+ return typeof value === 'boolean'
36
+ ? { ok: true, value: { present: true, value } }
37
+ : fieldIssue(field, 'expected-boolean');
38
+ }
39
+ if (field.type === 'number') {
40
+ return typeof value === 'number' && Number.isFinite(value)
41
+ ? { ok: true, value: { present: true, value } }
42
+ : fieldIssue(field, 'expected-finite-number');
43
+ }
44
+ if (typeof value !== 'string') {
45
+ return fieldIssue(field, 'expected-string');
46
+ }
47
+ if (field.type === 'select' && !(field.options ?? []).some((option) => option.value === value)) {
48
+ return fieldIssue(field, 'unsupported-select-value');
49
+ }
50
+ return { ok: true, value: { present: true, value } };
51
+ }
52
+ export function isKnowledgeStoreProviderFieldDefaultValid(field, value) {
53
+ if (field.type === 'boolean')
54
+ return typeof value === 'boolean';
55
+ if (field.type === 'number')
56
+ return typeof value === 'number' && Number.isFinite(value);
57
+ if (typeof value !== 'string')
58
+ return false;
59
+ return field.type !== 'select' || (field.options ?? []).some((option) => option.value === value);
60
+ }
61
+ export function normalizeKnowledgeStoreConnectionDraftConfig(fields, values) {
62
+ return normalizeDeclaredFields(fields, values, 'connection-draft');
63
+ }
64
+ export function normalizeKnowledgeStoreCredentialFields(fields, values) {
65
+ const result = normalizeDeclaredFields(fields, values, 'credential-draft');
66
+ if (!result.ok)
67
+ return result;
68
+ return { ok: true, value: result.value };
69
+ }
70
+ export function normalizeKnowledgeStoreConnectionDefinition(connectionId, definition, provider) {
71
+ const displayName = typeof definition.displayName === 'string' ? definition.displayName.trim() : '';
72
+ if (!displayName)
73
+ throw new Error(`Knowledge store connection "${connectionId}" has no display name.`);
74
+ if (definition.provider !== provider.id) {
75
+ throw new Error(`Knowledge store connection "${displayName}" names the wrong provider.`);
76
+ }
77
+ if (!isPlainRecord(definition.config)) {
78
+ throw new Error(`Knowledge store connection "${displayName}" has invalid provider configuration.`);
79
+ }
80
+ const fieldsByKey = new Set(provider.connectionConfigSpec.map((field) => field.key));
81
+ for (const key of Object.keys(definition.config)) {
82
+ if (!fieldsByKey.has(key)) {
83
+ throw new Error(`Knowledge store connection "${displayName}" contains unknown configuration field "${key}".`);
84
+ }
85
+ }
86
+ const normalizedConfig = normalizeDeclaredFields(provider.connectionConfigSpec, definition.config, 'connection-runtime');
87
+ if (!normalizedConfig.ok) {
88
+ throw new Error(formatRuntimeConnectionFieldIssue(displayName, normalizedConfig.issue));
89
+ }
90
+ const pluginId = typeof definition.pluginId === 'string' ? definition.pluginId.trim() : '';
91
+ if (definition.pluginId != null && (!pluginId || pluginId !== definition.pluginId)) {
92
+ throw new Error(`Knowledge store connection "${displayName}" has an invalid owning plugin ID.`);
93
+ }
94
+ const providerPluginId = provider.pluginId ?? provider.id;
95
+ if (pluginId && pluginId !== providerPluginId) {
96
+ throw new Error(`Knowledge store connection "${displayName}" names the wrong owning plugin.`);
97
+ }
98
+ return {
99
+ displayName,
100
+ provider: provider.id,
101
+ pluginId: providerPluginId,
102
+ config: normalizedConfig.value,
103
+ };
104
+ }
105
+ export function readKnowledgeStoreConnectionCredentials(settings, provider, connectionId) {
106
+ const result = normalizeDeclaredFields(provider.credentialConfigSpec ?? [], readCredentialValues(settings, provider.id, connectionId), 'credential-runtime');
107
+ if (!result.ok)
108
+ return result;
109
+ return { ok: true, value: result.value };
110
+ }
111
+ export function readKnowledgeStoreConnectionCredentialsDraft(settings, provider, connectionId) {
112
+ const storedValues = readCredentialValues(settings, provider.id, connectionId);
113
+ const entries = [];
114
+ for (const field of provider.credentialConfigSpec ?? []) {
115
+ const value = readOwnProperty(storedValues, field.key);
116
+ if (typeof value === 'string')
117
+ entries.push([field.key, value]);
118
+ }
119
+ return Object.fromEntries(entries);
120
+ }
121
+ export function writeKnowledgeStoreConnectionCredentials(settings, providerId, connectionId, credentials) {
122
+ const pluginSettings = isPlainRecord(settings.pluginSettings) ? settings.pluginSettings : {};
123
+ const providerSettings = readOwnRecord(pluginSettings, providerId) ?? {};
124
+ const existingSets = readOwnRecord(providerSettings, 'knowledgeStoreCredentials') ?? {};
125
+ const nextSets = Object.keys(credentials).length > 0
126
+ ? { ...existingSets, [connectionId]: { ...credentials } }
127
+ : omitOwnProperty(existingSets, connectionId);
128
+ return {
129
+ ...settings,
130
+ pluginSettings: {
131
+ ...pluginSettings,
132
+ [providerId]: {
133
+ ...providerSettings,
134
+ knowledgeStoreCredentials: nextSets,
135
+ },
136
+ },
137
+ };
138
+ }
139
+ export function removeKnowledgeStoreConnectionCredentials(settings, providerId, connectionId) {
140
+ const pluginSettings = isPlainRecord(settings.pluginSettings) ? settings.pluginSettings : undefined;
141
+ const providerSettings = readOwnRecord(pluginSettings, providerId);
142
+ if (!providerSettings)
143
+ return settings;
144
+ const credentialSets = readOwnRecord(providerSettings, 'knowledgeStoreCredentials');
145
+ if (!credentialSets)
146
+ return settings;
147
+ return {
148
+ ...settings,
149
+ pluginSettings: {
150
+ ...pluginSettings,
151
+ [providerId]: {
152
+ ...providerSettings,
153
+ knowledgeStoreCredentials: omitOwnProperty(credentialSets, connectionId),
154
+ },
155
+ },
156
+ };
157
+ }
158
+ function normalizeDeclaredFields(fields, values, mode) {
159
+ const entries = [];
160
+ for (const field of fields) {
161
+ const value = getDeclaredFieldValue(field, values, mode);
162
+ const normalized = normalizeKnowledgeStoreProviderFieldValue(field, value, mode);
163
+ if (!normalized.ok)
164
+ return normalized;
165
+ if (normalized.value.present)
166
+ entries.push([field.key, normalized.value.value]);
167
+ }
168
+ return { ok: true, value: Object.fromEntries(entries) };
169
+ }
170
+ function getDeclaredFieldValue(field, values, mode) {
171
+ if (hasOwnProperty(values, field.key))
172
+ return values[field.key];
173
+ if (mode === 'credential-draft')
174
+ return typeof field.default === 'string' ? field.default : '';
175
+ return field.default;
176
+ }
177
+ function readCredentialValues(settings, providerId, connectionId) {
178
+ const providerSettings = readOwnRecord(settings.pluginSettings, providerId);
179
+ const credentialSets = readOwnRecord(providerSettings, 'knowledgeStoreCredentials');
180
+ const storedCredentials = readOwnRecord(credentialSets, connectionId);
181
+ return storedCredentials ? { ...storedCredentials } : {};
182
+ }
183
+ function formatRuntimeConnectionFieldIssue(displayName, issue) {
184
+ return issue.code === 'required'
185
+ ? `Knowledge store connection "${displayName}" requires ${issue.fieldLabel}.`
186
+ : `Knowledge store connection "${displayName}" has an invalid value for ${issue.fieldLabel}.`;
187
+ }
188
+ function fieldIssue(field, code) {
189
+ return {
190
+ ok: false,
191
+ issue: {
192
+ code,
193
+ fieldKey: field.key,
194
+ fieldLabel: field.label,
195
+ },
196
+ };
197
+ }
198
+ function readOwnProperty(value, key) {
199
+ return hasOwnProperty(value, key) ? value[key] : undefined;
200
+ }
201
+ function readOwnRecord(value, key) {
202
+ const property = readOwnProperty(value, key);
203
+ return isPlainRecord(property) ? property : undefined;
204
+ }
205
+ function hasOwnProperty(value, key) {
206
+ return isPlainRecord(value) && Object.prototype.hasOwnProperty.call(value, key);
207
+ }
208
+ function omitOwnProperty(source, key) {
209
+ return Object.fromEntries(Object.entries(source).filter(([entryKey]) => entryKey !== key));
210
+ }
211
+ function isPlainRecord(value) {
212
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
213
+ return false;
214
+ const prototype = Object.getPrototypeOf(value);
215
+ return prototype === Object.prototype || prototype === null;
216
+ }
@@ -1,4 +1,5 @@
1
1
  import { isReservedKnowledgeObjectKey, normalizeKnowledgeConnectionId } from './KnowledgeStoreValidation.js';
2
+ import { isKnowledgeStoreProviderFieldDefaultValid, normalizeKnowledgeStoreConnectionDefinition, readKnowledgeStoreConnectionCredentials, } from './KnowledgeStoreFieldPolicy.js';
2
3
  const providers = new Map();
3
4
  export function registerKnowledgeStoreProvider(provider) {
4
5
  if (!provider || typeof provider !== 'object') {
@@ -78,7 +79,7 @@ export class KnowledgeStoreController {
78
79
  if (!provider) {
79
80
  throw new Error(`Knowledge store provider "${providerId}" for connection "${definition.displayName}" is not installed.`);
80
81
  }
81
- const normalizedDefinition = normalizeConnectionDefinition(normalizedId, definition, provider);
82
+ const normalizedDefinition = normalizeKnowledgeStoreConnectionDefinition(normalizedId, definition, provider);
82
83
  const executor = context.executor;
83
84
  if (!provider.supportedExecutors.includes(executor)) {
84
85
  throw new Error(`Knowledge store "${definition.displayName}" does not support the ${executor === 'nodejs' ? 'Node' : 'Browser'} executor.`);
@@ -95,7 +96,7 @@ export class KnowledgeStoreController {
95
96
  executor: context.executor,
96
97
  project: context.project,
97
98
  settings: context.settings,
98
- credentials: readProviderCredentials(context.settings, provider, normalizedId),
99
+ credentials: resolveProviderCredentials(context.settings, provider, normalizedId),
99
100
  };
100
101
  pending = Promise.resolve(provider.createStore(normalizedId, normalizedDefinition, providerContext)).then((store) => validateResolvedStore(store, normalizedId, context.executor));
101
102
  storeCache.set(normalizedId, pending);
@@ -120,31 +121,13 @@ function validateResolvedStore(store, connectionId, executor) {
120
121
  }
121
122
  return store;
122
123
  }
123
- function readProviderCredentials(settings, provider, connectionId) {
124
- const providerSettings = readOwnProperty(settings.pluginSettings, provider.id);
125
- const credentialSets = isRecord(providerSettings)
126
- ? readOwnProperty(providerSettings, 'knowledgeStoreCredentials')
127
- : undefined;
128
- const storedCredentials = isRecord(credentialSets) ? readOwnProperty(credentialSets, connectionId) : undefined;
129
- const storedValues = isRecord(storedCredentials) ? storedCredentials : {};
130
- const credentials = {};
131
- for (const field of provider.credentialConfigSpec ?? []) {
132
- const value = hasOwnProperty(storedValues, field.key) ? storedValues[field.key] : field.default;
133
- if (value === undefined || value === '') {
134
- if (field.required) {
135
- throw new Error(`Knowledge store connection "${connectionId}" requires ${field.label}.`);
136
- }
137
- continue;
138
- }
139
- if (typeof value !== 'string') {
140
- throw new Error(`Knowledge store connection "${connectionId}" has invalid stored credentials for ${field.label}.`);
141
- }
142
- if (field.required && !value.trim()) {
143
- throw new Error(`Knowledge store connection "${connectionId}" requires ${field.label}.`);
144
- }
145
- credentials[field.key] = value;
146
- }
147
- return credentials;
124
+ function resolveProviderCredentials(settings, provider, connectionId) {
125
+ const result = readKnowledgeStoreConnectionCredentials(settings, provider, connectionId);
126
+ if (result.ok)
127
+ return result.value;
128
+ throw new Error(result.issue.code === 'required'
129
+ ? `Knowledge store connection "${connectionId}" requires ${result.issue.fieldLabel}.`
130
+ : `Knowledge store connection "${connectionId}" has invalid stored credentials for ${result.issue.fieldLabel}.`);
148
131
  }
149
132
  function validateStoreCapabilities(capabilities, connectionId) {
150
133
  if (capabilities.supportedExecutors != null &&
@@ -196,6 +179,9 @@ function validateProviderFields(providerId, fields, kind) {
196
179
  if (kind === 'credential' && field.type !== 'string' && field.type !== 'secret') {
197
180
  throw new Error(`Knowledge store provider "${providerId}" credential field "${field.key}" must be a string or secret.`);
198
181
  }
182
+ if (kind === 'credential' && field.options !== undefined) {
183
+ throw new Error(`Knowledge store provider "${providerId}" credential field "${field.key}" cannot declare select options.`);
184
+ }
199
185
  if (field.type === 'select') {
200
186
  const options = field.options;
201
187
  if (!Array.isArray(options) ||
@@ -209,7 +195,7 @@ function validateProviderFields(providerId, fields, kind) {
209
195
  throw new Error(`Knowledge store provider "${providerId}" select field "${field.key}" requires labeled options with unique string values.`);
210
196
  }
211
197
  }
212
- if (field.default !== undefined && !isProviderFieldValue(field, field.default)) {
198
+ if (field.default !== undefined && !isKnowledgeStoreProviderFieldDefaultValid(field, field.default)) {
213
199
  throw new Error(`Knowledge store provider "${providerId}" field "${field.key}" has an invalid default value.`);
214
200
  }
215
201
  }
@@ -228,65 +214,3 @@ function snapshotProviderDefinition(provider) {
228
214
  supportedExecutors: Object.freeze([...provider.supportedExecutors]),
229
215
  });
230
216
  }
231
- function normalizeConnectionDefinition(connectionId, definition, provider) {
232
- const displayName = typeof definition.displayName === 'string' ? definition.displayName.trim() : '';
233
- if (!displayName)
234
- throw new Error(`Knowledge store connection "${connectionId}" has no display name.`);
235
- if (!isRecord(definition.config)) {
236
- throw new Error(`Knowledge store connection "${displayName}" has invalid provider configuration.`);
237
- }
238
- const fieldsByKey = new Map(provider.connectionConfigSpec.map((field) => [field.key, field]));
239
- for (const key of Object.keys(definition.config)) {
240
- if (!fieldsByKey.has(key)) {
241
- throw new Error(`Knowledge store connection "${displayName}" contains unknown configuration field "${key}".`);
242
- }
243
- }
244
- const config = {};
245
- for (const field of provider.connectionConfigSpec) {
246
- const value = hasOwnProperty(definition.config, field.key) ? definition.config[field.key] : field.default;
247
- if (field.required && (value == null || (typeof value === 'string' && !value.trim()))) {
248
- throw new Error(`Knowledge store connection "${displayName}" requires ${field.label}.`);
249
- }
250
- if (value === undefined || value === '')
251
- continue;
252
- if (!isProviderFieldValue(field, value)) {
253
- throw new Error(`Knowledge store connection "${displayName}" has an invalid value for ${field.label}.`);
254
- }
255
- config[field.key] = value;
256
- }
257
- const pluginId = typeof definition.pluginId === 'string' ? definition.pluginId.trim() : '';
258
- if (definition.pluginId != null && (!pluginId || pluginId !== definition.pluginId)) {
259
- throw new Error(`Knowledge store connection "${displayName}" has an invalid owning plugin ID.`);
260
- }
261
- const providerPluginId = provider.pluginId ?? provider.id;
262
- if (pluginId && pluginId !== providerPluginId) {
263
- throw new Error(`Knowledge store connection "${displayName}" names the wrong owning plugin.`);
264
- }
265
- return {
266
- displayName,
267
- provider: provider.id,
268
- pluginId: providerPluginId,
269
- config,
270
- };
271
- }
272
- function isProviderFieldValue(field, value) {
273
- if (field.type === 'boolean')
274
- return typeof value === 'boolean';
275
- if (field.type === 'number')
276
- return typeof value === 'number' && Number.isFinite(value);
277
- if (typeof value !== 'string')
278
- return false;
279
- return field.type !== 'select' || (field.options ?? []).some((option) => option.value === value);
280
- }
281
- function isRecord(value) {
282
- if (typeof value !== 'object' || value === null || Array.isArray(value))
283
- return false;
284
- const prototype = Object.getPrototypeOf(value);
285
- return prototype === Object.prototype || prototype === null;
286
- }
287
- function readOwnProperty(value, key) {
288
- return hasOwnProperty(value, key) ? value[key] : undefined;
289
- }
290
- function hasOwnProperty(value, key) {
291
- return isRecord(value) && Object.prototype.hasOwnProperty.call(value, key);
292
- }
@@ -138,11 +138,9 @@ export class ManagedKnowledgeStore {
138
138
  warnings: [],
139
139
  };
140
140
  }
141
- context.reportProgress?.({ message: `Preparing ${documents.length} knowledge document(s).`, percent: 5 });
142
141
  const chunks = await chunkDocuments(documents, documentIds, version, chunking, context);
143
142
  if (chunks.length === 0)
144
143
  throw new Error('Sync Knowledge Source produced no non-empty chunks.');
145
- context.reportProgress?.({ message: `Uploading ${chunks.length} knowledge chunk(s).`, percent: 15 });
146
144
  await this.driver.upsertChunks(source.sourceId, version, chunks, context);
147
145
  throwIfAborted(context.signal);
148
146
  const manifest = {
@@ -155,7 +153,6 @@ export class ManagedKnowledgeStore {
155
153
  updatedAt: new Date().toISOString(),
156
154
  ...(metadata && Object.keys(metadata).length ? { metadata } : {}),
157
155
  };
158
- context.reportProgress?.({ message: 'Committing the new knowledge-source version.', percent: 90 });
159
156
  await this.driver.commitManifest(manifest, context);
160
157
  const committed = await this.#getManifest(source.sourceId, context);
161
158
  if (!sameManifestActivation(committed, manifest)) {
@@ -186,7 +183,6 @@ export class ManagedKnowledgeStore {
186
183
  }
187
184
  }
188
185
  }
189
- context.reportProgress?.({ message: 'Knowledge source is ready.', percent: 100 });
190
186
  return {
191
187
  source: { ...source, version },
192
188
  result: existing ? 'updated' : 'created',
@@ -356,10 +352,6 @@ async function chunkDocuments(documents, documentIds, version, options, context)
356
352
  ...(document.metadata ? { metadata: document.metadata } : {}),
357
353
  });
358
354
  });
359
- context.reportProgress?.({
360
- message: `Prepared document ${documentIndex + 1} of ${documents.length}.`,
361
- percent: 5 + Math.round(((documentIndex + 1) / documents.length) * 10),
362
- });
363
355
  }
364
356
  return chunks;
365
357
  }
@@ -0,0 +1,26 @@
1
+ const INPUT_PORT_PATTERN = /^input([1-9]\d*)$/;
2
+ const OUTPUT_PORT_PATTERN = /^output([1-9]\d*)$/;
3
+ /** Shared hard safety limit for the dynamic Data Bus channel port range. */
4
+ export const MAX_DATA_BUS_CHANNEL_INDEX = 10_000;
5
+ function assertDataBusChannelIndex(channelIndex) {
6
+ if (!Number.isSafeInteger(channelIndex) ||
7
+ channelIndex < 1 ||
8
+ channelIndex > MAX_DATA_BUS_CHANNEL_INDEX) {
9
+ throw new RangeError(`Data Bus channel index must be a safe integer from 1 to ${MAX_DATA_BUS_CHANNEL_INDEX}.`);
10
+ }
11
+ }
12
+ export function parseDataBusChannelIndex(portId, input) {
13
+ const match = (input ? INPUT_PORT_PATTERN : OUTPUT_PORT_PATTERN).exec(portId);
14
+ const channelIndex = match ? Number(match[1]) : Number.NaN;
15
+ return Number.isSafeInteger(channelIndex) && channelIndex > 0 && channelIndex <= MAX_DATA_BUS_CHANNEL_INDEX
16
+ ? channelIndex
17
+ : undefined;
18
+ }
19
+ export function getDataBusInputPortId(channelIndex) {
20
+ assertDataBusChannelIndex(channelIndex);
21
+ return `input${channelIndex}`;
22
+ }
23
+ export function getDataBusOutputPortId(channelIndex) {
24
+ assertDataBusChannelIndex(channelIndex);
25
+ return `output${channelIndex}`;
26
+ }