@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
@@ -11,13 +11,13 @@ export function getPluginConfig(plugin, settings, name) {
11
11
  if (!plugin) {
12
12
  return undefined;
13
13
  }
14
- const configSpec = plugin?.configSpec?.[name];
14
+ const configSpec = readOwnProperty(plugin.configSpec, name);
15
15
  if (!configSpec) {
16
16
  return undefined;
17
17
  }
18
- const pluginSettings = settings.pluginSettings?.[plugin.id];
19
- if (pluginSettings) {
20
- const value = pluginSettings[name];
18
+ const pluginSettings = readOwnProperty(settings.pluginSettings, plugin.id);
19
+ if (pluginSettings && typeof pluginSettings === 'object' && !Array.isArray(pluginSettings)) {
20
+ const value = readOwnProperty(pluginSettings, name);
21
21
  if (value && typeof value === 'string') {
22
22
  return value;
23
23
  }
@@ -28,8 +28,14 @@ export function getPluginConfig(plugin, settings, name) {
28
28
  }
29
29
  const envFallback = configSpec.pullEnvironmentVariable;
30
30
  const envFallbackName = envFallback === true ? name : envFallback;
31
- if (envFallbackName && settings.pluginEnv?.[envFallbackName]) {
32
- return settings.pluginEnv[envFallbackName];
31
+ const envValue = envFallbackName ? readOwnProperty(settings.pluginEnv, envFallbackName) : undefined;
32
+ if (typeof envValue === 'string' && envValue) {
33
+ return envValue;
33
34
  }
34
35
  return undefined;
35
36
  }
37
+ function readOwnProperty(value, key) {
38
+ if (!value || typeof value !== 'object' || Array.isArray(value))
39
+ return undefined;
40
+ return Object.prototype.hasOwnProperty.call(value, key) ? value[key] : undefined;
41
+ }
@@ -2,7 +2,7 @@
2
2
  import * as yaml from 'yaml';
3
3
  import { graphV3Deserializer, projectV3Deserializer } from './serialization_v3.js';
4
4
  import { getError } from '../errors.js';
5
- import { yamlProblem } from './serializationUtils.js';
5
+ import { ProjectValidationError, yamlProblem, } from './serializationUtils.js';
6
6
  import { prepareSerializedInput } from './serializationInput.js';
7
7
  import { UiGraphNormalizationError } from '../../model/UiGraphNormalization.js';
8
8
  import { datasetV4Deserializer, datasetV4Serializer, graphV4Deserializer, graphV4Serializer, projectV4Deserializer, projectV4Serializer, } from './serialization_v4.js';
@@ -30,6 +30,9 @@ export function deserializeProject(serializedProject, path = null) {
30
30
  if (err instanceof UiGraphNormalizationError) {
31
31
  throw new Error(`Could not deserialize project: ${err.message}`, { cause: err });
32
32
  }
33
+ if (err instanceof ProjectValidationError) {
34
+ throw new Error(`Could not deserialize project: ${err.message}`, { cause: err });
35
+ }
33
36
  throw new Error('Could not deserialize project');
34
37
  }
35
38
  }
@@ -1,5 +1,14 @@
1
1
  import { formatUiGraphNormalizationIssue, normalizeUiGraphRecord, UiGraphNormalizationError, } from '../../model/UiGraphNormalization.js';
2
2
  import { prepareSerializedInput } from './serializationInput.js';
3
+ import { isReservedKnowledgeObjectKey, normalizeKnowledgeConnectionId, normalizeKnowledgeMetadata, } from '../../integrations/KnowledgeStoreValidation.js';
4
+ export class ProjectValidationError extends Error {
5
+ validation;
6
+ constructor(validation) {
7
+ super(`Invalid project file: ${validation.errors.join('; ')}`);
8
+ this.validation = validation;
9
+ this.name = 'ProjectValidationError';
10
+ }
11
+ }
3
12
  /** Validates a deserialized project structure. Returns errors for structural problems. */
4
13
  export function validateProject(project) {
5
14
  const errors = [];
@@ -18,6 +27,8 @@ export function validateProject(project) {
18
27
  errors.push('Missing project metadata.id');
19
28
  if (!meta.title)
20
29
  errors.push('Missing project metadata.title');
30
+ if (meta.knowledgeStores != null)
31
+ validateKnowledgeStores(meta.knowledgeStores, errors);
21
32
  }
22
33
  // Graphs checks
23
34
  if (!p.graphs || typeof p.graphs !== 'object') {
@@ -69,6 +80,53 @@ export function validateProject(project) {
69
80
  }
70
81
  return { valid: errors.length === 0, errors, warnings };
71
82
  }
83
+ function validateKnowledgeStores(value, errors) {
84
+ if (!isPlainRecord(value)) {
85
+ errors.push('Project metadata.knowledgeStores is not a plain object');
86
+ return;
87
+ }
88
+ for (const [connectionId, definition] of Object.entries(value)) {
89
+ try {
90
+ const normalizedId = normalizeKnowledgeConnectionId(connectionId);
91
+ if (normalizedId !== connectionId)
92
+ throw new Error('connection ID cannot be padded');
93
+ if (!isPlainRecord(definition))
94
+ throw new Error('definition is not a plain object');
95
+ if (typeof definition.displayName !== 'string' || !definition.displayName.trim()) {
96
+ throw new Error('displayName must be a non-empty string');
97
+ }
98
+ if (definition.displayName !== definition.displayName.trim()) {
99
+ throw new Error('displayName cannot be padded');
100
+ }
101
+ validateKnowledgeProviderId(definition.provider, 'provider');
102
+ if (definition.pluginId != null)
103
+ validateKnowledgeProviderId(definition.pluginId, 'pluginId');
104
+ if (!isPlainRecord(definition.config))
105
+ throw new Error('config must be a plain object');
106
+ for (const key of Object.keys(definition.config)) {
107
+ if (key !== key.trim())
108
+ throw new Error(`config field "${key}" cannot be padded`);
109
+ }
110
+ normalizeKnowledgeMetadata(definition.config, 'Knowledge store connection configuration');
111
+ }
112
+ catch (error) {
113
+ errors.push(`Knowledge store connection "${connectionId}": ${error instanceof Error ? error.message : String(error)}`);
114
+ }
115
+ }
116
+ }
117
+ function validateKnowledgeProviderId(value, field) {
118
+ if (typeof value !== 'string' || !value.trim() || value !== value.trim()) {
119
+ throw new Error(`${field} must be a non-empty, unpadded string`);
120
+ }
121
+ if (isReservedKnowledgeObjectKey(value))
122
+ throw new Error(`${field} "${value}" is reserved`);
123
+ }
124
+ function isPlainRecord(value) {
125
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
126
+ return false;
127
+ const prototype = Object.getPrototypeOf(value);
128
+ return prototype === Object.prototype || prototype === null;
129
+ }
72
130
  function validateUiGraphs(uiGraphs, errors) {
73
131
  try {
74
132
  normalizeUiGraphRecord(uiGraphs, { repairComponentIds: false });
@@ -85,7 +143,7 @@ function validateUiGraphs(uiGraphs, errors) {
85
143
  export function doubleCheckProject(project) {
86
144
  const result = validateProject(project);
87
145
  if (!result.valid) {
88
- throw new Error(`Invalid project file: ${result.errors.join('; ')}`);
146
+ throw new ProjectValidationError(result);
89
147
  }
90
148
  }
91
149
  export function yamlProblem(err) {
@@ -1,4 +1,4 @@
1
1
  export { createUiGraphChatHistoryFlushStatePatch, createUiGraphChatPinStatePatch, createUiGraphChatSubmissionStatePatch, getUiGraphActionState, getUiGraphChatDraftStateKey, getUiGraphChatMessagesStateKey, } from './model/UiGraph.js';
2
2
  export { applyUiGraphStatePatch, createUiGraphActionExecutionController, createUiGraphInteractionController, getUiGraphComponentRenderModel, getUiGraphJsonOutputFilename, getUiGraphProgressiveJsonOutputChunks, } from './model/UiGraphRuntimeModel.js';
3
3
  export { parseRivetWebAppClientMessage, parseRivetWebAppServerMessage, RIVET_WEB_APP_ACTION_PROTOCOL_VERSION, } from './model/UiGraphActionProtocol.js';
4
- export { copyUiGraphText, applyUiGraphWebAppStorageActionPatch, applyUiGraphWebAppStoragePatch, clearUiGraphChatSearchMatches, downloadUiGraphJsonOutput, hasUiGraphChatPersistentStateChanged, getUiGraphChatPersistentState, getUiGraphChatStorageKey, getUiGraphWebAppStorageKey, highlightUiGraphChatSearchMatches, loadUiGraphChatPersistentState, loadUiGraphWebAppStorage, observeUiGraphOutputResizeBounds, revealUiGraphChatElement, revealUiGraphChatSearchMatch, saveUiGraphChatPersistentState, } from './model/UiGraphBrowserRuntime.js';
4
+ export { copyUiGraphText, applyUiGraphWebAppStorageActionPatch, applyUiGraphWebAppStoragePatch, clearUiGraphChatSearchMatches, downloadUiGraphJsonOutput, enhanceUiGraphChatJsonCodeBlocks, hasUiGraphChatPersistentStateChanged, getUiGraphChatPersistentState, getUiGraphChatMessagePresentations, getUiGraphChatStorageKey, getUiGraphWebAppStorageKey, highlightUiGraphChatSearchMatches, loadUiGraphChatPersistentState, loadUiGraphWebAppStorage, observeUiGraphOutputResizeBounds, revealUiGraphChatElement, revealUiGraphChatSearchMatch, saveUiGraphChatPersistentState, } from './model/UiGraphBrowserRuntime.js';
@@ -16,6 +16,7 @@ import type { Tokenizer } from '../integrations/Tokenizer.js';
16
16
  import { type LooseDataValue } from './looseDataValue.js';
17
17
  import type { ProjectReferenceLoader } from '../model/ProjectReferenceLoader.js';
18
18
  import type { RivetStoredValueStore } from '../model/StoredValueStore.js';
19
+ import type { RivetKnowledgeStoreRegistry } from '../integrations/KnowledgeStore.js';
19
20
  export type RunGraphOptions = {
20
21
  graph?: string;
21
22
  inputs?: Record<string, LooseDataValue>;
@@ -42,6 +43,7 @@ export type RunGraphOptions = {
42
43
  projectReferenceLoader?: ProjectReferenceLoader;
43
44
  editorExecutionCache?: ProcessContext['editorExecutionCache'];
44
45
  storedValueStore?: RivetStoredValueStore;
46
+ knowledgeStores?: RivetKnowledgeStoreRegistry;
45
47
  /** Return root graph outputs before managed async branches settle. */
46
48
  returnWhenGraphOutputsReady?: boolean;
47
49
  } & {
@@ -33,6 +33,10 @@ export * from './model/chat-v2/index.js';
33
33
  export * from './integrations/integrations.js';
34
34
  import './integrations/enableIntegrations.js';
35
35
  export * from './integrations/VectorDatabase.js';
36
+ export * from './integrations/KnowledgeStore.js';
37
+ export * from './integrations/KnowledgeStoreProvider.js';
38
+ export * from './integrations/KnowledgeStoreValidation.js';
39
+ export * from './integrations/ManagedKnowledgeStore.js';
36
40
  export * from './integrations/mcp/MCPProvider.js';
37
41
  export * from './integrations/EmbeddingGenerator.js';
38
42
  export * from './integrations/LLMProvider.js';
@@ -0,0 +1,131 @@
1
+ import type { GraphProgress } from '../model/GraphProgress.js';
2
+ export type KnowledgeStoreConnectionId = string;
3
+ export type KnowledgeMetadataScalar = null | boolean | number | string;
4
+ export type KnowledgeMetadataValue = KnowledgeMetadataScalar | boolean[] | number[] | string[];
5
+ export type KnowledgeMetadata = Record<string, KnowledgeMetadataValue>;
6
+ export type RivetKnowledgeSourceReference = {
7
+ connectionId: KnowledgeStoreConnectionId;
8
+ sourceId: string;
9
+ /** When omitted, operations resolve the source's active committed version. */
10
+ version?: string;
11
+ };
12
+ export type RivetKnowledgeDocument = {
13
+ id?: string;
14
+ text: string;
15
+ title?: string;
16
+ metadata?: KnowledgeMetadata;
17
+ };
18
+ export type RivetKnowledgeEvidence = {
19
+ id: string;
20
+ text: string;
21
+ relevanceScore?: number;
22
+ source: RivetKnowledgeSourceReference;
23
+ documentId: string;
24
+ title?: string;
25
+ chunkIndex?: number;
26
+ metadata?: KnowledgeMetadata;
27
+ };
28
+ export type KnowledgeFilterComparisonOperator = 'eq' | 'neq' | 'in' | 'nin' | 'gt' | 'gte' | 'lt' | 'lte' | 'exists';
29
+ export type KnowledgeFilter = {
30
+ field: string;
31
+ operator: KnowledgeFilterComparisonOperator;
32
+ value?: KnowledgeMetadataValue;
33
+ } | {
34
+ and: KnowledgeFilter[];
35
+ } | {
36
+ or: KnowledgeFilter[];
37
+ } | {
38
+ not: KnowledgeFilter;
39
+ };
40
+ export type RivetKnowledgeStoreCapabilities = {
41
+ supportedFilterOperators?: ReadonlyArray<KnowledgeFilterComparisonOperator>;
42
+ supportsProviderReranking?: boolean;
43
+ supportedExecutors?: ReadonlyArray<'browser' | 'nodejs'>;
44
+ };
45
+ export type KnowledgeOperationContext = {
46
+ signal: AbortSignal;
47
+ reportProgress?: (progress: GraphProgress) => void;
48
+ getTokenCount?: (text: string) => Promise<number>;
49
+ };
50
+ export type KnowledgeChunkingOptions = {
51
+ unit?: 'characters' | 'tokens';
52
+ targetSize?: number;
53
+ overlap?: number;
54
+ minimumBoundarySize?: number;
55
+ includeTitle?: boolean;
56
+ };
57
+ type KnowledgeSourceStatusFields = {
58
+ source: RivetKnowledgeSourceReference;
59
+ documentCount?: number;
60
+ chunkCount?: number;
61
+ updatedAt?: string;
62
+ metadata?: KnowledgeMetadata;
63
+ message: string;
64
+ };
65
+ export type KnowledgeSourceStatus = (KnowledgeSourceStatusFields & {
66
+ exists: true;
67
+ activeVersion: string;
68
+ }) | (KnowledgeSourceStatusFields & {
69
+ exists: false;
70
+ activeVersion?: never;
71
+ });
72
+ export type GetKnowledgeSourceStatusRequest = {
73
+ source: RivetKnowledgeSourceReference;
74
+ expectedVersion?: string;
75
+ };
76
+ export type GetKnowledgeSourceStatusResult = KnowledgeSourceStatus & {
77
+ matchesExpectedVersion?: boolean;
78
+ };
79
+ export type SyncKnowledgeSourceRequest = {
80
+ source: RivetKnowledgeSourceReference;
81
+ documents: RivetKnowledgeDocument[];
82
+ metadata?: KnowledgeMetadata;
83
+ chunking?: KnowledgeChunkingOptions;
84
+ forceRefresh?: boolean;
85
+ };
86
+ export type SyncKnowledgeSourceResult = {
87
+ source: RivetKnowledgeSourceReference & {
88
+ version: string;
89
+ };
90
+ result: 'created' | 'updated' | 'unchanged';
91
+ previousVersion?: string;
92
+ documentCount: number;
93
+ chunkCount: number;
94
+ warnings: string[];
95
+ };
96
+ export type KnowledgeRerankOptions = {
97
+ mode: 'connection-default' | 'required';
98
+ topN?: number;
99
+ };
100
+ export type SearchKnowledgeSourceRequest = {
101
+ source: RivetKnowledgeSourceReference;
102
+ queries: string[];
103
+ topK?: number;
104
+ filter?: KnowledgeFilter;
105
+ rerank?: KnowledgeRerankOptions;
106
+ maxConcurrency?: number;
107
+ finalResultCount?: number;
108
+ };
109
+ export type KnowledgeQueryResult = {
110
+ query: string;
111
+ evidence: RivetKnowledgeEvidence[];
112
+ };
113
+ export type SearchKnowledgeSourceResult = {
114
+ sourceFound: boolean;
115
+ source: RivetKnowledgeSourceReference;
116
+ evidence: RivetKnowledgeEvidence[];
117
+ queryResults: KnowledgeQueryResult[];
118
+ message: string;
119
+ };
120
+ /**
121
+ * High-level, provider-neutral store used by Rivet nodes and programmatic hosts.
122
+ * Implementations own their durable source/version representation.
123
+ */
124
+ export interface RivetKnowledgeStore {
125
+ readonly capabilities: RivetKnowledgeStoreCapabilities;
126
+ getSourceStatus(request: GetKnowledgeSourceStatusRequest, context: KnowledgeOperationContext): Promise<GetKnowledgeSourceStatusResult>;
127
+ syncSource(request: SyncKnowledgeSourceRequest, context: KnowledgeOperationContext): Promise<SyncKnowledgeSourceResult>;
128
+ search(request: SearchKnowledgeSourceRequest, context: KnowledgeOperationContext): Promise<SearchKnowledgeSourceResult>;
129
+ }
130
+ export type RivetKnowledgeStoreRegistry = Record<KnowledgeStoreConnectionId, RivetKnowledgeStore>;
131
+ export {};
@@ -0,0 +1,46 @@
1
+ import type { InternalProcessContext } from '../model/ProcessContext.js';
2
+ import type { KnowledgeStoreConnectionId, RivetKnowledgeStore, RivetKnowledgeStoreRegistry } from './KnowledgeStore.js';
3
+ import type { KnowledgeStoreConnectionDefinition } from '../model/Project.js';
4
+ import type { Settings } from '../model/Settings.js';
5
+ export type KnowledgeStoreProviderConfigField = {
6
+ key: string;
7
+ label: string;
8
+ type: 'string' | 'number' | 'boolean' | 'secret' | 'select';
9
+ description?: string;
10
+ required?: boolean;
11
+ default?: string | number | boolean;
12
+ options?: Array<{
13
+ label: string;
14
+ value: string;
15
+ }>;
16
+ };
17
+ export type KnowledgeStoreProviderDefinition = {
18
+ id: string;
19
+ displayName: string;
20
+ /** Rivet plugin that owns this provider. Defaults to the provider ID. */
21
+ pluginId?: string;
22
+ connectionConfigSpec: KnowledgeStoreProviderConfigField[];
23
+ credentialConfigSpec?: Array<KnowledgeStoreProviderConfigField & {
24
+ type: 'string' | 'secret';
25
+ }>;
26
+ supportedExecutors: Array<'browser' | 'nodejs'>;
27
+ createStore(connectionId: KnowledgeStoreConnectionId, definition: KnowledgeStoreConnectionDefinition, context: KnowledgeStoreProviderContext): RivetKnowledgeStore | Promise<RivetKnowledgeStore>;
28
+ testConnection?(definition: KnowledgeStoreConnectionDefinition, credentials: Record<string, string>, signal: AbortSignal, context: KnowledgeStoreProviderTestContext): void | Promise<void>;
29
+ };
30
+ type KnowledgeStoreResolutionContext = Pick<InternalProcessContext, 'executor' | 'project' | 'settings'>;
31
+ export type KnowledgeStoreProviderContext = KnowledgeStoreResolutionContext & {
32
+ /** Validated local credentials declared by this provider for this connection. */
33
+ credentials: Readonly<Record<string, string>>;
34
+ };
35
+ export type KnowledgeStoreProviderTestContext = {
36
+ settings: Settings;
37
+ };
38
+ export declare function registerKnowledgeStoreProvider(provider: KnowledgeStoreProviderDefinition): void;
39
+ export declare function getKnowledgeStoreProvider(providerId: string): KnowledgeStoreProviderDefinition | undefined;
40
+ export declare function getKnowledgeStoreProviders(): KnowledgeStoreProviderDefinition[];
41
+ export declare class KnowledgeStoreController {
42
+ #private;
43
+ constructor(hostStores: RivetKnowledgeStoreRegistry | undefined);
44
+ resolve(connectionId: KnowledgeStoreConnectionId, context: KnowledgeStoreResolutionContext): Promise<RivetKnowledgeStore>;
45
+ }
46
+ export {};
@@ -0,0 +1,16 @@
1
+ import type { GetKnowledgeSourceStatusResult, KnowledgeFilter, KnowledgeMetadata, RivetKnowledgeDocument, RivetKnowledgeEvidence, RivetKnowledgeSourceReference, SearchKnowledgeSourceResult, SyncKnowledgeSourceResult } from './KnowledgeStore.js';
2
+ export declare function normalizeKnowledgeConnectionId(value: unknown): string;
3
+ export declare function isReservedKnowledgeObjectKey(key: string): boolean;
4
+ export declare function normalizeKnowledgeSourceId(value: unknown): string;
5
+ export declare function normalizeKnowledgeSourceReference(value: unknown): RivetKnowledgeSourceReference;
6
+ export declare function normalizeKnowledgeQueries(value: unknown): string[];
7
+ export declare function normalizeKnowledgeMetadata(value: unknown, label?: string): KnowledgeMetadata;
8
+ export declare function normalizeKnowledgeDocument(value: unknown, index?: number): RivetKnowledgeDocument;
9
+ export declare function normalizeKnowledgeEvidence(value: unknown): RivetKnowledgeEvidence;
10
+ export declare function normalizeKnowledgeSourceStatusResult(value: unknown, expectedSource?: RivetKnowledgeSourceReference, expectedVersion?: string): GetKnowledgeSourceStatusResult;
11
+ export declare function normalizeSyncKnowledgeSourceResult(value: unknown, expectedSource?: RivetKnowledgeSourceReference): SyncKnowledgeSourceResult;
12
+ export declare function normalizeSearchKnowledgeSourceResult(value: unknown, expectedSource?: RivetKnowledgeSourceReference, expectedQueries?: readonly string[]): SearchKnowledgeSourceResult;
13
+ export declare function normalizeKnowledgeFilter(value: unknown): KnowledgeFilter;
14
+ export declare function isKnowledgeSourceReference(value: unknown): value is RivetKnowledgeSourceReference;
15
+ export declare function isKnowledgeDocument(value: unknown): value is RivetKnowledgeDocument;
16
+ export declare function isKnowledgeEvidence(value: unknown): value is RivetKnowledgeEvidence;
@@ -0,0 +1,57 @@
1
+ import type { GetKnowledgeSourceStatusRequest, GetKnowledgeSourceStatusResult, KnowledgeChunkingOptions, KnowledgeFilter, KnowledgeMetadata, KnowledgeOperationContext, RivetKnowledgeDocument, RivetKnowledgeEvidence, RivetKnowledgeStore, RivetKnowledgeStoreCapabilities, SearchKnowledgeSourceRequest, SearchKnowledgeSourceResult, SyncKnowledgeSourceRequest, SyncKnowledgeSourceResult } from './KnowledgeStore.js';
2
+ export type ManagedKnowledgeChunk = {
3
+ id: string;
4
+ text: string;
5
+ documentId: string;
6
+ title?: string;
7
+ chunkIndex: number;
8
+ chunksInDocument: number;
9
+ metadata?: KnowledgeMetadata;
10
+ };
11
+ export type KnowledgeSourceManifest = {
12
+ schemaVersion: string;
13
+ sourceId: string;
14
+ activeVersion: string;
15
+ /** Uniquely identifies one activation, including a force refresh of the same content version. */
16
+ commitId?: string;
17
+ documentCount: number;
18
+ chunkCount: number;
19
+ updatedAt: string;
20
+ metadata?: KnowledgeMetadata;
21
+ };
22
+ export type KnowledgeDriverSearchRequest = {
23
+ sourceId: string;
24
+ version: string;
25
+ query: string;
26
+ topK: number;
27
+ filter?: KnowledgeFilter;
28
+ rerank?: SearchKnowledgeSourceRequest['rerank'];
29
+ };
30
+ export interface ManagedKnowledgeStoreDriver {
31
+ readonly capabilities: RivetKnowledgeStoreCapabilities;
32
+ /**
33
+ * Stable backend scope used to serialize writes to one source across store
34
+ * instances in this JavaScript runtime. Omit it for instance-local locking.
35
+ */
36
+ readonly operationScope?: string;
37
+ getManifest(sourceId: string, context: KnowledgeOperationContext): Promise<KnowledgeSourceManifest | undefined>;
38
+ upsertChunks(sourceId: string, version: string, chunks: ManagedKnowledgeChunk[], context: KnowledgeOperationContext): Promise<void>;
39
+ commitManifest(manifest: KnowledgeSourceManifest, context: KnowledgeOperationContext): Promise<void>;
40
+ search(request: KnowledgeDriverSearchRequest, context: KnowledgeOperationContext): Promise<RivetKnowledgeEvidence[]>;
41
+ deleteVersion(sourceId: string, version: string, context: KnowledgeOperationContext): Promise<void>;
42
+ }
43
+ /**
44
+ * Provides deterministic chunking, immutable version activation, idempotency,
45
+ * same-process source serialization, and multi-query result fusion for drivers.
46
+ */
47
+ export declare class ManagedKnowledgeStore implements RivetKnowledgeStore {
48
+ #private;
49
+ readonly driver: ManagedKnowledgeStoreDriver;
50
+ readonly capabilities: RivetKnowledgeStoreCapabilities;
51
+ constructor(driver: ManagedKnowledgeStoreDriver);
52
+ getSourceStatus(request: GetKnowledgeSourceStatusRequest, context: KnowledgeOperationContext): Promise<GetKnowledgeSourceStatusResult>;
53
+ syncSource(request: SyncKnowledgeSourceRequest, context: KnowledgeOperationContext): Promise<SyncKnowledgeSourceResult>;
54
+ search(request: SearchKnowledgeSourceRequest, context: KnowledgeOperationContext): Promise<SearchKnowledgeSourceResult>;
55
+ }
56
+ export declare function normalizeKnowledgeSourceManifest(value: unknown, expectedSourceId: string): KnowledgeSourceManifest;
57
+ export declare function createSourceVersion(documents: RivetKnowledgeDocument[], metadata: KnowledgeMetadata | undefined, chunking: Required<KnowledgeChunkingOptions>): string;
@@ -1,5 +1,6 @@
1
1
  import type { GraphId } from '../index.js';
2
2
  import type { DataId } from './Project.js';
3
+ import type { RivetKnowledgeDocument, RivetKnowledgeEvidence, RivetKnowledgeSourceReference } from '../integrations/KnowledgeStore.js';
3
4
  export type DataValueDef<Type extends string, RuntimeType> = {
4
5
  type: Type;
5
6
  value: RuntimeType;
@@ -84,6 +85,9 @@ export type GraphReferenceValue = DataValueDef<'graph-reference', {
84
85
  graphId: GraphId;
85
86
  graphName: string;
86
87
  }>;
88
+ export type KnowledgeSourceDataValue = DataValueDef<'knowledge-source', RivetKnowledgeSourceReference>;
89
+ export type KnowledgeDocumentDataValue = DataValueDef<'knowledge-document', RivetKnowledgeDocument>;
90
+ export type KnowledgeEvidenceDataValue = DataValueDef<'knowledge-evidence', RivetKnowledgeEvidence>;
87
91
  export type DocumentDataValue = DataValueDef<'document', {
88
92
  mediaType: SupportedDocumentMediaTypes;
89
93
  data: Uint8Array;
@@ -91,6 +95,7 @@ export type DocumentDataValue = DataValueDef<'document', {
91
95
  context: string | undefined;
92
96
  enableCitations: boolean;
93
97
  }>;
98
+ export type GptFunctionResultHandling = 'continue' | 'return-direct';
94
99
  /** GPT function definition */
95
100
  export type GptFunction = {
96
101
  name: string;
@@ -98,10 +103,12 @@ export type GptFunction = {
98
103
  description: string;
99
104
  parameters: object;
100
105
  strict: boolean;
106
+ /** Rivet-only handling for the function result. This is not sent to the model provider. */
107
+ resultHandling?: GptFunctionResultHandling;
101
108
  };
102
109
  export type GptFunctionDataValue = DataValueDef<'gpt-function', GptFunction>;
103
110
  export type ControlFlowExcludedDataValue = DataValueDef<'control-flow-excluded', undefined | 'loop-not-broken'>;
104
- export type ScalarDataValue = StringDataValue | NumberDataValue | DateDataValue | TimeDataValue | DateTimeDataValue | BoolDataValue | ChatMessageDataValue | ControlFlowExcludedDataValue | AnyDataValue | ObjectDataValue | GptFunctionDataValue | VectorDataValue | ImageDataValue | BinaryDataValue | AudioDataValue | GraphReferenceValue | DocumentDataValue;
111
+ export type ScalarDataValue = StringDataValue | NumberDataValue | DateDataValue | TimeDataValue | DateTimeDataValue | BoolDataValue | ChatMessageDataValue | ControlFlowExcludedDataValue | AnyDataValue | ObjectDataValue | GptFunctionDataValue | VectorDataValue | ImageDataValue | BinaryDataValue | AudioDataValue | GraphReferenceValue | KnowledgeSourceDataValue | KnowledgeDocumentDataValue | KnowledgeEvidenceDataValue | DocumentDataValue;
105
112
  export type ScalarType = ScalarDataValue['type'];
106
113
  export type ArrayDataValue<T extends ScalarDataValue> = DataValueDef<`${T['type']}[]`, T['value'][]>;
107
114
  export type FunctionDataValue<T extends ScalarOrArrayDataValue> = DataValueDef<`fn<${T['type']}>`, () => T['value']>;
@@ -130,8 +137,8 @@ export type GetDataValue<Type extends DataType> = Extract<DataValue, {
130
137
  export type DataRef = {
131
138
  refId: DataId;
132
139
  };
133
- export declare const dataTypes: ["any", "any[]", "boolean", "boolean[]", "string", "string[]", "number", "number[]", "date", "date[]", "time", "time[]", "datetime", "datetime[]", "chat-message", "chat-message[]", "control-flow-excluded", "control-flow-excluded[]", "object", "object[]", "fn<string>", "fn<number>", "fn<boolean>", "fn<date>", "fn<time>", "fn<datetime>", "fn<any>", "fn<object>", "fn<chat-message>", "fn<control-flow-excluded>", "fn<string[]>", "fn<number[]>", "fn<boolean[]>", "fn<date[]>", "fn<time[]>", "fn<datetime[]>", "fn<any[]>", "fn<object[]>", "fn<chat-message[]>", "fn<control-flow-excluded[]>", "gpt-function", "gpt-function[]", "fn<gpt-function[]>", "fn<gpt-function>", "vector", "vector[]", "fn<vector>", "fn<vector[]>", "image", "image[]", "fn<image>", "fn<image[]>", "binary", "binary[]", "fn<binary>", "fn<binary[]>", "audio", "audio[]", "fn<audio>", "fn<audio[]>", "graph-reference", "graph-reference[]", "fn<graph-reference>", "fn<graph-reference[]>", "document", "document[]", "fn<document>", "fn<document[]>"];
134
- export declare const scalarTypes: ["any", "boolean", "string", "number", "date", "time", "datetime", "chat-message", "control-flow-excluded", "object", "gpt-function", "vector", "image", "binary", "audio", "graph-reference", "document"];
140
+ export declare const dataTypes: ["any", "any[]", "boolean", "boolean[]", "string", "string[]", "number", "number[]", "date", "date[]", "time", "time[]", "datetime", "datetime[]", "chat-message", "chat-message[]", "control-flow-excluded", "control-flow-excluded[]", "object", "object[]", "fn<string>", "fn<number>", "fn<boolean>", "fn<date>", "fn<time>", "fn<datetime>", "fn<any>", "fn<object>", "fn<chat-message>", "fn<control-flow-excluded>", "fn<string[]>", "fn<number[]>", "fn<boolean[]>", "fn<date[]>", "fn<time[]>", "fn<datetime[]>", "fn<any[]>", "fn<object[]>", "fn<chat-message[]>", "fn<control-flow-excluded[]>", "gpt-function", "gpt-function[]", "fn<gpt-function[]>", "fn<gpt-function>", "vector", "vector[]", "fn<vector>", "fn<vector[]>", "image", "image[]", "fn<image>", "fn<image[]>", "binary", "binary[]", "fn<binary>", "fn<binary[]>", "audio", "audio[]", "fn<audio>", "fn<audio[]>", "graph-reference", "graph-reference[]", "fn<graph-reference>", "fn<graph-reference[]>", "knowledge-source", "knowledge-source[]", "fn<knowledge-source>", "fn<knowledge-source[]>", "knowledge-document", "knowledge-document[]", "fn<knowledge-document>", "fn<knowledge-document[]>", "knowledge-evidence", "knowledge-evidence[]", "fn<knowledge-evidence>", "fn<knowledge-evidence[]>", "document", "document[]", "fn<document>", "fn<document[]>"];
141
+ export declare const scalarTypes: ["any", "boolean", "string", "number", "date", "time", "datetime", "chat-message", "control-flow-excluded", "object", "gpt-function", "vector", "image", "binary", "audio", "graph-reference", "knowledge-source", "knowledge-document", "knowledge-evidence", "document"];
135
142
  export declare const dataTypeDisplayNames: Record<DataType, string>;
136
143
  export declare function isScalarDataValue(value: DataValue | undefined): value is ScalarDataValue;
137
144
  export declare function isScalarDataType(type: DataType): type is ScalarDataType;
@@ -49,6 +49,12 @@ export type AnyDataEditorDefinition<T extends ChartNode> = SharedEditorDefinitio
49
49
  dataKey: DataOfType<T, any>;
50
50
  useInputToggleDataKey?: DataOfType<T, boolean>;
51
51
  };
52
+ export type JsonObjectEditorDefinition<T extends ChartNode> = SharedEditorDefinitionProps<T> & {
53
+ type: 'jsonObject';
54
+ dataKey: DataOfType<T, Record<string, unknown>>;
55
+ useInputToggleDataKey?: DataOfType<T, boolean>;
56
+ height?: number;
57
+ };
52
58
  export type DropdownEditorDefinition<T extends ChartNode> = SharedEditorDefinitionProps<T> & {
53
59
  type: 'dropdown';
54
60
  dataKey: DataOfType<T, string>;
@@ -183,5 +189,5 @@ export type DynamicEditorDefinition<T extends ChartNode> = SharedEditorDefinitio
183
189
  dataType: DataType;
184
190
  editor: DynamicEditorEditor;
185
191
  };
186
- export type EditorDefinition<T extends ChartNode> = InfoEditorDefinition<T> | StringEditorDefinition<T> | ToggleEditorDefinition<T> | DataTypeSelectorEditorDefinition<T> | AnyDataEditorDefinition<T> | DropdownEditorDefinition<T> | SegmentedEditorDefinition<T> | NumberEditorDefinition<T> | CodeEditorDefinition<T> | GraphSelectorEditorDefinition<T> | ColorEditorDefinition<T> | GraphSelectorEditorDefinition<T> | FileBrowserEditorDefinition<T> | ImageBrowserEditorDefinition<T> | DatasetSelectorEditorDefinition<T> | KeyValuePairEditorDefinition<T> | EditorDefinitionGroup<T> | StringListEditorDefinition<T> | CustomEditorDefinition<T> | DynamicEditorDefinition<T> | FilePathBrowserEditorDefinition<T> | DirectoryBrowserEditorDefinition<T>;
192
+ export type EditorDefinition<T extends ChartNode> = InfoEditorDefinition<T> | StringEditorDefinition<T> | ToggleEditorDefinition<T> | DataTypeSelectorEditorDefinition<T> | AnyDataEditorDefinition<T> | JsonObjectEditorDefinition<T> | DropdownEditorDefinition<T> | SegmentedEditorDefinition<T> | NumberEditorDefinition<T> | CodeEditorDefinition<T> | GraphSelectorEditorDefinition<T> | ColorEditorDefinition<T> | GraphSelectorEditorDefinition<T> | FileBrowserEditorDefinition<T> | ImageBrowserEditorDefinition<T> | DatasetSelectorEditorDefinition<T> | KeyValuePairEditorDefinition<T> | EditorDefinitionGroup<T> | StringListEditorDefinition<T> | CustomEditorDefinition<T> | DynamicEditorDefinition<T> | FilePathBrowserEditorDefinition<T> | DirectoryBrowserEditorDefinition<T>;
187
193
  export {};
@@ -11,6 +11,7 @@ import { type GraphExecutionPlan } from './GraphPreprocessor.js';
11
11
  import { type GraphBoundaryCache } from './GraphBoundaryCache.js';
12
12
  import { type GraphProgress } from './GraphProgress.js';
13
13
  import { type RivetStoredValueStore } from './StoredValueStore.js';
14
+ import type { RivetKnowledgeStoreRegistry } from '../integrations/KnowledgeStore.js';
14
15
  type WithExecution<T extends object> = T & {
15
16
  execution: GraphExecutionMetadata;
16
17
  };
@@ -244,6 +245,7 @@ export declare class GraphProcessor {
244
245
  userInput(nodeId: NodeId, values: StringArrayDataValue): void;
245
246
  setExternalFunction(name: string, fn: ExternalFunction): void;
246
247
  setStoredValueStore(store: RivetStoredValueStore | undefined): void;
248
+ setKnowledgeStores(stores: RivetKnowledgeStoreRegistry | undefined): void;
247
249
  abort(successful?: boolean, error?: Error | string): Promise<void>;
248
250
  pause(): void;
249
251
  resume(): void;