@valerypopoff/rivet2-core 2.4.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/bundle.cjs +1800 -753
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/cjs/interpolationRuntime.cjs +1578 -0
- package/dist/cjs/interpolationRuntime.cjs.map +7 -0
- package/dist/cjs/interpolationSyntax.cjs +186 -0
- package/dist/cjs/interpolationSyntax.cjs.map +7 -0
- package/dist/cjs/webAppRuntime.cjs.map +2 -2
- package/dist/esm/exports.js +2 -1
- package/dist/esm/integrations/CodeRunner.js +5 -0
- package/dist/esm/integrations/mcp/MCPBase.js +16 -6
- package/dist/esm/interpolationRuntime.js +5 -0
- package/dist/esm/model/AgentResponseTrace.js +8 -3
- package/dist/esm/model/GraphBoundaryCache.js +0 -6
- package/dist/esm/model/GraphBoundaryEffects.js +5 -1
- package/dist/esm/model/GraphOutputSelection.js +34 -0
- package/dist/esm/model/GraphProcessor.js +177 -50
- package/dist/esm/model/ProcessContextBuilder.js +4 -1
- package/dist/esm/model/RecordingPlayer.js +46 -14
- package/dist/esm/model/SplitRunProcessor.js +37 -16
- package/dist/esm/model/StoredValueStore.js +4 -3
- package/dist/esm/model/UiGraphRendererStyles.js +20 -0
- package/dist/esm/model/chat/aiSdkStreaming.js +3 -2
- package/dist/esm/model/chat-v2/aiSdkBridge.js +63 -5
- package/dist/esm/model/chat-v2/chatV2Pipeline.js +66 -3
- package/dist/esm/model/chat-v2/llmInvocationResultProjector.js +20 -7
- package/dist/esm/model/chat-v2/llmProfileFallback.js +12 -4
- package/dist/esm/model/nodes/CodeNewNode.js +16 -16
- package/dist/esm/model/nodes/DestructureNode.js +2 -2
- package/dist/esm/model/nodes/ExpressionNode.js +16 -16
- package/dist/esm/model/nodes/ExtractObjectPathNode.js +2 -2
- package/dist/esm/model/nodes/ExtractYamlNode.js +5 -5
- package/dist/esm/model/nodes/JSFilterNode.js +3 -1
- package/dist/esm/model/nodes/JSMapNode.js +3 -1
- package/dist/esm/model/nodes/LLMChatV2Node.js +30 -4
- package/dist/esm/model/nodes/MCPGetPromptNode.js +6 -2
- package/dist/esm/model/nodes/MCPToolCallNode.js +6 -2
- package/dist/esm/model/nodes/ObjectNode.js +19 -20
- package/dist/esm/model/nodes/PromptNode.js +10 -11
- package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +2 -40
- package/dist/esm/model/nodes/SubGraphNode.js +40 -26
- package/dist/esm/model/nodes/TextNode.js +11 -32
- package/dist/esm/model/nodes/ToTreeNode.js +6 -13
- package/dist/esm/model/nodes/ToolNode.js +33 -16
- package/dist/esm/model/nodes/jsListCallbackHelpers.js +19 -15
- package/dist/esm/model/nodes/jsValueInterpolation.js +83 -30
- package/dist/esm/model/nodes/nodeBodyPreview.js +23 -0
- package/dist/esm/plugins/openai/nodes/ThreadMessageNode.js +14 -11
- package/dist/esm/recording/ExecutionRecorder.js +55 -23
- package/dist/esm/utils/index.js +2 -0
- package/dist/esm/utils/interpolation.js +478 -221
- package/dist/esm/utils/interpolationSyntax.js +175 -0
- package/dist/esm/utils/jsonPath.js +129 -0
- package/dist/types/exports.d.ts +3 -1
- package/dist/types/integrations/CodeRunnerOptions.d.ts +9 -0
- package/dist/types/integrations/mcp/MCPBase.d.ts +3 -1
- package/dist/types/interpolationRuntime.d.ts +5 -0
- package/dist/types/model/AgentResponseTrace.d.ts +2 -0
- package/dist/types/model/ExecutorProtocol.d.ts +4 -0
- package/dist/types/model/GraphBoundaryCache.d.ts +0 -2
- package/dist/types/model/GraphOutputSelection.d.ts +8 -0
- package/dist/types/model/GraphProcessor.d.ts +12 -3
- package/dist/types/model/ProcessContext.d.ts +9 -2
- package/dist/types/model/ProcessContextBuilder.d.ts +2 -1
- package/dist/types/model/SplitRunProcessor.d.ts +2 -1
- package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
- package/dist/types/model/chat/aiSdkStreaming.d.ts +1 -1
- package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +1 -1
- package/dist/types/model/chat-v2/chatV2Types.d.ts +29 -0
- package/dist/types/model/chat-v2/llmInvocationResultProjector.d.ts +5 -1
- package/dist/types/model/nodes/ObjectNode.d.ts +1 -1
- package/dist/types/model/nodes/SubGraphNode.d.ts +2 -0
- package/dist/types/model/nodes/ToTreeNode.d.ts +5 -2
- package/dist/types/model/nodes/ToolNode.d.ts +13 -1
- package/dist/types/model/nodes/jsValueInterpolation.d.ts +16 -8
- package/dist/types/model/nodes/nodeBodyPreview.d.ts +7 -0
- package/dist/types/recording/ExecutionRecorder.d.ts +6 -1
- package/dist/types/recording/RecordedEvents.d.ts +2 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/interpolation.d.ts +93 -8
- package/dist/types/utils/interpolationSyntax.d.ts +21 -0
- package/dist/types/utils/jsonPath.d.ts +15 -0
- package/package.json +11 -1
|
@@ -0,0 +1,1578 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/interpolationRuntime.ts
|
|
31
|
+
var interpolationRuntime_exports = {};
|
|
32
|
+
__export(interpolationRuntime_exports, {
|
|
33
|
+
resolveCodeInterpolationExpression: () => resolveCodeInterpolationExpression
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(interpolationRuntime_exports);
|
|
36
|
+
|
|
37
|
+
// src/utils/genericUtilFunctions.ts
|
|
38
|
+
var exhaustiveTuple = () => (
|
|
39
|
+
// impressive inference from TS: it knows when the condition and the true branch can't both be satisfied
|
|
40
|
+
(...x) => x
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
// src/model/chat-v2/chatV2Shared.ts
|
|
44
|
+
function createChatV2CommonNodeData(overrides = {}) {
|
|
45
|
+
return {
|
|
46
|
+
model: "gpt-4o",
|
|
47
|
+
useModelInput: false,
|
|
48
|
+
temperature: 0.5,
|
|
49
|
+
useTemperatureInput: false,
|
|
50
|
+
topP: void 0,
|
|
51
|
+
useTopPInput: false,
|
|
52
|
+
topK: void 0,
|
|
53
|
+
useTopKInput: false,
|
|
54
|
+
presencePenalty: void 0,
|
|
55
|
+
usePresencePenaltyInput: false,
|
|
56
|
+
frequencyPenalty: void 0,
|
|
57
|
+
useFrequencyPenaltyInput: false,
|
|
58
|
+
stopSequences: [],
|
|
59
|
+
useStopSequencesInput: false,
|
|
60
|
+
seed: void 0,
|
|
61
|
+
useSeedInput: false,
|
|
62
|
+
maxTokens: 1024,
|
|
63
|
+
useMaxTokensInput: false,
|
|
64
|
+
useToolCalling: false,
|
|
65
|
+
outputUsage: false,
|
|
66
|
+
outputReasoning: false,
|
|
67
|
+
cache: false,
|
|
68
|
+
useAsGraphPartialOutput: false,
|
|
69
|
+
...overrides
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/model/chat-v2/chatV2Retry.ts
|
|
74
|
+
var DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_REPEAT_TIMES = 1;
|
|
75
|
+
var DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_COOLDOWN_MS = 0;
|
|
76
|
+
|
|
77
|
+
// src/model/chat-v2/llmProfileFieldRegistry.ts
|
|
78
|
+
var llmProfileFieldSpecs = [
|
|
79
|
+
{ key: "model", inputId: "model", valueKind: "string" },
|
|
80
|
+
{ key: "useModelInput", valueKind: "boolean", resolvedInputToggle: true },
|
|
81
|
+
{ key: "temperature", inputId: "temperature", valueKind: "required-number" },
|
|
82
|
+
{ key: "useTemperatureInput", valueKind: "boolean", resolvedInputToggle: true },
|
|
83
|
+
{ key: "topP", inputId: "topP", valueKind: "optional-number" },
|
|
84
|
+
{ key: "useTopPInput", valueKind: "boolean", resolvedInputToggle: true },
|
|
85
|
+
{ key: "topK", inputId: "topK", valueKind: "optional-number" },
|
|
86
|
+
{ key: "useTopKInput", valueKind: "boolean", resolvedInputToggle: true },
|
|
87
|
+
{ key: "presencePenalty", inputId: "presencePenalty", valueKind: "optional-number" },
|
|
88
|
+
{ key: "usePresencePenaltyInput", valueKind: "boolean", resolvedInputToggle: true },
|
|
89
|
+
{ key: "frequencyPenalty", inputId: "frequencyPenalty", valueKind: "optional-number" },
|
|
90
|
+
{ key: "useFrequencyPenaltyInput", valueKind: "boolean", resolvedInputToggle: true },
|
|
91
|
+
{ key: "stopSequences", inputId: "stopSequences" },
|
|
92
|
+
{ key: "useStopSequencesInput", valueKind: "boolean", resolvedInputToggle: true },
|
|
93
|
+
{ key: "seed", inputId: "seed", valueKind: "optional-number" },
|
|
94
|
+
{ key: "useSeedInput", valueKind: "boolean", resolvedInputToggle: true },
|
|
95
|
+
{ key: "maxTokens", inputId: "maxTokens", valueKind: "required-number" },
|
|
96
|
+
{ key: "useMaxTokensInput", valueKind: "boolean", resolvedInputToggle: true },
|
|
97
|
+
{ key: "provider" },
|
|
98
|
+
{ key: "apiKeySource", inputId: "apiKey" },
|
|
99
|
+
{ key: "providerApiKeyNames" },
|
|
100
|
+
{ key: "customProviderApiKeyProgrammaticName", valueKind: "string" },
|
|
101
|
+
{ key: "customProviderApiKeyEnvVarName", valueKind: "string" },
|
|
102
|
+
{ key: "customProviderBaseURL", inputId: "customProviderBaseURL", valueKind: "string" },
|
|
103
|
+
{ key: "useCustomProviderBaseURLInput", valueKind: "boolean", resolvedInputToggle: true },
|
|
104
|
+
{ key: "customProviderApi" },
|
|
105
|
+
{ key: "headers", inputId: "headers" },
|
|
106
|
+
{ key: "useHeadersInput", valueKind: "boolean", resolvedInputToggle: true },
|
|
107
|
+
{ key: "extraProviderOptions", inputId: "extraProviderOptions", valueKind: "string" },
|
|
108
|
+
{ key: "useExtraProviderOptionsInput", valueKind: "boolean", resolvedInputToggle: true },
|
|
109
|
+
{ key: "openAIReasoningEffort", valueKind: "string" },
|
|
110
|
+
{ key: "openAIReasoningSummary", valueKind: "string" },
|
|
111
|
+
{ key: "openAIPreviousResponseId", inputId: "previousResponseId", valueKind: "string" },
|
|
112
|
+
{ key: "useOpenAIPreviousResponseIdInput", valueKind: "boolean", resolvedInputToggle: true },
|
|
113
|
+
{ key: "enableOpenAIWebSearch", valueKind: "boolean" },
|
|
114
|
+
{ key: "openAIWebSearchContextSize" },
|
|
115
|
+
{ key: "enableOpenAICodeInterpreter", valueKind: "boolean" },
|
|
116
|
+
{ key: "anthropicThinkingMode" },
|
|
117
|
+
{ key: "anthropicThinkingBudget", inputId: "anthropicThinkingBudget", valueKind: "optional-number" },
|
|
118
|
+
{ key: "useAnthropicThinkingBudgetInput", valueKind: "boolean", resolvedInputToggle: true },
|
|
119
|
+
{ key: "anthropicEffort" },
|
|
120
|
+
{ key: "anthropicCacheControlTtl" },
|
|
121
|
+
{ key: "googleThinkingBudget", inputId: "googleThinkingBudget", valueKind: "optional-number" },
|
|
122
|
+
{ key: "useGoogleThinkingBudgetInput", valueKind: "boolean", resolvedInputToggle: true },
|
|
123
|
+
{ key: "googleThinkingLevel" },
|
|
124
|
+
{ key: "googleIncludeThoughts", valueKind: "boolean" },
|
|
125
|
+
{ key: "enableGoogleSearchGrounding", valueKind: "boolean" },
|
|
126
|
+
{ key: "enableGoogleUrlContext", valueKind: "boolean" },
|
|
127
|
+
{ key: "enableCircuitBreaker", valueKind: "boolean" },
|
|
128
|
+
{ key: "firstOutputTimeoutMs", valueKind: "required-number" },
|
|
129
|
+
{ key: "streamInactivityTimeoutMs", valueKind: "required-number" },
|
|
130
|
+
{ key: "circuitBreakerFailureThreshold", valueKind: "required-number" },
|
|
131
|
+
{ key: "circuitBreakerFailureWindowMs", valueKind: "required-number" },
|
|
132
|
+
{ key: "circuitBreakerOpenDurationMs", valueKind: "required-number" }
|
|
133
|
+
];
|
|
134
|
+
var llmProfileDataKeys = llmProfileFieldSpecs.map((field) => field.key);
|
|
135
|
+
var llmProfileInputIds = llmProfileFieldSpecs.flatMap((field) => "inputId" in field ? [field.inputId] : []).filter((inputId, index, inputIds) => inputIds.indexOf(inputId) === index);
|
|
136
|
+
function keysForValueKind(valueKind) {
|
|
137
|
+
return llmProfileFieldSpecs.filter((field) => "valueKind" in field && field.valueKind === valueKind).map((field) => field.key);
|
|
138
|
+
}
|
|
139
|
+
var llmProfileStringDataKeys = keysForValueKind("string");
|
|
140
|
+
var llmProfileBooleanDataKeys = keysForValueKind("boolean");
|
|
141
|
+
var llmProfileRequiredNumberDataKeys = keysForValueKind("required-number");
|
|
142
|
+
var llmProfileOptionalNumberDataKeys = keysForValueKind("optional-number");
|
|
143
|
+
var llmProfileResolvedInputToggleDataKeys = llmProfileFieldSpecs.filter((field) => "resolvedInputToggle" in field && field.resolvedInputToggle).map((field) => field.key);
|
|
144
|
+
|
|
145
|
+
// src/model/chat-v2/llmProfileHealthStore.ts
|
|
146
|
+
var import_non_secure = require("nanoid/non-secure");
|
|
147
|
+
var import_crypto_js = __toESM(require("crypto-js"), 1);
|
|
148
|
+
var import_safe_stable_stringify = __toESM(require("safe-stable-stringify"), 1);
|
|
149
|
+
var DEFAULT_LLM_PROFILE_FIRST_OUTPUT_TIMEOUT_MS = 3e4;
|
|
150
|
+
var DEFAULT_LLM_PROFILE_STREAM_INACTIVITY_TIMEOUT_MS = 3e4;
|
|
151
|
+
var DEFAULT_LLM_PROFILE_CIRCUIT_FAILURE_THRESHOLD = 3;
|
|
152
|
+
var DEFAULT_LLM_PROFILE_CIRCUIT_FAILURE_WINDOW_MS = 3e5;
|
|
153
|
+
var DEFAULT_LLM_PROFILE_CIRCUIT_OPEN_DURATION_MS = 3e5;
|
|
154
|
+
var LLM_PROFILE_CLOSED_PERMIT_MIN_RETENTION_MS = 24 * 60 * 60 * 1e3;
|
|
155
|
+
function sha256(value) {
|
|
156
|
+
return `sha256:${import_crypto_js.default.SHA256(value).toString(import_crypto_js.default.enc.Hex)}`;
|
|
157
|
+
}
|
|
158
|
+
function createRivetLLMProfileHealthIdentity(params) {
|
|
159
|
+
var _a;
|
|
160
|
+
const profileName = (_a = params.profileName) == null ? void 0 : _a.trim();
|
|
161
|
+
const routingConfiguration = {
|
|
162
|
+
provider: params.configuration.provider,
|
|
163
|
+
model: params.configuration.model,
|
|
164
|
+
...params.configuration.provider !== "custom" ? {} : {
|
|
165
|
+
customProviderApi: params.configuration.customProviderApi ?? "completions",
|
|
166
|
+
customProviderBaseURL: params.configuration.customProviderBaseURL
|
|
167
|
+
},
|
|
168
|
+
headers: canonicalizeEffectiveRoutingHeaders(params.chatNodeHeaders, params.configuration.headers)
|
|
169
|
+
};
|
|
170
|
+
const serialized = (0, import_safe_stable_stringify.default)({
|
|
171
|
+
routingConfiguration,
|
|
172
|
+
credential: params.credential
|
|
173
|
+
}) ?? "";
|
|
174
|
+
const configurationFingerprint = sha256(serialized);
|
|
175
|
+
const projectId = params.projectId == null ? void 0 : String(params.projectId);
|
|
176
|
+
const profileNodeId = params.profileNodeId == null ? void 0 : String(params.profileNodeId);
|
|
177
|
+
const key = sha256(
|
|
178
|
+
(0, import_safe_stable_stringify.default)({
|
|
179
|
+
kind: "rivet-llm-profile-health",
|
|
180
|
+
projectId,
|
|
181
|
+
profileNodeId,
|
|
182
|
+
configurationFingerprint
|
|
183
|
+
}) ?? ""
|
|
184
|
+
);
|
|
185
|
+
return {
|
|
186
|
+
key: `llm-profile:${key}`,
|
|
187
|
+
...params.projectId == null ? {} : { projectId: params.projectId },
|
|
188
|
+
...params.profileNodeId == null ? {} : { profileNodeId: params.profileNodeId },
|
|
189
|
+
...profileName === "" || profileName == null ? {} : { profileName },
|
|
190
|
+
provider: params.configuration.provider,
|
|
191
|
+
model: params.configuration.model,
|
|
192
|
+
...params.configuration.provider !== "custom" ? {} : { customProviderApi: params.configuration.customProviderApi ?? "completions" },
|
|
193
|
+
configurationFingerprint
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function canonicalizeEffectiveRoutingHeaders(chatNodeHeaders, profileHeaders) {
|
|
197
|
+
const headers = /* @__PURE__ */ new Map();
|
|
198
|
+
for (const [key, value] of Object.entries(chatNodeHeaders ?? {})) {
|
|
199
|
+
const normalizedKey = key.trim().toLowerCase();
|
|
200
|
+
if (normalizedKey) headers.set(normalizedKey, value);
|
|
201
|
+
}
|
|
202
|
+
for (const { key, value } of profileHeaders) {
|
|
203
|
+
const normalizedKey = key.trim().toLowerCase();
|
|
204
|
+
if (normalizedKey) headers.set(normalizedKey, value);
|
|
205
|
+
}
|
|
206
|
+
return [...headers.entries()].sort(([left], [right]) => left.localeCompare(right));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// src/model/chat-v2/llmChatV2NodeData.ts
|
|
210
|
+
var llmChatV2ProfileDataKeys = llmProfileDataKeys;
|
|
211
|
+
function createLLMChatV2NodeData() {
|
|
212
|
+
return {
|
|
213
|
+
...createChatV2CommonNodeData({
|
|
214
|
+
model: "gpt-5"
|
|
215
|
+
}),
|
|
216
|
+
configurationMode: "inline",
|
|
217
|
+
provider: "openai",
|
|
218
|
+
apiKeySource: "environment",
|
|
219
|
+
customProviderApiKeyProgrammaticName: "",
|
|
220
|
+
customProviderApiKeyEnvVarName: "CUSTOM_PROVIDER_API_KEY",
|
|
221
|
+
customProviderBaseURL: "",
|
|
222
|
+
useCustomProviderBaseURLInput: false,
|
|
223
|
+
customProviderApi: "completions",
|
|
224
|
+
baseURL: "",
|
|
225
|
+
useBaseURLInput: false,
|
|
226
|
+
headers: [],
|
|
227
|
+
useHeadersInput: false,
|
|
228
|
+
extraProviderOptions: "",
|
|
229
|
+
useExtraProviderOptionsInput: false,
|
|
230
|
+
openAIReasoningEffort: "",
|
|
231
|
+
openAIReasoningSummary: "",
|
|
232
|
+
openAIPreviousResponseId: "",
|
|
233
|
+
useOpenAIPreviousResponseIdInput: false,
|
|
234
|
+
enableOpenAIWebSearch: false,
|
|
235
|
+
openAIWebSearchContextSize: "medium",
|
|
236
|
+
enableOpenAICodeInterpreter: false,
|
|
237
|
+
anthropicThinkingMode: "",
|
|
238
|
+
anthropicThinkingBudget: void 0,
|
|
239
|
+
useAnthropicThinkingBudgetInput: false,
|
|
240
|
+
anthropicEffort: "",
|
|
241
|
+
anthropicCacheControlTtl: "",
|
|
242
|
+
googleThinkingBudget: void 0,
|
|
243
|
+
useGoogleThinkingBudgetInput: false,
|
|
244
|
+
googleThinkingLevel: "",
|
|
245
|
+
googleIncludeThoughts: false,
|
|
246
|
+
enableGoogleSearchGrounding: false,
|
|
247
|
+
enableGoogleUrlContext: false,
|
|
248
|
+
enableCircuitBreaker: false,
|
|
249
|
+
firstOutputTimeoutMs: DEFAULT_LLM_PROFILE_FIRST_OUTPUT_TIMEOUT_MS,
|
|
250
|
+
streamInactivityTimeoutMs: DEFAULT_LLM_PROFILE_STREAM_INACTIVITY_TIMEOUT_MS,
|
|
251
|
+
circuitBreakerFailureThreshold: DEFAULT_LLM_PROFILE_CIRCUIT_FAILURE_THRESHOLD,
|
|
252
|
+
circuitBreakerFailureWindowMs: DEFAULT_LLM_PROFILE_CIRCUIT_FAILURE_WINDOW_MS,
|
|
253
|
+
circuitBreakerOpenDurationMs: DEFAULT_LLM_PROFILE_CIRCUIT_OPEN_DURATION_MS,
|
|
254
|
+
responseFormat: "",
|
|
255
|
+
responseSchemaName: "",
|
|
256
|
+
useResponseSchemaNameInput: false,
|
|
257
|
+
responseSchemaDescription: "",
|
|
258
|
+
useResponseSchemaDescriptionInput: false,
|
|
259
|
+
toolChoice: "",
|
|
260
|
+
toolChoiceFunction: "",
|
|
261
|
+
parallelToolCalls: false,
|
|
262
|
+
autoContinueToolCalls: false,
|
|
263
|
+
maxToolRounds: 3,
|
|
264
|
+
retryOnNon200: false,
|
|
265
|
+
retryOnNon200RepeatTimes: DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_REPEAT_TIMES,
|
|
266
|
+
retryOnNon200CooldownMs: DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_COOLDOWN_MS,
|
|
267
|
+
outputLLMAttempts: false,
|
|
268
|
+
outputRequestBody: false,
|
|
269
|
+
outputResponseBody: false
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// src/model/chat-v2/llmProfileTypes.ts
|
|
274
|
+
var LLM_PROFILE_VALUE_VERSION = 1;
|
|
275
|
+
function createLLMProfileNodeData() {
|
|
276
|
+
return pickLLMChatV2ProfileData(createLLMChatV2NodeData());
|
|
277
|
+
}
|
|
278
|
+
function createDefaultLLMProfileValue() {
|
|
279
|
+
return {
|
|
280
|
+
version: LLM_PROFILE_VALUE_VERSION,
|
|
281
|
+
configuration: createLLMProfileNodeData(),
|
|
282
|
+
credential: { reference: { source: "none" } }
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
function pickLLMChatV2ProfileData(data) {
|
|
286
|
+
return Object.fromEntries(llmChatV2ProfileDataKeys.map((key) => [key, data[key]]));
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// src/model/DataValue.ts
|
|
290
|
+
var dataTypes = exhaustiveTuple()(
|
|
291
|
+
"any",
|
|
292
|
+
"any[]",
|
|
293
|
+
"boolean",
|
|
294
|
+
"boolean[]",
|
|
295
|
+
"string",
|
|
296
|
+
"string[]",
|
|
297
|
+
"number",
|
|
298
|
+
"number[]",
|
|
299
|
+
"date",
|
|
300
|
+
"date[]",
|
|
301
|
+
"time",
|
|
302
|
+
"time[]",
|
|
303
|
+
"datetime",
|
|
304
|
+
"datetime[]",
|
|
305
|
+
"chat-message",
|
|
306
|
+
"chat-message[]",
|
|
307
|
+
"control-flow-excluded",
|
|
308
|
+
"control-flow-excluded[]",
|
|
309
|
+
"object",
|
|
310
|
+
"object[]",
|
|
311
|
+
"fn<string>",
|
|
312
|
+
"fn<number>",
|
|
313
|
+
"fn<boolean>",
|
|
314
|
+
"fn<date>",
|
|
315
|
+
"fn<time>",
|
|
316
|
+
"fn<datetime>",
|
|
317
|
+
"fn<any>",
|
|
318
|
+
"fn<object>",
|
|
319
|
+
"fn<chat-message>",
|
|
320
|
+
"fn<control-flow-excluded>",
|
|
321
|
+
"fn<string[]>",
|
|
322
|
+
"fn<number[]>",
|
|
323
|
+
"fn<boolean[]>",
|
|
324
|
+
"fn<date[]>",
|
|
325
|
+
"fn<time[]>",
|
|
326
|
+
"fn<datetime[]>",
|
|
327
|
+
"fn<any[]>",
|
|
328
|
+
"fn<object[]>",
|
|
329
|
+
"fn<chat-message[]>",
|
|
330
|
+
"fn<control-flow-excluded[]>",
|
|
331
|
+
"gpt-function",
|
|
332
|
+
"gpt-function[]",
|
|
333
|
+
"fn<gpt-function[]>",
|
|
334
|
+
"fn<gpt-function>",
|
|
335
|
+
"vector",
|
|
336
|
+
"vector[]",
|
|
337
|
+
"fn<vector>",
|
|
338
|
+
"fn<vector[]>",
|
|
339
|
+
"image",
|
|
340
|
+
"image[]",
|
|
341
|
+
"fn<image>",
|
|
342
|
+
"fn<image[]>",
|
|
343
|
+
"binary",
|
|
344
|
+
"binary[]",
|
|
345
|
+
"fn<binary>",
|
|
346
|
+
"fn<binary[]>",
|
|
347
|
+
"audio",
|
|
348
|
+
"audio[]",
|
|
349
|
+
"fn<audio>",
|
|
350
|
+
"fn<audio[]>",
|
|
351
|
+
"graph-reference",
|
|
352
|
+
"graph-reference[]",
|
|
353
|
+
"fn<graph-reference>",
|
|
354
|
+
"fn<graph-reference[]>",
|
|
355
|
+
"knowledge-source",
|
|
356
|
+
"knowledge-source[]",
|
|
357
|
+
"fn<knowledge-source>",
|
|
358
|
+
"fn<knowledge-source[]>",
|
|
359
|
+
"knowledge-document",
|
|
360
|
+
"knowledge-document[]",
|
|
361
|
+
"fn<knowledge-document>",
|
|
362
|
+
"fn<knowledge-document[]>",
|
|
363
|
+
"knowledge-evidence",
|
|
364
|
+
"knowledge-evidence[]",
|
|
365
|
+
"fn<knowledge-evidence>",
|
|
366
|
+
"fn<knowledge-evidence[]>",
|
|
367
|
+
"llm-config",
|
|
368
|
+
"llm-config[]",
|
|
369
|
+
"fn<llm-config>",
|
|
370
|
+
"fn<llm-config[]>",
|
|
371
|
+
"document",
|
|
372
|
+
"document[]",
|
|
373
|
+
"fn<document>",
|
|
374
|
+
"fn<document[]>"
|
|
375
|
+
);
|
|
376
|
+
var scalarTypes = exhaustiveTuple()(
|
|
377
|
+
"any",
|
|
378
|
+
"boolean",
|
|
379
|
+
"string",
|
|
380
|
+
"number",
|
|
381
|
+
"date",
|
|
382
|
+
"time",
|
|
383
|
+
"datetime",
|
|
384
|
+
"chat-message",
|
|
385
|
+
"control-flow-excluded",
|
|
386
|
+
"object",
|
|
387
|
+
"gpt-function",
|
|
388
|
+
"vector",
|
|
389
|
+
"image",
|
|
390
|
+
"binary",
|
|
391
|
+
"audio",
|
|
392
|
+
"graph-reference",
|
|
393
|
+
"knowledge-source",
|
|
394
|
+
"knowledge-document",
|
|
395
|
+
"knowledge-evidence",
|
|
396
|
+
"llm-config",
|
|
397
|
+
"document"
|
|
398
|
+
);
|
|
399
|
+
function isScalarDataValue(value) {
|
|
400
|
+
if (!value) {
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
403
|
+
return !isArrayDataType(value.type) && !isFunctionDataType(value.type);
|
|
404
|
+
}
|
|
405
|
+
function isScalarDataType(type) {
|
|
406
|
+
return !isArrayDataType(type) && !isFunctionDataType(type);
|
|
407
|
+
}
|
|
408
|
+
function isArrayDataValue(value) {
|
|
409
|
+
if (!value) {
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
return isArrayDataType(value.type) || (value.type === "any" || value.type === "object") && Array.isArray(value.value);
|
|
413
|
+
}
|
|
414
|
+
function isArrayDataType(type) {
|
|
415
|
+
return type.endsWith("[]");
|
|
416
|
+
}
|
|
417
|
+
function isFunctionDataType(type) {
|
|
418
|
+
return type.startsWith("fn<");
|
|
419
|
+
}
|
|
420
|
+
function isFunctionDataValue(value) {
|
|
421
|
+
if (!value) {
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
return isFunctionDataType(value.type) || value.type === "any" && typeof value.value === "function";
|
|
425
|
+
}
|
|
426
|
+
function functionTypeToReturnType(functionType) {
|
|
427
|
+
return functionType.slice(3, -1);
|
|
428
|
+
}
|
|
429
|
+
function functionTypeToScalarType(functionType) {
|
|
430
|
+
const returnType = functionTypeToReturnType(functionType);
|
|
431
|
+
return isArrayDataType(returnType) ? arrayTypeToScalarType(returnType) : returnType;
|
|
432
|
+
}
|
|
433
|
+
function arrayTypeToScalarType(arrayType) {
|
|
434
|
+
return arrayType.slice(0, -2);
|
|
435
|
+
}
|
|
436
|
+
function getScalarTypeOf(type) {
|
|
437
|
+
if (isArrayDataType(type)) {
|
|
438
|
+
return arrayTypeToScalarType(type);
|
|
439
|
+
}
|
|
440
|
+
if (isFunctionDataType(type)) {
|
|
441
|
+
return functionTypeToScalarType(type);
|
|
442
|
+
}
|
|
443
|
+
return type;
|
|
444
|
+
}
|
|
445
|
+
function unwrapDataValue(value) {
|
|
446
|
+
if (!value) {
|
|
447
|
+
return void 0;
|
|
448
|
+
}
|
|
449
|
+
if (isFunctionDataValue(value)) {
|
|
450
|
+
const evaluated = value.value();
|
|
451
|
+
if (value.type === "any") {
|
|
452
|
+
return { type: "any", value: evaluated };
|
|
453
|
+
}
|
|
454
|
+
return { type: functionTypeToReturnType(value.type), value: evaluated };
|
|
455
|
+
}
|
|
456
|
+
return value;
|
|
457
|
+
}
|
|
458
|
+
var scalarDefaults = {
|
|
459
|
+
string: "",
|
|
460
|
+
number: 0,
|
|
461
|
+
boolean: false,
|
|
462
|
+
any: void 0,
|
|
463
|
+
"chat-message": {
|
|
464
|
+
type: "user",
|
|
465
|
+
message: "",
|
|
466
|
+
isCacheBreakpoint: void 0
|
|
467
|
+
},
|
|
468
|
+
"control-flow-excluded": void 0,
|
|
469
|
+
date: (/* @__PURE__ */ new Date()).toISOString(),
|
|
470
|
+
time: (/* @__PURE__ */ new Date()).toISOString(),
|
|
471
|
+
datetime: (/* @__PURE__ */ new Date()).toISOString(),
|
|
472
|
+
object: {},
|
|
473
|
+
"gpt-function": {
|
|
474
|
+
name: "unknown",
|
|
475
|
+
description: "",
|
|
476
|
+
parameters: {},
|
|
477
|
+
namespace: void 0,
|
|
478
|
+
strict: false
|
|
479
|
+
},
|
|
480
|
+
vector: [],
|
|
481
|
+
image: {
|
|
482
|
+
mediaType: "image/jpeg",
|
|
483
|
+
data: new Uint8Array()
|
|
484
|
+
},
|
|
485
|
+
binary: new Uint8Array(),
|
|
486
|
+
audio: { data: new Uint8Array() },
|
|
487
|
+
"graph-reference": { graphId: "", graphName: "" },
|
|
488
|
+
"knowledge-source": { connectionId: "", sourceId: "" },
|
|
489
|
+
"knowledge-document": { text: "" },
|
|
490
|
+
"knowledge-evidence": {
|
|
491
|
+
id: "",
|
|
492
|
+
text: "",
|
|
493
|
+
source: { connectionId: "", sourceId: "" },
|
|
494
|
+
documentId: ""
|
|
495
|
+
},
|
|
496
|
+
"llm-config": createDefaultLLMProfileValue(),
|
|
497
|
+
document: {
|
|
498
|
+
mediaType: "text/plain",
|
|
499
|
+
data: new Uint8Array(),
|
|
500
|
+
title: void 0,
|
|
501
|
+
context: void 0,
|
|
502
|
+
enableCitations: false
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
// src/utils/expectType.ts
|
|
507
|
+
function getDeferredValue(value, type) {
|
|
508
|
+
const targetReturnType = functionTypeToReturnType(type);
|
|
509
|
+
if (isFunctionDataType(value.type)) {
|
|
510
|
+
const sourceReturnType = functionTypeToReturnType(value.type);
|
|
511
|
+
return targetReturnType === "any" || sourceReturnType === "any" || sourceReturnType === targetReturnType ? value.value : void 0;
|
|
512
|
+
}
|
|
513
|
+
if (value.type === "any" && typeof value.value === "function") {
|
|
514
|
+
return value.value;
|
|
515
|
+
}
|
|
516
|
+
if (targetReturnType === "any" || value.type === "any" || value.type === targetReturnType) {
|
|
517
|
+
return () => value.value;
|
|
518
|
+
}
|
|
519
|
+
return void 0;
|
|
520
|
+
}
|
|
521
|
+
function expectTypeOptional(value, type) {
|
|
522
|
+
if (value === void 0) {
|
|
523
|
+
return void 0;
|
|
524
|
+
}
|
|
525
|
+
if (isArrayDataType(type) && isArrayDataValue(value) && getScalarTypeOf(type) === getScalarTypeOf(value.type)) {
|
|
526
|
+
return value.value;
|
|
527
|
+
}
|
|
528
|
+
if (isArrayDataType(type) && isScalarDataValue(value) && getScalarTypeOf(type) === value.type) {
|
|
529
|
+
return [value.value];
|
|
530
|
+
}
|
|
531
|
+
if (value.type === type) {
|
|
532
|
+
return value.value;
|
|
533
|
+
}
|
|
534
|
+
if (isFunctionDataType(type)) {
|
|
535
|
+
const deferredValue = getDeferredValue(value, type);
|
|
536
|
+
if (deferredValue) {
|
|
537
|
+
return deferredValue;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
if (isFunctionDataType(value.type) && value.type === `fn<${type}>`) {
|
|
541
|
+
value = unwrapDataValue(value);
|
|
542
|
+
}
|
|
543
|
+
if (value.type !== type) {
|
|
544
|
+
throw new Error(`Expected value of type ${type} but got ${value == null ? void 0 : value.type}`);
|
|
545
|
+
}
|
|
546
|
+
return value.value;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// src/integrations/KnowledgeStoreValidation.ts
|
|
550
|
+
function normalizeKnowledgeConnectionId(value) {
|
|
551
|
+
const id = typeof value === "string" ? value.trim() : "";
|
|
552
|
+
if (!id) throw new Error("Knowledge store connection ID cannot be empty.");
|
|
553
|
+
if (id.length > 256) throw new Error("Knowledge store connection ID cannot exceed 256 characters.");
|
|
554
|
+
if (isReservedKnowledgeObjectKey(id)) {
|
|
555
|
+
throw new Error(`Knowledge store connection ID "${id}" is reserved.`);
|
|
556
|
+
}
|
|
557
|
+
return id;
|
|
558
|
+
}
|
|
559
|
+
function isReservedKnowledgeObjectKey(key) {
|
|
560
|
+
return key === "__proto__" || key === "prototype" || key === "constructor";
|
|
561
|
+
}
|
|
562
|
+
function normalizeKnowledgeSourceId(value) {
|
|
563
|
+
const id = typeof value === "string" ? value.trim() : "";
|
|
564
|
+
if (!id) throw new Error("Knowledge source ID cannot be empty.");
|
|
565
|
+
if (id.length > 512) throw new Error("Knowledge source ID cannot exceed 512 characters.");
|
|
566
|
+
return id;
|
|
567
|
+
}
|
|
568
|
+
function normalizeKnowledgeSourceReference(value) {
|
|
569
|
+
if (!isRecord(value)) throw new Error("Knowledge Source must be an object.");
|
|
570
|
+
const connectionId = normalizeKnowledgeConnectionId(value.connectionId);
|
|
571
|
+
const sourceId = normalizeKnowledgeSourceId(value.sourceId);
|
|
572
|
+
const version = normalizeKnowledgeVersion(value.version, "Knowledge source version");
|
|
573
|
+
return { connectionId, sourceId, ...version ? { version } : {} };
|
|
574
|
+
}
|
|
575
|
+
function normalizeKnowledgeMetadata(value, label = "Knowledge metadata") {
|
|
576
|
+
if (value == null) return {};
|
|
577
|
+
if (!isRecord(value)) throw new Error(`${label} must be a plain object.`);
|
|
578
|
+
const normalized = {};
|
|
579
|
+
for (const [rawKey, rawValue] of Object.entries(value)) {
|
|
580
|
+
const key = rawKey.trim();
|
|
581
|
+
if (!key) throw new Error(`${label} contains an empty field name.`);
|
|
582
|
+
rejectUnsafeObjectKey(key, label);
|
|
583
|
+
if (Object.prototype.hasOwnProperty.call(normalized, key)) {
|
|
584
|
+
throw new Error(`${label} contains duplicate field "${key}" after trimming.`);
|
|
585
|
+
}
|
|
586
|
+
normalized[key] = normalizeKnowledgeMetadataValue(rawValue, `${label}.${key}`);
|
|
587
|
+
}
|
|
588
|
+
return normalized;
|
|
589
|
+
}
|
|
590
|
+
function normalizeKnowledgeDocument(value, index) {
|
|
591
|
+
const label = index == null ? "Knowledge document" : `Knowledge document ${index + 1}`;
|
|
592
|
+
if (typeof value === "string") {
|
|
593
|
+
const text2 = normalizeDocumentText(value);
|
|
594
|
+
if (!text2) throw new Error(`${label} text cannot be empty.`);
|
|
595
|
+
return { text: text2 };
|
|
596
|
+
}
|
|
597
|
+
if (!isRecord(value)) throw new Error(`${label} must be a string or object.`);
|
|
598
|
+
const text = normalizeDocumentText(value.text);
|
|
599
|
+
if (!text) throw new Error(`${label} text cannot be empty.`);
|
|
600
|
+
const id = optionalTrimmedString(value.id, `${label} ID`) ?? "";
|
|
601
|
+
const title = optionalTrimmedString(value.title, `${label} title`) ?? "";
|
|
602
|
+
const metadata = value.metadata == null ? void 0 : normalizeKnowledgeMetadata(value.metadata, `${label} metadata`);
|
|
603
|
+
return {
|
|
604
|
+
...id ? { id } : {},
|
|
605
|
+
text,
|
|
606
|
+
...title ? { title } : {},
|
|
607
|
+
...metadata && Object.keys(metadata).length > 0 ? { metadata } : {}
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
function normalizeKnowledgeEvidence(value) {
|
|
611
|
+
if (!isRecord(value)) throw new Error("Knowledge Evidence must be an object.");
|
|
612
|
+
const id = typeof value.id === "string" ? value.id.trim() : "";
|
|
613
|
+
const text = normalizeDocumentText(value.text);
|
|
614
|
+
const documentId = typeof value.documentId === "string" ? value.documentId.trim() : "";
|
|
615
|
+
if (!id || !text || !documentId) {
|
|
616
|
+
throw new Error("Knowledge Evidence requires non-empty id, text, and documentId fields.");
|
|
617
|
+
}
|
|
618
|
+
const score = optionalFiniteNumber(value.relevanceScore, "Knowledge Evidence relevance score");
|
|
619
|
+
const title = optionalTrimmedString(value.title, "Knowledge Evidence title") ?? "";
|
|
620
|
+
const chunkIndex = optionalNonNegativeInteger(value.chunkIndex, "Knowledge Evidence chunk index");
|
|
621
|
+
return {
|
|
622
|
+
id,
|
|
623
|
+
text,
|
|
624
|
+
source: normalizeKnowledgeSourceReference(value.source),
|
|
625
|
+
documentId,
|
|
626
|
+
...score == null ? {} : { relevanceScore: score },
|
|
627
|
+
...title ? { title } : {},
|
|
628
|
+
...chunkIndex == null ? {} : { chunkIndex },
|
|
629
|
+
...value.metadata == null ? {} : { metadata: normalizeKnowledgeMetadata(value.metadata) }
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
function normalizeKnowledgeMetadataValue(value, label) {
|
|
633
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
634
|
+
if (typeof value === "number") {
|
|
635
|
+
if (!Number.isFinite(value)) throw new Error(`${label} must be a finite number.`);
|
|
636
|
+
return value;
|
|
637
|
+
}
|
|
638
|
+
if (Array.isArray(value)) {
|
|
639
|
+
if (value.every((item) => typeof item === "string")) return value;
|
|
640
|
+
if (value.every((item) => typeof item === "boolean")) return value;
|
|
641
|
+
if (value.every((item) => typeof item === "number" && Number.isFinite(item))) return value;
|
|
642
|
+
throw new Error(`${label} arrays must contain only strings, booleans, or finite numbers of one type.`);
|
|
643
|
+
}
|
|
644
|
+
throw new Error(`${label} must be a portable scalar or a homogeneous scalar array.`);
|
|
645
|
+
}
|
|
646
|
+
function normalizeDocumentText(value) {
|
|
647
|
+
return typeof value === "string" ? value.replace(/\r\n?/g, "\n").trim() : "";
|
|
648
|
+
}
|
|
649
|
+
function optionalTrimmedString(value, label) {
|
|
650
|
+
if (value == null || value === "") return void 0;
|
|
651
|
+
if (typeof value !== "string") throw new Error(`${label} must be a string.`);
|
|
652
|
+
const normalized = value.trim();
|
|
653
|
+
return normalized || void 0;
|
|
654
|
+
}
|
|
655
|
+
function normalizeKnowledgeVersion(value, label) {
|
|
656
|
+
const version = optionalTrimmedString(value, label);
|
|
657
|
+
if (version && version.length > 512) throw new Error(`${label} cannot exceed 512 characters.`);
|
|
658
|
+
return version;
|
|
659
|
+
}
|
|
660
|
+
function optionalFiniteNumber(value, label) {
|
|
661
|
+
if (value == null) return void 0;
|
|
662
|
+
if (typeof value !== "number" || !Number.isFinite(value)) throw new Error(`${label} must be a finite number.`);
|
|
663
|
+
return value;
|
|
664
|
+
}
|
|
665
|
+
function optionalNonNegativeInteger(value, label) {
|
|
666
|
+
if (value == null) return void 0;
|
|
667
|
+
if (!Number.isInteger(value) || value < 0) throw new Error(`${label} must be a non-negative integer.`);
|
|
668
|
+
return value;
|
|
669
|
+
}
|
|
670
|
+
function rejectUnsafeObjectKey(key, label) {
|
|
671
|
+
if (isReservedKnowledgeObjectKey(key)) {
|
|
672
|
+
throw new Error(`${label} field "${key}" is reserved.`);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
function isRecord(value) {
|
|
676
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
677
|
+
const prototype = Object.getPrototypeOf(value);
|
|
678
|
+
return prototype === Object.prototype || prototype === null;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// src/model/chat-v2/customProviderApi.ts
|
|
682
|
+
function parseCustomProviderApi(value) {
|
|
683
|
+
switch (value) {
|
|
684
|
+
case void 0:
|
|
685
|
+
case "completions":
|
|
686
|
+
return "completions";
|
|
687
|
+
case "responses":
|
|
688
|
+
return "responses";
|
|
689
|
+
default:
|
|
690
|
+
throw new Error(`Unsupported Custom provider API: ${String(value)}.`);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
// src/model/chat-v2/chatV2CredentialNames.ts
|
|
695
|
+
var CHAT_V2_DEFAULT_CREDENTIAL_NAMES = {
|
|
696
|
+
openai: {
|
|
697
|
+
programmaticName: "openAiApiKey",
|
|
698
|
+
environmentVariableName: "OPENAI_API_KEY"
|
|
699
|
+
},
|
|
700
|
+
anthropic: {
|
|
701
|
+
programmaticName: "anthropicApiKey",
|
|
702
|
+
environmentVariableName: "ANTHROPIC_API_KEY"
|
|
703
|
+
},
|
|
704
|
+
google: {
|
|
705
|
+
programmaticName: "googleApiKey",
|
|
706
|
+
environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY"
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
var programmaticNamePattern = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
710
|
+
var environmentVariableNamePattern = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
711
|
+
function isValidChatV2ProgrammaticCredentialName(name) {
|
|
712
|
+
return programmaticNamePattern.test(name);
|
|
713
|
+
}
|
|
714
|
+
function isValidChatV2EnvironmentCredentialName(name) {
|
|
715
|
+
return environmentVariableNamePattern.test(name);
|
|
716
|
+
}
|
|
717
|
+
function normalizeChatV2CredentialNames(provider, value) {
|
|
718
|
+
var _a, _b;
|
|
719
|
+
if (value != null && (typeof value !== "object" || Array.isArray(value))) {
|
|
720
|
+
throw new Error(`${provider} API key names must be an object.`);
|
|
721
|
+
}
|
|
722
|
+
const raw = value;
|
|
723
|
+
if ((raw == null ? void 0 : raw.programmaticName) != null && typeof raw.programmaticName !== "string") {
|
|
724
|
+
throw new Error(`${provider} programmatic API key name must be a string.`);
|
|
725
|
+
}
|
|
726
|
+
if ((raw == null ? void 0 : raw.environmentVariableName) != null && typeof raw.environmentVariableName !== "string") {
|
|
727
|
+
throw new Error(`${provider} API key environment variable must be a string.`);
|
|
728
|
+
}
|
|
729
|
+
const defaults = CHAT_V2_DEFAULT_CREDENTIAL_NAMES[provider];
|
|
730
|
+
const programmaticName = ((_a = raw == null ? void 0 : raw.programmaticName) == null ? void 0 : _a.trim()) || defaults.programmaticName;
|
|
731
|
+
const environmentVariableName = ((_b = raw == null ? void 0 : raw.environmentVariableName) == null ? void 0 : _b.trim()) || defaults.environmentVariableName;
|
|
732
|
+
if (!isValidChatV2ProgrammaticCredentialName(programmaticName)) {
|
|
733
|
+
throw new Error(
|
|
734
|
+
`${provider} programmatic API key name must be a JavaScript-style identifier (letters, digits, _, or $, and not starting with a digit).`
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
if (!isValidChatV2EnvironmentCredentialName(environmentVariableName)) {
|
|
738
|
+
throw new Error(
|
|
739
|
+
`${provider} API key environment variable must contain only letters, digits, and _, and must not start with a digit.`
|
|
740
|
+
);
|
|
741
|
+
}
|
|
742
|
+
return { programmaticName, environmentVariableName };
|
|
743
|
+
}
|
|
744
|
+
function normalizeChatV2CredentialNamesByProvider(value) {
|
|
745
|
+
if (value == null) return void 0;
|
|
746
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
747
|
+
throw new Error("Built-in provider API key names must be an object.");
|
|
748
|
+
}
|
|
749
|
+
const raw = value;
|
|
750
|
+
const unsupportedProvider = Object.keys(raw).find(
|
|
751
|
+
(provider) => !Object.hasOwn(CHAT_V2_DEFAULT_CREDENTIAL_NAMES, provider)
|
|
752
|
+
);
|
|
753
|
+
if (unsupportedProvider) {
|
|
754
|
+
throw new Error(`Unsupported provider API key names entry: ${unsupportedProvider}.`);
|
|
755
|
+
}
|
|
756
|
+
const normalized = {};
|
|
757
|
+
for (const provider of ["openai", "anthropic", "google"]) {
|
|
758
|
+
if (raw[provider] != null) {
|
|
759
|
+
normalized[provider] = normalizeChatV2CredentialNames(provider, raw[provider]);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
return Object.keys(normalized).length === 0 ? void 0 : normalized;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
// src/model/chat-v2/llmProfile.ts
|
|
766
|
+
var credentialSources = /* @__PURE__ */ new Set([
|
|
767
|
+
"input",
|
|
768
|
+
"settings",
|
|
769
|
+
"plugin",
|
|
770
|
+
"programmatic",
|
|
771
|
+
"environment",
|
|
772
|
+
"none"
|
|
773
|
+
]);
|
|
774
|
+
var profileProviders = /* @__PURE__ */ new Set(["openai", "anthropic", "google", "custom"]);
|
|
775
|
+
function normalizeLLMProfileValue(value) {
|
|
776
|
+
if (!isRecord2(value)) {
|
|
777
|
+
throw new Error("LLM Profile input must contain an LLM profile value.");
|
|
778
|
+
}
|
|
779
|
+
if (value.version !== LLM_PROFILE_VALUE_VERSION) {
|
|
780
|
+
throw new Error(`Unsupported LLM Profile version: ${String(value.version)}.`);
|
|
781
|
+
}
|
|
782
|
+
if (!isRecord2(value.configuration)) {
|
|
783
|
+
throw new Error("LLM Profile configuration is missing.");
|
|
784
|
+
}
|
|
785
|
+
const defaults = createLLMChatV2NodeData();
|
|
786
|
+
const provider = normalizeProvider(value.configuration.provider ?? defaults.provider);
|
|
787
|
+
const model = value.configuration.model;
|
|
788
|
+
if (typeof model !== "string" || !model.trim()) {
|
|
789
|
+
throw new Error("LLM Profile model must be a non-empty string.");
|
|
790
|
+
}
|
|
791
|
+
const credential = normalizeCredential(value.credential);
|
|
792
|
+
const configuration = normalizeConfiguration({
|
|
793
|
+
...defaults,
|
|
794
|
+
...value.configuration,
|
|
795
|
+
provider,
|
|
796
|
+
model: model.trim()
|
|
797
|
+
});
|
|
798
|
+
const sourceIdentity = normalizeSourceIdentity(value.healthIdentity);
|
|
799
|
+
const profileName = normalizeProfileName(value.profileName) ?? sourceIdentity.profileName;
|
|
800
|
+
return {
|
|
801
|
+
version: LLM_PROFILE_VALUE_VERSION,
|
|
802
|
+
configuration,
|
|
803
|
+
credential,
|
|
804
|
+
...profileName == null ? {} : { profileName },
|
|
805
|
+
healthIdentity: createRivetLLMProfileHealthIdentity({
|
|
806
|
+
configuration,
|
|
807
|
+
credential,
|
|
808
|
+
...sourceIdentity,
|
|
809
|
+
...profileName == null ? {} : { profileName }
|
|
810
|
+
})
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
function normalizeConfiguration(data) {
|
|
814
|
+
var _a, _b;
|
|
815
|
+
for (const field of llmProfileStringDataKeys) {
|
|
816
|
+
if (typeof data[field] !== "string") {
|
|
817
|
+
throw new Error(`LLM Profile ${field} must be a string.`);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
for (const field of llmProfileBooleanDataKeys) {
|
|
821
|
+
if (typeof data[field] !== "boolean") {
|
|
822
|
+
throw new Error(`LLM Profile ${field} must be a boolean.`);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
for (const field of llmProfileRequiredNumberDataKeys) {
|
|
826
|
+
if (typeof data[field] !== "number" || !Number.isFinite(data[field])) {
|
|
827
|
+
throw new Error(`LLM Profile ${field} must be a finite number.`);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
for (const field of llmProfileOptionalNumberDataKeys) {
|
|
831
|
+
const fieldValue = data[field];
|
|
832
|
+
if (fieldValue != null && (typeof fieldValue !== "number" || !Number.isFinite(fieldValue))) {
|
|
833
|
+
throw new Error(`LLM Profile ${field} must be a finite number when provided.`);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
if (!Array.isArray(data.stopSequences) || data.stopSequences.some((sequence) => typeof sequence !== "string")) {
|
|
837
|
+
throw new Error("LLM Profile stopSequences must be an array of strings.");
|
|
838
|
+
}
|
|
839
|
+
if (!Array.isArray(data.headers) || data.headers.some(
|
|
840
|
+
(header) => !isRecord2(header) || typeof header.key !== "string" || typeof header.value !== "string"
|
|
841
|
+
)) {
|
|
842
|
+
throw new Error("LLM Profile headers must contain string key/value pairs.");
|
|
843
|
+
}
|
|
844
|
+
if (data.apiKeySource !== "environment" && data.apiKeySource !== "input") {
|
|
845
|
+
throw new Error(`Unsupported LLM Profile API key source: ${String(data.apiKeySource)}.`);
|
|
846
|
+
}
|
|
847
|
+
assertEnumValue(data.openAIWebSearchContextSize, ["low", "medium", "high"], "OpenAI web search context");
|
|
848
|
+
const customProviderApi = parseCustomProviderApi(data.customProviderApi);
|
|
849
|
+
assertEnumValue(data.anthropicThinkingMode, ["", "adaptive", "enabled", "disabled"], "Anthropic thinking mode");
|
|
850
|
+
assertEnumValue(data.anthropicEffort, ["", "low", "medium", "high", "max"], "Anthropic effort");
|
|
851
|
+
assertEnumValue(data.anthropicCacheControlTtl, ["", "5m", "1h"], "Anthropic cache TTL");
|
|
852
|
+
assertEnumValue(data.googleThinkingLevel, ["", "minimal", "low", "medium", "high"], "Google thinking level");
|
|
853
|
+
const resolvedData = {
|
|
854
|
+
...data,
|
|
855
|
+
customProviderApi,
|
|
856
|
+
providerApiKeyNames: normalizeChatV2CredentialNamesByProvider(data.providerApiKeyNames),
|
|
857
|
+
model: data.model.trim(),
|
|
858
|
+
customProviderBaseURL: data.customProviderBaseURL.trim(),
|
|
859
|
+
customProviderApiKeyProgrammaticName: (_a = data.customProviderApiKeyProgrammaticName) == null ? void 0 : _a.trim(),
|
|
860
|
+
customProviderApiKeyEnvVarName: (_b = data.customProviderApiKeyEnvVarName) == null ? void 0 : _b.trim(),
|
|
861
|
+
stopSequences: [...data.stopSequences],
|
|
862
|
+
headers: data.headers.map(({ key, value }) => ({ key, value }))
|
|
863
|
+
};
|
|
864
|
+
for (const field of llmProfileResolvedInputToggleDataKeys) {
|
|
865
|
+
resolvedData[field] = false;
|
|
866
|
+
}
|
|
867
|
+
return pickLLMChatV2ProfileData(resolvedData);
|
|
868
|
+
}
|
|
869
|
+
function assertEnumValue(value, allowed, label) {
|
|
870
|
+
if (typeof value !== "string" || !allowed.includes(value)) {
|
|
871
|
+
throw new Error(`Unsupported LLM Profile ${label}: ${String(value)}.`);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
function normalizeProvider(value) {
|
|
875
|
+
if (typeof value !== "string" || !profileProviders.has(value)) {
|
|
876
|
+
throw new Error(`Unsupported LLM Profile provider: ${String(value)}.`);
|
|
877
|
+
}
|
|
878
|
+
return value;
|
|
879
|
+
}
|
|
880
|
+
function normalizeCredential(value) {
|
|
881
|
+
if (!isRecord2(value) || !isRecord2(value.reference) || typeof value.reference.source !== "string" || !credentialSources.has(value.reference.source)) {
|
|
882
|
+
throw new Error("LLM Profile credential metadata is invalid.");
|
|
883
|
+
}
|
|
884
|
+
const credentialValue = value.value;
|
|
885
|
+
if (credentialValue != null && typeof credentialValue !== "string") {
|
|
886
|
+
throw new Error("LLM Profile API key must be a string when provided.");
|
|
887
|
+
}
|
|
888
|
+
const name = value.reference.name;
|
|
889
|
+
if (name != null && typeof name !== "string") {
|
|
890
|
+
throw new Error("LLM Profile credential name must be a string when provided.");
|
|
891
|
+
}
|
|
892
|
+
return {
|
|
893
|
+
...credentialValue == null ? {} : { value: credentialValue },
|
|
894
|
+
reference: {
|
|
895
|
+
source: value.reference.source,
|
|
896
|
+
...name == null ? {} : { name }
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
}
|
|
900
|
+
function normalizeSourceIdentity(value) {
|
|
901
|
+
if (!isRecord2(value)) {
|
|
902
|
+
return {};
|
|
903
|
+
}
|
|
904
|
+
const profileName = normalizeProfileName(value.profileName);
|
|
905
|
+
return {
|
|
906
|
+
...typeof value.projectId === "string" ? { projectId: value.projectId } : {},
|
|
907
|
+
...typeof value.profileNodeId === "string" ? { profileNodeId: value.profileNodeId } : {},
|
|
908
|
+
...profileName == null ? {} : { profileName }
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
function normalizeProfileName(value) {
|
|
912
|
+
if (typeof value !== "string") return void 0;
|
|
913
|
+
const normalized = value.trim();
|
|
914
|
+
return normalized === "" ? void 0 : normalized;
|
|
915
|
+
}
|
|
916
|
+
function isRecord2(value) {
|
|
917
|
+
return typeof value === "object" && value != null && !Array.isArray(value);
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
// src/utils/coerceType.ts
|
|
921
|
+
function isValidatedObjectValueType(type) {
|
|
922
|
+
return type === "knowledge-source" || type === "knowledge-document" || type === "knowledge-evidence" || type === "llm-config";
|
|
923
|
+
}
|
|
924
|
+
function canAttemptGeneralCoercion(from, to) {
|
|
925
|
+
return !isValidatedObjectValueType(from) || to === "object" || to === "string";
|
|
926
|
+
}
|
|
927
|
+
function generalScalarRule(target, coerce) {
|
|
928
|
+
return {
|
|
929
|
+
...coerce ? { coerce } : {},
|
|
930
|
+
canAttempt: (from) => canAttemptGeneralCoercion(from, target)
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
function sameTypeOrObjectScalarRule(target, coerce) {
|
|
934
|
+
return {
|
|
935
|
+
...coerce ? { coerce } : {},
|
|
936
|
+
canAttempt: (from) => from === target || from === "object"
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
var scalarCoercionRules = {
|
|
940
|
+
any: {
|
|
941
|
+
canAttempt: () => true
|
|
942
|
+
},
|
|
943
|
+
boolean: generalScalarRule("boolean", coerceToBoolean),
|
|
944
|
+
string: generalScalarRule("string", coerceToString),
|
|
945
|
+
number: generalScalarRule("number", coerceToNumber),
|
|
946
|
+
date: generalScalarRule("date"),
|
|
947
|
+
time: generalScalarRule("time"),
|
|
948
|
+
datetime: generalScalarRule("datetime"),
|
|
949
|
+
"chat-message": generalScalarRule("chat-message", coerceToChatMessage),
|
|
950
|
+
"control-flow-excluded": generalScalarRule("control-flow-excluded"),
|
|
951
|
+
object: generalScalarRule("object", coerceToObject),
|
|
952
|
+
"gpt-function": {
|
|
953
|
+
canAttempt: (from) => from === "object"
|
|
954
|
+
},
|
|
955
|
+
vector: generalScalarRule("vector"),
|
|
956
|
+
image: sameTypeOrObjectScalarRule("image"),
|
|
957
|
+
binary: sameTypeOrObjectScalarRule("binary", coerceToBinary),
|
|
958
|
+
audio: sameTypeOrObjectScalarRule("audio"),
|
|
959
|
+
"graph-reference": generalScalarRule("graph-reference", coerceToGraphReference),
|
|
960
|
+
"knowledge-source": sameTypeOrObjectScalarRule(
|
|
961
|
+
"knowledge-source",
|
|
962
|
+
(value) => coerceValidatedObjectValue(value, normalizeKnowledgeSourceReference)
|
|
963
|
+
),
|
|
964
|
+
"knowledge-document": sameTypeOrObjectScalarRule(
|
|
965
|
+
"knowledge-document",
|
|
966
|
+
(value) => coerceValidatedObjectValue(value, normalizeKnowledgeDocument)
|
|
967
|
+
),
|
|
968
|
+
"knowledge-evidence": sameTypeOrObjectScalarRule(
|
|
969
|
+
"knowledge-evidence",
|
|
970
|
+
(value) => coerceValidatedObjectValue(value, normalizeKnowledgeEvidence)
|
|
971
|
+
),
|
|
972
|
+
"llm-config": sameTypeOrObjectScalarRule(
|
|
973
|
+
"llm-config",
|
|
974
|
+
(value) => coerceValidatedObjectValue(value, normalizeLLMProfileValue)
|
|
975
|
+
),
|
|
976
|
+
document: generalScalarRule("document")
|
|
977
|
+
};
|
|
978
|
+
function coerceTypeOptional(wrapped, type) {
|
|
979
|
+
if (wrapped && isFunctionDataType(type)) {
|
|
980
|
+
return expectTypeOptional(wrapped, type);
|
|
981
|
+
}
|
|
982
|
+
const value = wrapped ? unwrapDataValue(wrapped) : void 0;
|
|
983
|
+
if (isArrayDataType(type) && !isArrayDataValue(value)) {
|
|
984
|
+
const coerced = coerceTypeOptional(value, getScalarTypeOf(type));
|
|
985
|
+
if (coerced === void 0) {
|
|
986
|
+
return void 0;
|
|
987
|
+
}
|
|
988
|
+
const coercedArray = [coerced];
|
|
989
|
+
return coercedArray;
|
|
990
|
+
}
|
|
991
|
+
if (isArrayDataType(type) && isArrayDataValue(value)) {
|
|
992
|
+
if (getScalarTypeOf(type) === getScalarTypeOf(value.type)) {
|
|
993
|
+
return value.value;
|
|
994
|
+
}
|
|
995
|
+
const coercedArray = value.value.map(
|
|
996
|
+
(v) => coerceTypeOptional({ type: getScalarTypeOf(value.type), value: v }, getScalarTypeOf(type))
|
|
997
|
+
);
|
|
998
|
+
return coercedArray;
|
|
999
|
+
}
|
|
1000
|
+
const scalarRule = isScalarDataType(type) ? scalarCoercionRules[type] : void 0;
|
|
1001
|
+
const result = (scalarRule == null ? void 0 : scalarRule.coerce) ? scalarRule.coerce(value) : coerceWithoutSpecializedRule(value, type);
|
|
1002
|
+
return result;
|
|
1003
|
+
}
|
|
1004
|
+
function coerceWithoutSpecializedRule(value, type) {
|
|
1005
|
+
if (!value) {
|
|
1006
|
+
return value;
|
|
1007
|
+
}
|
|
1008
|
+
if (getScalarTypeOf(value.type) === "any" || getScalarTypeOf(type) === "any") {
|
|
1009
|
+
return value.value;
|
|
1010
|
+
}
|
|
1011
|
+
return expectTypeOptional(value, type);
|
|
1012
|
+
}
|
|
1013
|
+
function inferType(value) {
|
|
1014
|
+
if (value === void 0) {
|
|
1015
|
+
return { type: "any", value: void 0 };
|
|
1016
|
+
}
|
|
1017
|
+
if (value === null) {
|
|
1018
|
+
return { type: "any", value: null };
|
|
1019
|
+
}
|
|
1020
|
+
if (typeof value === "function") {
|
|
1021
|
+
return { type: "fn<any>", value };
|
|
1022
|
+
}
|
|
1023
|
+
if (typeof value === "string") {
|
|
1024
|
+
return { type: "string", value };
|
|
1025
|
+
}
|
|
1026
|
+
if (typeof value === "boolean") {
|
|
1027
|
+
return { type: "boolean", value };
|
|
1028
|
+
}
|
|
1029
|
+
if (typeof value === "number") {
|
|
1030
|
+
return { type: "number", value };
|
|
1031
|
+
}
|
|
1032
|
+
if (value instanceof Date) {
|
|
1033
|
+
return { type: "datetime", value: value.toISOString() };
|
|
1034
|
+
}
|
|
1035
|
+
if (Array.isArray(value)) {
|
|
1036
|
+
if (value.length === 0) {
|
|
1037
|
+
return { type: "any[]", value: [] };
|
|
1038
|
+
}
|
|
1039
|
+
const inferredType = inferType(value[0]);
|
|
1040
|
+
return { type: inferredType.type + "[]", value };
|
|
1041
|
+
}
|
|
1042
|
+
if (typeof value === "object") {
|
|
1043
|
+
return { type: "object", value };
|
|
1044
|
+
}
|
|
1045
|
+
throw new Error(`Cannot infer type of value: ${value}`);
|
|
1046
|
+
}
|
|
1047
|
+
function coerceToString(value) {
|
|
1048
|
+
if (!value) {
|
|
1049
|
+
return "";
|
|
1050
|
+
}
|
|
1051
|
+
if (isArrayDataValue(value)) {
|
|
1052
|
+
return value.value.map((v) => coerceTypeOptional({ type: getScalarTypeOf(value.type), value: v }, "string")).join("\n");
|
|
1053
|
+
}
|
|
1054
|
+
if (value.type === "string") {
|
|
1055
|
+
return value.value;
|
|
1056
|
+
}
|
|
1057
|
+
if (value.type === "boolean") {
|
|
1058
|
+
return value.value.toString();
|
|
1059
|
+
}
|
|
1060
|
+
if (value.type === "number") {
|
|
1061
|
+
return value.value.toString();
|
|
1062
|
+
}
|
|
1063
|
+
if (value.type === "date") {
|
|
1064
|
+
return value.value;
|
|
1065
|
+
}
|
|
1066
|
+
if (value.type === "time") {
|
|
1067
|
+
return value.value;
|
|
1068
|
+
}
|
|
1069
|
+
if (value.type === "datetime") {
|
|
1070
|
+
return value.value;
|
|
1071
|
+
}
|
|
1072
|
+
if (value.type === "chat-message") {
|
|
1073
|
+
const messageParts = Array.isArray(value.value.message) ? value.value.message : [value.value.message];
|
|
1074
|
+
const singleString = messageParts.map((part) => {
|
|
1075
|
+
if (typeof part === "string") {
|
|
1076
|
+
return part;
|
|
1077
|
+
}
|
|
1078
|
+
return part.type === "url" ? `(Image: ${part.url})` : "(Image)";
|
|
1079
|
+
}).join("\n\n");
|
|
1080
|
+
return singleString;
|
|
1081
|
+
}
|
|
1082
|
+
if (value.value === void 0) {
|
|
1083
|
+
return void 0;
|
|
1084
|
+
}
|
|
1085
|
+
if (value.value === null) {
|
|
1086
|
+
return void 0;
|
|
1087
|
+
}
|
|
1088
|
+
if (typeof value.value === "object" && !Array.isArray(value.value)) {
|
|
1089
|
+
return JSON.stringify(value.value);
|
|
1090
|
+
}
|
|
1091
|
+
if (value.type === "any" || value.type === "object") {
|
|
1092
|
+
const inferred = inferType(value.value);
|
|
1093
|
+
return coerceTypeOptional(inferred, "string");
|
|
1094
|
+
}
|
|
1095
|
+
return JSON.stringify(value.value);
|
|
1096
|
+
}
|
|
1097
|
+
function coerceToChatMessage(value) {
|
|
1098
|
+
var _a;
|
|
1099
|
+
const chatMessage = coerceToChatMessageRaw(value);
|
|
1100
|
+
if ((chatMessage == null ? void 0 : chatMessage.type) === "assistant") {
|
|
1101
|
+
if (((_a = chatMessage.function_call) == null ? void 0 : _a.arguments) && typeof chatMessage.function_call.arguments !== "string") {
|
|
1102
|
+
chatMessage.function_call.arguments = JSON.stringify(chatMessage.function_call.arguments);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
return chatMessage;
|
|
1106
|
+
}
|
|
1107
|
+
function coerceToChatMessageRaw(value) {
|
|
1108
|
+
if (!value || value.value == null) {
|
|
1109
|
+
return void 0;
|
|
1110
|
+
}
|
|
1111
|
+
if (value.type === "chat-message") {
|
|
1112
|
+
return value.value;
|
|
1113
|
+
}
|
|
1114
|
+
if (value.type === "string") {
|
|
1115
|
+
return { type: "user", message: value.value };
|
|
1116
|
+
}
|
|
1117
|
+
if (value.type === "object" && "type" in value.value && "message" in value.value && typeof value.value.type === "string" && typeof value.value.message === "string") {
|
|
1118
|
+
return value.value;
|
|
1119
|
+
}
|
|
1120
|
+
if (value.type === "any") {
|
|
1121
|
+
const inferred = inferType(value.value);
|
|
1122
|
+
return coerceTypeOptional(inferred, "chat-message");
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
function coerceToBoolean(value) {
|
|
1126
|
+
if (!value || !value.value) {
|
|
1127
|
+
return false;
|
|
1128
|
+
}
|
|
1129
|
+
if (isArrayDataValue(value)) {
|
|
1130
|
+
return value.value.map((v) => coerceTypeOptional({ type: value.type.replace("[]", ""), value: v }, "boolean")).every((v) => v);
|
|
1131
|
+
}
|
|
1132
|
+
if (value.type === "string") {
|
|
1133
|
+
return value.value.length > 0 && value.value !== "false";
|
|
1134
|
+
}
|
|
1135
|
+
if (value.type === "boolean") {
|
|
1136
|
+
return value.value;
|
|
1137
|
+
}
|
|
1138
|
+
if (value.type === "number") {
|
|
1139
|
+
return value.value !== 0;
|
|
1140
|
+
}
|
|
1141
|
+
if (value.type === "date") {
|
|
1142
|
+
return true;
|
|
1143
|
+
}
|
|
1144
|
+
if (value.type === "time") {
|
|
1145
|
+
return true;
|
|
1146
|
+
}
|
|
1147
|
+
if (value.type === "datetime") {
|
|
1148
|
+
return true;
|
|
1149
|
+
}
|
|
1150
|
+
if (value.type === "chat-message") {
|
|
1151
|
+
const hasValue = Array.isArray(value.value.message) && value.value.message.length > 0 || typeof value.value.message === "string" && value.value.message.length > 0 || typeof value.value.message === "object" && "type" in value.value.message && value.value.message.type === "url" && value.value.message.url.length > 0;
|
|
1152
|
+
return hasValue;
|
|
1153
|
+
}
|
|
1154
|
+
return !!value.value;
|
|
1155
|
+
}
|
|
1156
|
+
function coerceToNumber(value) {
|
|
1157
|
+
if (!value || value.value == null) {
|
|
1158
|
+
return void 0;
|
|
1159
|
+
}
|
|
1160
|
+
if (isArrayDataValue(value)) {
|
|
1161
|
+
return void 0;
|
|
1162
|
+
}
|
|
1163
|
+
if (value.type === "string") {
|
|
1164
|
+
return parseFloat(value.value);
|
|
1165
|
+
}
|
|
1166
|
+
if (value.type === "boolean") {
|
|
1167
|
+
return value.value ? 1 : 0;
|
|
1168
|
+
}
|
|
1169
|
+
if (value.type === "number") {
|
|
1170
|
+
return value.value;
|
|
1171
|
+
}
|
|
1172
|
+
if (value.type === "date") {
|
|
1173
|
+
return new Date(value.value).valueOf();
|
|
1174
|
+
}
|
|
1175
|
+
if (value.type === "time") {
|
|
1176
|
+
return new Date(value.value).valueOf();
|
|
1177
|
+
}
|
|
1178
|
+
if (value.type === "datetime") {
|
|
1179
|
+
return new Date(value.value).valueOf();
|
|
1180
|
+
}
|
|
1181
|
+
if (value.type === "chat-message") {
|
|
1182
|
+
if (typeof value.value.message === "string") {
|
|
1183
|
+
return parseFloat(value.value.message);
|
|
1184
|
+
}
|
|
1185
|
+
if (Array.isArray(value.value.message) && value.value.message.length === 1 && typeof value.value.message[0] === "string") {
|
|
1186
|
+
return parseFloat(value.value.message[0]);
|
|
1187
|
+
}
|
|
1188
|
+
return void 0;
|
|
1189
|
+
}
|
|
1190
|
+
if (value.type === "any" || value.type === "object") {
|
|
1191
|
+
const inferred = inferType(value.value);
|
|
1192
|
+
if (inferred.type === "any" || inferred.type === "object") {
|
|
1193
|
+
return void 0;
|
|
1194
|
+
}
|
|
1195
|
+
return coerceTypeOptional(inferred, "number");
|
|
1196
|
+
}
|
|
1197
|
+
return void 0;
|
|
1198
|
+
}
|
|
1199
|
+
function coerceToObject(value) {
|
|
1200
|
+
if (!value || value.value == null) {
|
|
1201
|
+
return void 0;
|
|
1202
|
+
}
|
|
1203
|
+
return value.value;
|
|
1204
|
+
}
|
|
1205
|
+
function coerceToBinary(value) {
|
|
1206
|
+
if (!value || value.value == null) {
|
|
1207
|
+
return void 0;
|
|
1208
|
+
}
|
|
1209
|
+
if (value.type === "binary") {
|
|
1210
|
+
return value.value;
|
|
1211
|
+
}
|
|
1212
|
+
if (value.type === "string") {
|
|
1213
|
+
return new TextEncoder().encode(value.value);
|
|
1214
|
+
}
|
|
1215
|
+
if (value.type === "boolean") {
|
|
1216
|
+
return new TextEncoder().encode(value.value.toString());
|
|
1217
|
+
}
|
|
1218
|
+
if (value.type === "vector" || value.type === "number[]") {
|
|
1219
|
+
return new Uint8Array(value.value);
|
|
1220
|
+
}
|
|
1221
|
+
if (value.type === "number") {
|
|
1222
|
+
return new Uint8Array([value.value]);
|
|
1223
|
+
}
|
|
1224
|
+
if (value.type === "audio" || value.type === "image" || value.type === "document") {
|
|
1225
|
+
return value.value.data;
|
|
1226
|
+
}
|
|
1227
|
+
return new TextEncoder().encode(JSON.stringify(value.value));
|
|
1228
|
+
}
|
|
1229
|
+
function coerceToGraphReference(value) {
|
|
1230
|
+
if (!value || value.value == null) {
|
|
1231
|
+
return void 0;
|
|
1232
|
+
}
|
|
1233
|
+
if (value.type === "graph-reference") {
|
|
1234
|
+
return value.value;
|
|
1235
|
+
}
|
|
1236
|
+
if (value.type === "string") {
|
|
1237
|
+
return { graphName: value.value, graphId: "" };
|
|
1238
|
+
}
|
|
1239
|
+
if (value.type === "object" && "graphName" in value.value && "graphId" in value.value) {
|
|
1240
|
+
return value.value;
|
|
1241
|
+
}
|
|
1242
|
+
return void 0;
|
|
1243
|
+
}
|
|
1244
|
+
function coerceValidatedObjectValue(value, normalize) {
|
|
1245
|
+
if (!value || value.value == null || isArrayDataValue(value)) return void 0;
|
|
1246
|
+
try {
|
|
1247
|
+
return normalize(value.value);
|
|
1248
|
+
} catch {
|
|
1249
|
+
return void 0;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
// src/utils/jsonPath.ts
|
|
1254
|
+
var import_jsonpath_plus = require("jsonpath-plus");
|
|
1255
|
+
|
|
1256
|
+
// src/utils/interpolationSyntax.ts
|
|
1257
|
+
var REGEX_LITERAL_PREFIX_CHARACTERS = /* @__PURE__ */ new Set([
|
|
1258
|
+
"(",
|
|
1259
|
+
"[",
|
|
1260
|
+
"{",
|
|
1261
|
+
":",
|
|
1262
|
+
";",
|
|
1263
|
+
",",
|
|
1264
|
+
"=",
|
|
1265
|
+
"!",
|
|
1266
|
+
"~",
|
|
1267
|
+
"?",
|
|
1268
|
+
"&",
|
|
1269
|
+
"|",
|
|
1270
|
+
"+",
|
|
1271
|
+
"-",
|
|
1272
|
+
"*",
|
|
1273
|
+
"%",
|
|
1274
|
+
"^",
|
|
1275
|
+
"<",
|
|
1276
|
+
">"
|
|
1277
|
+
]);
|
|
1278
|
+
function isInterpolationSyntaxCharacterEscaped(value, index) {
|
|
1279
|
+
let backslashCount = 0;
|
|
1280
|
+
for (let cursor = index - 1; cursor >= 0 && value[cursor] === "\\"; cursor -= 1) {
|
|
1281
|
+
backslashCount += 1;
|
|
1282
|
+
}
|
|
1283
|
+
return backslashCount % 2 === 1;
|
|
1284
|
+
}
|
|
1285
|
+
function isInterpolationRegexLiteralStart(value, index) {
|
|
1286
|
+
if (value[index] !== "/") {
|
|
1287
|
+
return false;
|
|
1288
|
+
}
|
|
1289
|
+
let previousIndex = index - 1;
|
|
1290
|
+
while (previousIndex >= 0 && /\s/.test(value[previousIndex])) {
|
|
1291
|
+
previousIndex -= 1;
|
|
1292
|
+
}
|
|
1293
|
+
return previousIndex < 0 || REGEX_LITERAL_PREFIX_CHARACTERS.has(value[previousIndex]);
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
// src/utils/jsonPath.ts
|
|
1297
|
+
function getNextNonWhitespaceCharacter(value, index) {
|
|
1298
|
+
for (let cursor = index; cursor < value.length; cursor++) {
|
|
1299
|
+
if (!/\s/.test(value[cursor])) {
|
|
1300
|
+
return value[cursor];
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
return void 0;
|
|
1304
|
+
}
|
|
1305
|
+
function getWhitespaceRunEnd(value, index) {
|
|
1306
|
+
let cursor = index;
|
|
1307
|
+
while (cursor < value.length && /\s/.test(value[cursor])) {
|
|
1308
|
+
cursor += 1;
|
|
1309
|
+
}
|
|
1310
|
+
return cursor;
|
|
1311
|
+
}
|
|
1312
|
+
function normalizeJsonPathExpression(path) {
|
|
1313
|
+
const trimmedPath = path.trim();
|
|
1314
|
+
if (!/\s/.test(trimmedPath)) {
|
|
1315
|
+
return trimmedPath;
|
|
1316
|
+
}
|
|
1317
|
+
const result = [];
|
|
1318
|
+
let lastResultCharacter;
|
|
1319
|
+
let quote;
|
|
1320
|
+
let regex = false;
|
|
1321
|
+
let regexCharacterClass = false;
|
|
1322
|
+
const filterBrackets = [];
|
|
1323
|
+
let filterDepth = 0;
|
|
1324
|
+
const append = (value) => {
|
|
1325
|
+
if (value === "") {
|
|
1326
|
+
return;
|
|
1327
|
+
}
|
|
1328
|
+
result.push(value);
|
|
1329
|
+
lastResultCharacter = value.at(-1);
|
|
1330
|
+
};
|
|
1331
|
+
for (let cursor = 0; cursor < trimmedPath.length; cursor++) {
|
|
1332
|
+
const character = trimmedPath[cursor];
|
|
1333
|
+
if (regex) {
|
|
1334
|
+
if (character === "[" && !isInterpolationSyntaxCharacterEscaped(trimmedPath, cursor)) {
|
|
1335
|
+
regexCharacterClass = true;
|
|
1336
|
+
} else if (character === "]" && !isInterpolationSyntaxCharacterEscaped(trimmedPath, cursor)) {
|
|
1337
|
+
regexCharacterClass = false;
|
|
1338
|
+
} else if (character === "/" && !regexCharacterClass && !isInterpolationSyntaxCharacterEscaped(trimmedPath, cursor)) {
|
|
1339
|
+
regex = false;
|
|
1340
|
+
}
|
|
1341
|
+
append(character);
|
|
1342
|
+
continue;
|
|
1343
|
+
}
|
|
1344
|
+
if (quote) {
|
|
1345
|
+
if (character === quote && !isInterpolationSyntaxCharacterEscaped(trimmedPath, cursor)) {
|
|
1346
|
+
quote = void 0;
|
|
1347
|
+
}
|
|
1348
|
+
append(character);
|
|
1349
|
+
continue;
|
|
1350
|
+
}
|
|
1351
|
+
if (character === '"' || character === "'" || character === "`") {
|
|
1352
|
+
quote = character;
|
|
1353
|
+
append(character);
|
|
1354
|
+
continue;
|
|
1355
|
+
}
|
|
1356
|
+
if (character === "/" && isInterpolationRegexLiteralStart(trimmedPath, cursor)) {
|
|
1357
|
+
regex = true;
|
|
1358
|
+
regexCharacterClass = false;
|
|
1359
|
+
append(character);
|
|
1360
|
+
continue;
|
|
1361
|
+
}
|
|
1362
|
+
const insideFilter = filterDepth > 0;
|
|
1363
|
+
if (/\s/.test(character)) {
|
|
1364
|
+
const whitespaceEnd = getWhitespaceRunEnd(trimmedPath, cursor);
|
|
1365
|
+
const previousCharacter = lastResultCharacter;
|
|
1366
|
+
const nextCharacter = trimmedPath[whitespaceEnd];
|
|
1367
|
+
const shouldRemoveWhitespace = previousCharacter === "[" || nextCharacter === "]" || nextCharacter === "[" || !insideFilter && (previousCharacter === "." || previousCharacter === "]" || nextCharacter === ".");
|
|
1368
|
+
if (!shouldRemoveWhitespace) {
|
|
1369
|
+
append(trimmedPath.slice(cursor, whitespaceEnd));
|
|
1370
|
+
}
|
|
1371
|
+
cursor = whitespaceEnd - 1;
|
|
1372
|
+
continue;
|
|
1373
|
+
}
|
|
1374
|
+
if (character === "[") {
|
|
1375
|
+
const opensFilter = getNextNonWhitespaceCharacter(trimmedPath, cursor + 1) === "?";
|
|
1376
|
+
filterBrackets.push(opensFilter);
|
|
1377
|
+
if (opensFilter) {
|
|
1378
|
+
filterDepth += 1;
|
|
1379
|
+
}
|
|
1380
|
+
append(character);
|
|
1381
|
+
continue;
|
|
1382
|
+
}
|
|
1383
|
+
if (character === "]") {
|
|
1384
|
+
if (filterBrackets.pop()) {
|
|
1385
|
+
filterDepth -= 1;
|
|
1386
|
+
}
|
|
1387
|
+
append(character);
|
|
1388
|
+
continue;
|
|
1389
|
+
}
|
|
1390
|
+
append(character);
|
|
1391
|
+
}
|
|
1392
|
+
return result.join("").trim();
|
|
1393
|
+
}
|
|
1394
|
+
function evaluateJsonPath(value, path, wrap = false) {
|
|
1395
|
+
return (0, import_jsonpath_plus.JSONPath)({
|
|
1396
|
+
json: value ?? null,
|
|
1397
|
+
path: normalizeJsonPathExpression(path),
|
|
1398
|
+
wrap
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
// src/utils/misc.ts
|
|
1403
|
+
var import_ts_dedent = require("ts-dedent");
|
|
1404
|
+
|
|
1405
|
+
// src/utils/interpolation.ts
|
|
1406
|
+
var INTERPOLATION_TEMPLATE_CACHE_MAX_TEMPLATE_LENGTH = 64 * 1024;
|
|
1407
|
+
var INTERPOLATION_TEMPLATE_CACHE_MAX_TEMPLATE_CHARS = 1024 * 1024;
|
|
1408
|
+
var INTERPOLATION_TEMPLATE_CACHE_MAX_STORAGE_CHARS = 2 * 1024 * 1024;
|
|
1409
|
+
var INTERPOLATION_EXPRESSION_CACHE_MAX_ENTRIES = 512;
|
|
1410
|
+
var INTERPOLATION_EXPRESSION_CACHE_MAX_EXPRESSION_LENGTH = 4 * 1024;
|
|
1411
|
+
var INTERPOLATION_EXPRESSION_CACHE_MAX_CHARS = 128 * 1024;
|
|
1412
|
+
var interpolationExpressionCache = /* @__PURE__ */ new Map();
|
|
1413
|
+
var cachedInterpolationExpressionChars = 0;
|
|
1414
|
+
var dataValueTypeSet = new Set(dataTypes);
|
|
1415
|
+
function unwrapPotentialDataValue(value) {
|
|
1416
|
+
if (isRivetDataValue(value)) {
|
|
1417
|
+
return value.value;
|
|
1418
|
+
}
|
|
1419
|
+
return value;
|
|
1420
|
+
}
|
|
1421
|
+
function isRivetDataValue(value) {
|
|
1422
|
+
return typeof value === "object" && value !== null && typeof value.type === "string" && dataValueTypeSet.has(value.type) && Object.prototype.hasOwnProperty.call(value, "value");
|
|
1423
|
+
}
|
|
1424
|
+
function findQuotedStringEnd(value, start) {
|
|
1425
|
+
const quote = value[start];
|
|
1426
|
+
for (let cursor = start + 1; cursor < value.length; cursor++) {
|
|
1427
|
+
if (value[cursor] === quote && !isInterpolationSyntaxCharacterEscaped(value, cursor)) {
|
|
1428
|
+
return cursor;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
return void 0;
|
|
1432
|
+
}
|
|
1433
|
+
function parseQuotedBaseReference(expression) {
|
|
1434
|
+
if (expression[0] !== "[") {
|
|
1435
|
+
return void 0;
|
|
1436
|
+
}
|
|
1437
|
+
let cursor = 1;
|
|
1438
|
+
while (expression[cursor] === " ") {
|
|
1439
|
+
cursor += 1;
|
|
1440
|
+
}
|
|
1441
|
+
const quote = expression[cursor];
|
|
1442
|
+
if (quote !== '"' && quote !== "'") {
|
|
1443
|
+
return void 0;
|
|
1444
|
+
}
|
|
1445
|
+
const quoteEnd = findQuotedStringEnd(expression, cursor);
|
|
1446
|
+
if (quoteEnd === void 0) {
|
|
1447
|
+
return void 0;
|
|
1448
|
+
}
|
|
1449
|
+
const baseName = expression.slice(cursor + 1, quoteEnd);
|
|
1450
|
+
if (!baseName) {
|
|
1451
|
+
return void 0;
|
|
1452
|
+
}
|
|
1453
|
+
cursor = quoteEnd + 1;
|
|
1454
|
+
while (expression[cursor] === " ") {
|
|
1455
|
+
cursor += 1;
|
|
1456
|
+
}
|
|
1457
|
+
if (expression[cursor] !== "]") {
|
|
1458
|
+
return void 0;
|
|
1459
|
+
}
|
|
1460
|
+
const suffix = expression.slice(cursor + 1).trimStart();
|
|
1461
|
+
if (suffix !== "" && !suffix.startsWith(".") && !suffix.startsWith("[")) {
|
|
1462
|
+
return void 0;
|
|
1463
|
+
}
|
|
1464
|
+
return { baseName, suffix: suffix || void 0 };
|
|
1465
|
+
}
|
|
1466
|
+
function parseBaseReference(expression, source) {
|
|
1467
|
+
const trimmedExpression = expression.trim();
|
|
1468
|
+
if (!trimmedExpression) {
|
|
1469
|
+
return void 0;
|
|
1470
|
+
}
|
|
1471
|
+
const quotedReference = parseQuotedBaseReference(trimmedExpression);
|
|
1472
|
+
if (quotedReference) {
|
|
1473
|
+
return {
|
|
1474
|
+
source,
|
|
1475
|
+
baseName: quotedReference.baseName,
|
|
1476
|
+
jsonPath: quotedReference.suffix ? normalizeJsonPathExpression(`$${quotedReference.suffix}`) : void 0
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1479
|
+
let suffixStart = -1;
|
|
1480
|
+
for (let cursor = 0; cursor < trimmedExpression.length; cursor++) {
|
|
1481
|
+
const character = trimmedExpression[cursor];
|
|
1482
|
+
if (character === "." || character === "[") {
|
|
1483
|
+
suffixStart = cursor;
|
|
1484
|
+
break;
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
if (suffixStart === -1) {
|
|
1488
|
+
return {
|
|
1489
|
+
source,
|
|
1490
|
+
baseName: trimmedExpression,
|
|
1491
|
+
jsonPath: void 0
|
|
1492
|
+
};
|
|
1493
|
+
}
|
|
1494
|
+
const baseName = trimmedExpression.slice(0, suffixStart).trim();
|
|
1495
|
+
const suffix = normalizeJsonPathExpression(trimmedExpression.slice(suffixStart));
|
|
1496
|
+
if (!baseName || !suffix.startsWith(".") && !suffix.startsWith("[")) {
|
|
1497
|
+
return void 0;
|
|
1498
|
+
}
|
|
1499
|
+
return {
|
|
1500
|
+
source,
|
|
1501
|
+
baseName,
|
|
1502
|
+
jsonPath: `$${suffix}`
|
|
1503
|
+
};
|
|
1504
|
+
}
|
|
1505
|
+
function parseInterpolationExpressionUncached(trimmedExpression) {
|
|
1506
|
+
for (const [prefix, source] of [
|
|
1507
|
+
["@graphInputs", "graphInputs"],
|
|
1508
|
+
["@context", "context"]
|
|
1509
|
+
]) {
|
|
1510
|
+
if (trimmedExpression.startsWith(`${prefix}.`)) {
|
|
1511
|
+
return parseBaseReference(trimmedExpression.slice(prefix.length + 1), source);
|
|
1512
|
+
}
|
|
1513
|
+
if (trimmedExpression.startsWith(`${prefix}[`)) {
|
|
1514
|
+
return parseBaseReference(trimmedExpression.slice(prefix.length), source);
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
return parseBaseReference(trimmedExpression, "variable");
|
|
1518
|
+
}
|
|
1519
|
+
function getCachedInterpolationExpression(expression) {
|
|
1520
|
+
const trimmedExpression = expression.trim();
|
|
1521
|
+
if (interpolationExpressionCache.has(trimmedExpression)) {
|
|
1522
|
+
return interpolationExpressionCache.get(trimmedExpression);
|
|
1523
|
+
}
|
|
1524
|
+
const parsed = parseInterpolationExpressionUncached(trimmedExpression);
|
|
1525
|
+
if (trimmedExpression.length > INTERPOLATION_EXPRESSION_CACHE_MAX_EXPRESSION_LENGTH) {
|
|
1526
|
+
return parsed;
|
|
1527
|
+
}
|
|
1528
|
+
if (interpolationExpressionCache.size >= INTERPOLATION_EXPRESSION_CACHE_MAX_ENTRIES || cachedInterpolationExpressionChars + trimmedExpression.length > INTERPOLATION_EXPRESSION_CACHE_MAX_CHARS) {
|
|
1529
|
+
interpolationExpressionCache.clear();
|
|
1530
|
+
cachedInterpolationExpressionChars = 0;
|
|
1531
|
+
}
|
|
1532
|
+
const immutableParsed = parsed ? Object.freeze({ ...parsed }) : void 0;
|
|
1533
|
+
interpolationExpressionCache.set(trimmedExpression, immutableParsed);
|
|
1534
|
+
cachedInterpolationExpressionChars += trimmedExpression.length;
|
|
1535
|
+
return immutableParsed;
|
|
1536
|
+
}
|
|
1537
|
+
function getInterpolationSource(reference, sources) {
|
|
1538
|
+
switch (reference.source) {
|
|
1539
|
+
case "variable":
|
|
1540
|
+
return sources.variables;
|
|
1541
|
+
case "graphInputs":
|
|
1542
|
+
return sources.graphInputValues;
|
|
1543
|
+
case "context":
|
|
1544
|
+
return sources.contextValues;
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
function resolveInterpolationExpressionRawValue(expression, sources) {
|
|
1548
|
+
const reference = typeof expression === "string" ? getCachedInterpolationExpression(expression) : expression;
|
|
1549
|
+
if (!reference) {
|
|
1550
|
+
return void 0;
|
|
1551
|
+
}
|
|
1552
|
+
const source = getInterpolationSource(reference, sources);
|
|
1553
|
+
if (!source || !Object.prototype.hasOwnProperty.call(source, reference.baseName)) {
|
|
1554
|
+
return void 0;
|
|
1555
|
+
}
|
|
1556
|
+
const shouldUnwrapDataValue = reference.source !== "variable" || sources.unwrapVariableDataValues !== false;
|
|
1557
|
+
const baseValue = shouldUnwrapDataValue ? unwrapPotentialDataValue(source[reference.baseName]) : source[reference.baseName];
|
|
1558
|
+
if (reference.jsonPath === void 0) {
|
|
1559
|
+
return baseValue;
|
|
1560
|
+
}
|
|
1561
|
+
try {
|
|
1562
|
+
return evaluateJsonPath(baseValue, reference.jsonPath, false);
|
|
1563
|
+
} catch {
|
|
1564
|
+
return void 0;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
function resolveCodeInterpolationExpression(inputs, expression, graphInputValues, contextValues) {
|
|
1568
|
+
return resolveInterpolationExpressionRawValue(expression, {
|
|
1569
|
+
variables: inputs,
|
|
1570
|
+
graphInputValues,
|
|
1571
|
+
contextValues
|
|
1572
|
+
});
|
|
1573
|
+
}
|
|
1574
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1575
|
+
0 && (module.exports = {
|
|
1576
|
+
resolveCodeInterpolationExpression
|
|
1577
|
+
});
|
|
1578
|
+
//# sourceMappingURL=interpolationRuntime.cjs.map
|