@valerypopoff/rivet2-core 2.15.0 → 2.17.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 +4350 -2077
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/cjs/interpolationRuntime.cjs +22 -3
- package/dist/cjs/interpolationRuntime.cjs.map +3 -3
- package/dist/cjs/interpolationSyntax.cjs +9 -5
- package/dist/cjs/interpolationSyntax.cjs.map +2 -2
- package/dist/esm/api/createProcessor.js +5 -2
- package/dist/esm/exports.js +2 -0
- package/dist/esm/model/GraphBoundaryCache.js +2 -1
- package/dist/esm/model/GraphProcessor.js +268 -6
- package/dist/esm/model/Nodes.js +10 -0
- package/dist/esm/model/ProjectBundle.js +235 -0
- package/dist/esm/model/SplitRunProcessor.js +28 -7
- package/dist/esm/model/StreamingWatchTopology.js +118 -8
- package/dist/esm/model/SubgraphProjectTarget.js +7 -0
- package/dist/esm/model/chat-v2/aiSdkBridge.js +7 -5
- package/dist/esm/model/chat-v2/chatV2Pipeline.js +13 -8
- package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +19 -1
- package/dist/esm/model/chat-v2/chatV2Shared.js +2 -1
- package/dist/esm/model/chat-v2/llmChatV2Body.js +11 -8
- package/dist/esm/model/chat-v2/llmChatV2NodeData.js +2 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +15 -1
- package/dist/esm/model/chat-v2/llmChatV2NodeMigration.js +22 -2
- package/dist/esm/model/chat-v2/llmProfile.js +3 -0
- package/dist/esm/model/chat-v2/llmProfileBody.js +2 -2
- package/dist/esm/model/chat-v2/llmProfileFieldRegistry.js +1 -1
- package/dist/esm/model/chat-v2/llmProfileNodeRuntime.js +1 -1
- package/dist/esm/model/chat-v2/temperature.js +9 -0
- package/dist/esm/model/classifier/credentials.js +30 -4
- package/dist/esm/model/classifier/images.js +176 -0
- package/dist/esm/model/classifier/json.js +57 -0
- package/dist/esm/model/classifier/limits.js +270 -0
- package/dist/esm/model/classifier/openai.js +118 -0
- package/dist/esm/model/classifier/preparation.js +74 -0
- package/dist/esm/model/classifier/providers.js +260 -185
- package/dist/esm/model/classifier/questionHelpers.js +29 -45
- package/dist/esm/model/classifier/questions.js +53 -0
- package/dist/esm/model/classifier/response.js +75 -0
- package/dist/esm/model/classifier/state.js +204 -0
- package/dist/esm/model/nodeRunFailure.js +47 -0
- package/dist/esm/model/nodes/CatchStreamingChunksNode.js +42 -0
- package/dist/esm/model/nodes/ClassifierEvaluateNode.js +178 -138
- package/dist/esm/model/nodes/ClassifierQuestionNode.js +59 -15
- package/dist/esm/model/nodes/GetGlobalNode.js +2 -2
- package/dist/esm/model/nodes/HttpCallNode.js +44 -75
- package/dist/esm/model/nodes/ImageNode.js +44 -3
- package/dist/esm/model/nodes/LLMChatV2Node.js +24 -3
- package/dist/esm/model/nodes/ObjectNode.js +29 -18
- package/dist/esm/model/nodes/PromptNode.js +2 -1
- package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +4 -1
- package/dist/esm/model/nodes/SetGlobalNode.js +5 -3
- package/dist/esm/model/nodes/StopWatchingStreamingOutputNode.js +8 -8
- package/dist/esm/model/nodes/StreamValueNode.js +38 -0
- package/dist/esm/model/nodes/SubGraphNode.js +196 -35
- package/dist/esm/model/nodes/ToBase64Node.js +106 -0
- package/dist/esm/model/nodes/WatchStreamingOutputNode.js +7 -7
- package/dist/esm/recording/ExecutionRecorder.js +26 -0
- package/dist/esm/utils/base64.js +18 -15
- package/dist/esm/utils/errors.js +41 -0
- package/dist/esm/utils/interpolation.js +44 -22
- package/dist/esm/utils/interpolationSyntax.js +15 -6
- package/dist/esm/utils/serialization/serialization.js +3 -2
- package/dist/esm/utils/serialization/serializationUtils.js +6 -0
- package/dist/esm/utils/serialization/serialization_v4.js +15 -3
- package/dist/types/api/createProcessor.d.ts +7 -1
- package/dist/types/exports.d.ts +2 -0
- package/dist/types/model/CycleDetector.d.ts +1 -2
- package/dist/types/model/ExecutorProtocol.d.ts +2 -0
- package/dist/types/model/GraphBoundaryCache.d.ts +2 -0
- package/dist/types/model/GraphProcessor.d.ts +1 -0
- package/dist/types/model/Nodes.d.ts +6 -2
- package/dist/types/model/ProcessContext.d.ts +12 -0
- package/dist/types/model/ProjectBundle.d.ts +54 -0
- package/dist/types/model/ProjectReferenceLoader.d.ts +3 -0
- package/dist/types/model/StreamingWatchTopology.d.ts +11 -1
- package/dist/types/model/SubgraphProjectTarget.d.ts +38 -0
- package/dist/types/model/chat-v2/chatV2Shared.d.ts +1 -1
- package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +3 -1
- package/dist/types/model/chat-v2/llmChatV2NodeMigration.d.ts +3 -1
- package/dist/types/model/chat-v2/llmProfileFieldRegistry.d.ts +6 -6
- package/dist/types/model/chat-v2/temperature.d.ts +2 -0
- package/dist/types/model/classifier/credentials.d.ts +3 -1
- package/dist/types/model/classifier/images.d.ts +18 -0
- package/dist/types/model/classifier/json.d.ts +19 -0
- package/dist/types/model/classifier/limits.d.ts +42 -0
- package/dist/types/model/classifier/openai.d.ts +5 -0
- package/dist/types/model/classifier/preparation.d.ts +16 -0
- package/dist/types/model/classifier/providers.d.ts +67 -9
- package/dist/types/model/classifier/questionHelpers.d.ts +6 -4
- package/dist/types/model/classifier/questions.d.ts +4 -0
- package/dist/types/model/classifier/response.d.ts +4 -0
- package/dist/types/model/classifier/state.d.ts +37 -0
- package/dist/types/model/classifier/types.d.ts +2 -0
- package/dist/types/model/nodeRunFailure.d.ts +13 -0
- package/dist/types/model/nodes/CatchStreamingChunksNode.d.ts +20 -0
- package/dist/types/model/nodes/ClassifierEvaluateNode.d.ts +3 -0
- package/dist/types/model/nodes/GetGlobalNode.d.ts +7 -0
- package/dist/types/model/nodes/ImageNode.d.ts +4 -0
- package/dist/types/model/nodes/LLMChatV2Node.d.ts +1 -0
- package/dist/types/model/nodes/ObjectNode.d.ts +2 -1
- package/dist/types/model/nodes/StreamValueNode.d.ts +14 -0
- package/dist/types/model/nodes/SubGraphNode.d.ts +21 -2
- package/dist/types/model/nodes/ToBase64Node.d.ts +12 -0
- package/dist/types/recording/ExecutionRecorder.d.ts +8 -2
- package/dist/types/utils/base64.d.ts +1 -1
- package/dist/types/utils/errors.d.ts +4 -0
- package/dist/types/utils/interpolation.d.ts +13 -2
- package/dist/types/utils/interpolationSyntax.d.ts +1 -1
- package/dist/types/utils/serialization/serialization.d.ts +3 -1
- package/dist/types/utils/serialization/serializationUtils.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { getSubgraphTargetBoundaryIssue } from './nodes/SubGraphNode.js';
|
|
2
|
+
import { getGraphBoundary } from './GraphBoundaryCache.js';
|
|
3
|
+
import { resolveNodePrefabInstance } from './NodePrefabResolver.js';
|
|
4
|
+
import { findStronglyConnectedComponents } from './CycleDetector.js';
|
|
5
|
+
/** Deliberate, user-facing bundle validation failures; never raw storage errors. */
|
|
6
|
+
export class ProjectBundleError extends Error {
|
|
7
|
+
constructor(message, options) {
|
|
8
|
+
super(message, options);
|
|
9
|
+
this.name = 'ProjectBundleError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export const PROJECT_BUNDLE_MANIFEST = 'rivet-bundle.json';
|
|
13
|
+
export const PROJECT_BUNDLE_MAX_ARTIFACTS = 256;
|
|
14
|
+
export function projectBundleTargetKey(projectId, version) {
|
|
15
|
+
return JSON.stringify([projectId, version]);
|
|
16
|
+
}
|
|
17
|
+
function samePluginRequirement(left, right) {
|
|
18
|
+
if (left.id !== right.id || left.type !== right.type)
|
|
19
|
+
return false;
|
|
20
|
+
if (left.type === 'built-in')
|
|
21
|
+
return true; // Display names are not runtime identity.
|
|
22
|
+
if (left.type === 'package' && right.type === 'package')
|
|
23
|
+
return left.package === right.package && left.tag === right.tag;
|
|
24
|
+
return left.type === 'uri' && right.type === 'uri' && left.uri === right.uri;
|
|
25
|
+
}
|
|
26
|
+
function* projectSubgraphs(project) {
|
|
27
|
+
for (const [sourceGraphId, graph] of Object.entries(project.graphs)) {
|
|
28
|
+
for (const authored of graph.nodes) {
|
|
29
|
+
const node = resolveNodePrefabInstance(project, authored);
|
|
30
|
+
if (!node.disabled && node.type === 'nodePrefabInstance')
|
|
31
|
+
throw new ProjectBundleError(`Bundle contains an unresolved library node ${node.id}.`);
|
|
32
|
+
if (node.disabled || node.type !== 'subGraph')
|
|
33
|
+
continue;
|
|
34
|
+
const data = node.data;
|
|
35
|
+
if (data.targetProjectId) {
|
|
36
|
+
if (data.targetVersion !== undefined && data.targetVersion !== 'latest' && data.targetVersion !== 'published')
|
|
37
|
+
throw new ProjectBundleError('Invalid Subgraph project version.');
|
|
38
|
+
}
|
|
39
|
+
else if (data.targetScope === 'other-projects') {
|
|
40
|
+
throw new ProjectBundleError(`Subgraph ${node.title || node.id} has no selected project.`);
|
|
41
|
+
}
|
|
42
|
+
yield { sourceGraphId, data };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function listProjectBundleCalls(project) {
|
|
47
|
+
const calls = [];
|
|
48
|
+
for (const { data } of projectSubgraphs(project)) {
|
|
49
|
+
if (data.targetProjectId)
|
|
50
|
+
calls.push({
|
|
51
|
+
projectId: data.targetProjectId,
|
|
52
|
+
version: data.targetVersion ?? 'latest',
|
|
53
|
+
graphId: data.graphId,
|
|
54
|
+
boundary: data.targetBoundary,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return calls;
|
|
58
|
+
}
|
|
59
|
+
/** Uses the same saved wire contract as runtime execution, without running any nodes. */
|
|
60
|
+
export function validateProjectBundleCall(call, target) {
|
|
61
|
+
if (!Object.hasOwn(target.graphs, call.graphId))
|
|
62
|
+
throw new ProjectBundleError(`Subgraph dependency is missing graph ${call.graphId}.`);
|
|
63
|
+
const boundary = getGraphBoundary(target, call.graphId);
|
|
64
|
+
if (!boundary)
|
|
65
|
+
throw new ProjectBundleError(`Subgraph dependency is missing graph ${call.graphId}.`);
|
|
66
|
+
const issue = getSubgraphTargetBoundaryIssue(call.boundary, boundary);
|
|
67
|
+
if (issue)
|
|
68
|
+
throw new ProjectBundleError(`Subgraph dependency has an incompatible boundary. ${issue}`);
|
|
69
|
+
}
|
|
70
|
+
/** Reject missing bindings and cross-project dependency cycles before executing any graph. */
|
|
71
|
+
export function validateProjectBundleProjects(manifest, projects) {
|
|
72
|
+
const targets = new Map(manifest.targets.map((t) => [projectBundleTargetKey(t.projectId, t.version), t.artifact]));
|
|
73
|
+
const references = new Map(manifest.references.map((r) => [r.projectId, r.artifact]));
|
|
74
|
+
const plugins = new Map(manifest.plugins.map((plugin) => [plugin.id, plugin]));
|
|
75
|
+
const vertices = new Map();
|
|
76
|
+
const graphKey = (artifact, graph) => JSON.stringify([artifact, graph]);
|
|
77
|
+
for (const artifact of manifest.artifacts) {
|
|
78
|
+
const project = projects.get(artifact.id);
|
|
79
|
+
if (!project || project.metadata.id !== artifact.projectId)
|
|
80
|
+
throw new ProjectBundleError('Bundle project identity mismatch.');
|
|
81
|
+
for (const requirement of project.plugins ?? []) {
|
|
82
|
+
const declared = plugins.get(requirement.id);
|
|
83
|
+
if (!declared || !samePluginRequirement(declared, requirement))
|
|
84
|
+
throw new ProjectBundleError(`Bundle is missing the required plugin declaration ${requirement.id}.`);
|
|
85
|
+
}
|
|
86
|
+
for (const graphId of Object.keys(project.graphs))
|
|
87
|
+
vertices.set(graphKey(artifact.id, graphId), { edges: [] });
|
|
88
|
+
}
|
|
89
|
+
for (const artifact of manifest.artifacts) {
|
|
90
|
+
const project = projects.get(artifact.id);
|
|
91
|
+
for (const { sourceGraphId, data } of projectSubgraphs(project)) {
|
|
92
|
+
let targetId = artifact.id;
|
|
93
|
+
if (data.targetProjectId) {
|
|
94
|
+
const call = {
|
|
95
|
+
projectId: data.targetProjectId,
|
|
96
|
+
version: data.targetVersion ?? 'latest',
|
|
97
|
+
graphId: data.graphId,
|
|
98
|
+
boundary: data.targetBoundary,
|
|
99
|
+
};
|
|
100
|
+
const id = targets.get(projectBundleTargetKey(call.projectId, call.version));
|
|
101
|
+
const target = id && projects.get(id);
|
|
102
|
+
if (!id || !target)
|
|
103
|
+
throw new ProjectBundleError(`Bundle is missing Subgraph ${call.projectId}:${call.version}:${call.graphId}`);
|
|
104
|
+
validateProjectBundleCall(call, target);
|
|
105
|
+
targetId = id;
|
|
106
|
+
}
|
|
107
|
+
const target = vertices.get(graphKey(targetId, data.graphId));
|
|
108
|
+
if (target)
|
|
109
|
+
vertices.get(graphKey(artifact.id, sourceGraphId)).edges.push({
|
|
110
|
+
target,
|
|
111
|
+
crossProject: Boolean(data.targetProjectId),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
for (const reference of project.references ?? []) {
|
|
115
|
+
if (!references.has(reference.id))
|
|
116
|
+
throw new ProjectBundleError(`Bundle is missing referenced project ${reference.id}`);
|
|
117
|
+
}
|
|
118
|
+
for (const [sourceGraphId, graph] of Object.entries(project.graphs)) {
|
|
119
|
+
for (const authored of graph.nodes) {
|
|
120
|
+
const node = resolveNodePrefabInstance(project, authored);
|
|
121
|
+
if (node.disabled || node.type !== 'referencedGraphAlias')
|
|
122
|
+
continue;
|
|
123
|
+
const { projectId, graphId } = node.data;
|
|
124
|
+
const targetId = references.get(projectId);
|
|
125
|
+
const target = targetId && vertices.get(graphKey(targetId, graphId));
|
|
126
|
+
if (!target)
|
|
127
|
+
throw new ProjectBundleError(`Bundle is missing referenced graph ${projectId}:${graphId}`);
|
|
128
|
+
// Legacy-only recursion keeps its existing semantics, but aliases can
|
|
129
|
+
// participate in a cycle containing an explicit cross-project call.
|
|
130
|
+
vertices.get(graphKey(artifact.id, sourceGraphId)).edges.push({ target, crossProject: false });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// Project-level cycles can be legitimate: A/main → B/main → A/helper.
|
|
135
|
+
// Reject only a recursive graph-call component containing a cross-project edge.
|
|
136
|
+
for (const component of findStronglyConnectedComponents([...vertices.values()], (v) => v.edges.map((e) => e.target))) {
|
|
137
|
+
const members = new Set(component);
|
|
138
|
+
if (component.some((v) => v.edges.some((e) => e.crossProject && members.has(e.target))))
|
|
139
|
+
throw new ProjectBundleError('Subgraph cross-project dependency cycle in bundle.');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export function validateProjectBundleManifest(value) {
|
|
143
|
+
const fail = (message) => {
|
|
144
|
+
throw new ProjectBundleError(`Invalid project bundle: ${message}`);
|
|
145
|
+
};
|
|
146
|
+
const object = (v) => v !== null && typeof v === 'object' && !Array.isArray(v) ? v : fail('expected object');
|
|
147
|
+
const string = (v) => typeof v === 'string' && v.length > 0 && v.length <= 4096 ? v : fail('expected nonempty string');
|
|
148
|
+
const array = (v) => Array.isArray(v) && v.length <= PROJECT_BUNDLE_MAX_ARTIFACTS ? v : fail('invalid or oversized list');
|
|
149
|
+
const version = (v) => v === 'latest' || v === 'published' ? v : fail('unknown project version');
|
|
150
|
+
const paths = new Set();
|
|
151
|
+
const file = (v) => {
|
|
152
|
+
const obj = object(v), path = string(obj.path);
|
|
153
|
+
if (path.includes('\\') ||
|
|
154
|
+
path.includes(':') ||
|
|
155
|
+
path.includes('\0') ||
|
|
156
|
+
path.startsWith('/') ||
|
|
157
|
+
path.split('/').some((part) => !part || part === '.' || part === '..') ||
|
|
158
|
+
paths.has(path.toLowerCase()))
|
|
159
|
+
fail('unsafe or duplicate artifact path');
|
|
160
|
+
paths.add(path.toLowerCase());
|
|
161
|
+
if (!Number.isSafeInteger(obj.bytes) || obj.bytes < 0 || obj.bytes > 64 * 1024 * 1024)
|
|
162
|
+
fail('invalid artifact size (maximum 64 MiB per file)');
|
|
163
|
+
if (typeof obj.sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(obj.sha256))
|
|
164
|
+
fail('invalid checksum');
|
|
165
|
+
return { path, bytes: obj.bytes, sha256: obj.sha256 };
|
|
166
|
+
};
|
|
167
|
+
const obj = object(value);
|
|
168
|
+
if (obj.format !== 'rivet-project-bundle' || obj.schemaVersion !== 1 || obj.requiredLoaderVersion !== 1)
|
|
169
|
+
fail('unsupported format or loader version; update @valerypopoff/rivet2-node');
|
|
170
|
+
const artifacts = array(obj.artifacts).map((v) => {
|
|
171
|
+
const a = object(v);
|
|
172
|
+
return {
|
|
173
|
+
id: string(a.id),
|
|
174
|
+
projectId: string(a.projectId),
|
|
175
|
+
title: string(a.title),
|
|
176
|
+
version: version(a.version),
|
|
177
|
+
revision: string(a.revision),
|
|
178
|
+
project: file(a.project),
|
|
179
|
+
...(a.datasets === undefined ? {} : { datasets: file(a.datasets) }),
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
const byId = new Map(artifacts.map((a) => [a.id, a]));
|
|
183
|
+
if (!artifacts.length || byId.size !== artifacts.length)
|
|
184
|
+
fail('empty or duplicate artifacts');
|
|
185
|
+
if (new Set(artifacts.map((a) => projectBundleTargetKey(a.projectId, a.version))).size !== artifacts.length)
|
|
186
|
+
fail('duplicate project/version artifacts');
|
|
187
|
+
const rootArtifact = string(obj.rootArtifact);
|
|
188
|
+
if (!byId.has(rootArtifact))
|
|
189
|
+
fail('missing root artifact');
|
|
190
|
+
const targetKeys = new Set(), referenceIds = new Set();
|
|
191
|
+
const targets = array(obj.targets).map((v) => {
|
|
192
|
+
const t = object(v), projectId = string(t.projectId), selectedVersion = version(t.version), artifact = string(t.artifact);
|
|
193
|
+
const key = projectBundleTargetKey(projectId, selectedVersion), a = byId.get(artifact);
|
|
194
|
+
if (targetKeys.has(key) || !a || a.projectId !== projectId || a.version !== selectedVersion)
|
|
195
|
+
fail('invalid or duplicate target binding');
|
|
196
|
+
targetKeys.add(key);
|
|
197
|
+
return { projectId, version: selectedVersion, artifact };
|
|
198
|
+
});
|
|
199
|
+
const references = array(obj.references).map((v) => {
|
|
200
|
+
const r = object(v), projectId = string(r.projectId), artifact = string(r.artifact);
|
|
201
|
+
if (referenceIds.has(projectId) || byId.get(artifact)?.projectId !== projectId)
|
|
202
|
+
fail('invalid or duplicate reference binding');
|
|
203
|
+
referenceIds.add(projectId);
|
|
204
|
+
return { projectId, artifact };
|
|
205
|
+
});
|
|
206
|
+
const pluginSpecs = array(obj.plugins).map((v) => {
|
|
207
|
+
const p = object(v), id = string(p.id);
|
|
208
|
+
if (p.type === 'built-in')
|
|
209
|
+
return { type: p.type, id, name: string(p.name) };
|
|
210
|
+
if (p.type === 'package')
|
|
211
|
+
return { type: p.type, id, package: string(p.package), tag: string(p.tag) };
|
|
212
|
+
if (p.type === 'uri')
|
|
213
|
+
return { type: p.type, id, uri: string(p.uri) };
|
|
214
|
+
return fail('invalid plugin requirement');
|
|
215
|
+
});
|
|
216
|
+
const pluginsById = new Map();
|
|
217
|
+
for (const plugin of pluginSpecs) {
|
|
218
|
+
const previous = pluginsById.get(plugin.id);
|
|
219
|
+
if (previous && !samePluginRequirement(previous, plugin))
|
|
220
|
+
fail(`conflicting requirements for plugin ${plugin.id}`);
|
|
221
|
+
if (!previous)
|
|
222
|
+
pluginsById.set(plugin.id, plugin);
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
format: 'rivet-project-bundle',
|
|
226
|
+
schemaVersion: 1,
|
|
227
|
+
requiredLoaderVersion: 1,
|
|
228
|
+
exportingRuntimeVersion: string(obj.exportingRuntimeVersion),
|
|
229
|
+
rootArtifact,
|
|
230
|
+
artifacts,
|
|
231
|
+
targets,
|
|
232
|
+
references,
|
|
233
|
+
plugins: [...pluginsById.values()],
|
|
234
|
+
};
|
|
235
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { max, range } from 'lodash-es';
|
|
2
|
-
import { isArrayDataValue, arrayizeDataValue
|
|
2
|
+
import { isArrayDataValue, arrayizeDataValue } from './DataValue.js';
|
|
3
3
|
import {} from './NodeBase.js';
|
|
4
4
|
import { getGraphAbortReasonFromError, isAbortLikeError } from './GraphAbortReasons.js';
|
|
5
5
|
import { getError } from '../utils/errors.js';
|
|
@@ -84,7 +84,13 @@ async function runSequential(node, inputValues, inputDefinitionsById, splittingA
|
|
|
84
84
|
resultOrigin = 'editor-cache';
|
|
85
85
|
});
|
|
86
86
|
deps.accumulateCost(output);
|
|
87
|
-
results.push({
|
|
87
|
+
results.push({
|
|
88
|
+
type: 'output',
|
|
89
|
+
index: i,
|
|
90
|
+
output,
|
|
91
|
+
resultOrigin,
|
|
92
|
+
durationMs: deps.finishNodeTiming?.(splitTimingStart),
|
|
93
|
+
});
|
|
88
94
|
}
|
|
89
95
|
catch (error) {
|
|
90
96
|
results.push({
|
|
@@ -183,13 +189,28 @@ function splitInputsAtIndex(inputValues, inputDefinitionsById, index) {
|
|
|
183
189
|
]));
|
|
184
190
|
}
|
|
185
191
|
function aggregateOutputs(results) {
|
|
186
|
-
|
|
192
|
+
const ports = new Map();
|
|
193
|
+
results.forEach((result, index) => {
|
|
187
194
|
for (const [portId, value] of entries(result.output)) {
|
|
188
|
-
|
|
189
|
-
|
|
195
|
+
const id = portId;
|
|
196
|
+
const aggregate = ports.get(id) ?? { values: [] };
|
|
197
|
+
// Exclusion is not a value type. Infer from a real item regardless of
|
|
198
|
+
// whether the first split item succeeded or returned a caught failure.
|
|
199
|
+
if (value?.type !== 'control-flow-excluded')
|
|
200
|
+
aggregate.type ??= value?.type;
|
|
201
|
+
aggregate.values[index] = value?.value;
|
|
202
|
+
ports.set(id, aggregate);
|
|
190
203
|
}
|
|
191
|
-
|
|
192
|
-
|
|
204
|
+
});
|
|
205
|
+
return fromEntries([...ports].map(([id, aggregate]) => [
|
|
206
|
+
id,
|
|
207
|
+
aggregate.type == null
|
|
208
|
+
? { type: 'control-flow-excluded', value: undefined }
|
|
209
|
+
: {
|
|
210
|
+
type: `${aggregate.type}[]`,
|
|
211
|
+
value: Array.from({ length: results.length }, (_, index) => aggregate.values[index]),
|
|
212
|
+
},
|
|
213
|
+
]));
|
|
193
214
|
}
|
|
194
215
|
function isSplitOutputResult(result) {
|
|
195
216
|
return result.type === 'output';
|
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
import { canRenderDataBusNode, getDataBusInputChannelIndex, getDataBusOutputChannelIndex } from './DataBusTopology.js';
|
|
2
2
|
import { resolveNodePrefabInstance } from './NodePrefabResolver.js';
|
|
3
|
+
import { getSubgraphTargetBoundaryChange, reconcileSubgraphTargetBoundary } from './nodes/SubGraphNode.js';
|
|
4
|
+
import { getGraphBoundary } from './GraphBoundaryCache.js';
|
|
3
5
|
import { createGraphOutputSelection } from './GraphOutputSelection.js';
|
|
6
|
+
import { getSubgraphProjectKey } from './SubgraphProjectTarget.js';
|
|
7
|
+
import { nanoid } from 'nanoid/non-secure';
|
|
8
|
+
/** Only ports that can publish live partials receive streaming wire markers. */
|
|
9
|
+
function canEmitStreamingOutput(node, outputId) {
|
|
10
|
+
const data = node.data;
|
|
11
|
+
switch (node.type) {
|
|
12
|
+
case 'streamValue':
|
|
13
|
+
return outputId === 'value';
|
|
14
|
+
case 'llmChatV2':
|
|
15
|
+
return data.useAsGraphPartialOutput === true &&
|
|
16
|
+
['response', 'in-messages', 'all-messages', 'function-calls', 'reasoning'].includes(outputId);
|
|
17
|
+
case 'chatAnthropic':
|
|
18
|
+
return ['response', 'all-messages', 'function-calls', 'citations'].includes(outputId);
|
|
19
|
+
case 'chatGoogle':
|
|
20
|
+
return ['response', 'function-calls'].includes(outputId);
|
|
21
|
+
case 'chatHuggingFace':
|
|
22
|
+
return outputId === 'output';
|
|
23
|
+
case 'loopUntil':
|
|
24
|
+
return outputId !== 'iteration' && outputId !== 'completed';
|
|
25
|
+
default:
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function getCallerProject(owner, caller, projects) {
|
|
30
|
+
if (caller.type === 'referencedGraphAlias')
|
|
31
|
+
return projects[caller.data.projectId];
|
|
32
|
+
if (!caller.data.targetProjectId)
|
|
33
|
+
return owner;
|
|
34
|
+
return projects[getSubgraphProjectKey({
|
|
35
|
+
projectId: caller.data.targetProjectId,
|
|
36
|
+
version: caller.data.targetVersion ?? 'latest',
|
|
37
|
+
})];
|
|
38
|
+
}
|
|
39
|
+
function getCallerBoundary(caller, target) {
|
|
40
|
+
if (caller.type !== 'subGraph')
|
|
41
|
+
return undefined;
|
|
42
|
+
const actual = getGraphBoundary(target, caller.data.graphId);
|
|
43
|
+
if (!actual || getSubgraphTargetBoundaryChange(caller.data.targetBoundary, actual))
|
|
44
|
+
return undefined;
|
|
45
|
+
return reconcileSubgraphTargetBoundary(caller.data.targetBoundary, actual);
|
|
46
|
+
}
|
|
4
47
|
/** An executing caller may forward outputs after its condition has passed. */
|
|
5
48
|
export function canForwardGraphCallerOutputPartials(node) {
|
|
6
49
|
return ((node.type === 'subGraph' || node.type === 'referencedGraphAlias') &&
|
|
@@ -29,7 +72,7 @@ export function canForwardGraphOutputPartials(graphOutput, sourceNode, graphOutp
|
|
|
29
72
|
!graphOutputIsFrozen);
|
|
30
73
|
}
|
|
31
74
|
/** Trace Watch demand through named boundaries without making ordinary nodes repeatable. */
|
|
32
|
-
export function getProjectStreamingOutputWatchConnections({ project, graph, referencedProjects, registry, frozenNodeOutputs = {}, isNodeFrozen, fullGraphCallers, }) {
|
|
75
|
+
export function getProjectStreamingOutputWatchConnections({ project, graph, referencedProjects, registry, frozenNodeOutputs = {}, isNodeFrozen, fullGraphCallers, getPreviewGraphOutputStreamingCapability, onlyStreamCapableSources = false, }) {
|
|
33
76
|
// Unsaved active graph edits must take precedence over the stored project graph.
|
|
34
77
|
const currentProject = {
|
|
35
78
|
...project,
|
|
@@ -96,7 +139,7 @@ export function getProjectStreamingOutputWatchConnections({ project, graph, refe
|
|
|
96
139
|
if (node.disabled || isFrozen(context.project, parent, node) || !canStreamThroughGraphCaller(node))
|
|
97
140
|
continue;
|
|
98
141
|
const caller = node;
|
|
99
|
-
const owner =
|
|
142
|
+
const owner = getCallerProject(context.project, caller, projects);
|
|
100
143
|
const child = owner?.graphs[caller.data.graphId];
|
|
101
144
|
if (!child)
|
|
102
145
|
continue;
|
|
@@ -106,12 +149,13 @@ export function getProjectStreamingOutputWatchConnections({ project, graph, refe
|
|
|
106
149
|
!caller.data.useAsGraphPartialOutput &&
|
|
107
150
|
!(parent === graph && fullGraphCallers?.has(caller.id))) {
|
|
108
151
|
const childContext = contexts.get(child);
|
|
152
|
+
const callerBoundary = getCallerBoundary(caller, owner);
|
|
109
153
|
const outputNames = new Set(Object.values(childContext.nodes)
|
|
110
154
|
.filter((node) => node.type === 'graphOutput')
|
|
111
155
|
.map((node) => node.data.id));
|
|
112
156
|
const outputs = parent.connections
|
|
113
157
|
.filter((edge) => edge.outputNodeId === caller.id)
|
|
114
|
-
.map((edge) => edge.outputId)
|
|
158
|
+
.map((edge) => callerBoundary?.outputs.find((output) => output.portId === edge.outputId)?.id ?? edge.outputId)
|
|
115
159
|
.filter((id) => outputNames.has(id));
|
|
116
160
|
try {
|
|
117
161
|
selected = createGraphOutputSelection({ ...child, nodes: Object.values(childContext.nodes) }, outputs, (node) => childContext.incoming(node.id).map((edge) => childContext.nodes[edge.outputNodeId])).nodeIds;
|
|
@@ -128,7 +172,9 @@ export function getProjectStreamingOutputWatchConnections({ project, graph, refe
|
|
|
128
172
|
const watchInputs = [];
|
|
129
173
|
for (const [candidate, context] of contexts) {
|
|
130
174
|
for (const node of Object.values(context.nodes)) {
|
|
131
|
-
if (node.type !== 'watchStreamingOutput'
|
|
175
|
+
if ((node.type !== 'watchStreamingOutput' && node.type !== 'catchStreamingChunks') ||
|
|
176
|
+
node.disabled ||
|
|
177
|
+
isFrozen(context.project, candidate, node))
|
|
132
178
|
continue;
|
|
133
179
|
const inputs = context.incoming(node.id).filter((edge) => edge.inputId === 'stream');
|
|
134
180
|
// Multiple providers are rejected by the Watch scheduler, not multiple streams.
|
|
@@ -170,10 +216,11 @@ export function getProjectStreamingOutputWatchConnections({ project, graph, refe
|
|
|
170
216
|
for (const parent of callers.get(candidate) ?? []) {
|
|
171
217
|
if (parent.selected && !parent.selected.has(edge.inputNodeId))
|
|
172
218
|
continue;
|
|
219
|
+
const callerPortId = getCallerBoundary(parent.node, context.project)?.inputs.find((input) => input.nodeId === source.id)?.portId ?? inputName;
|
|
173
220
|
const inputs = contexts
|
|
174
221
|
.get(parent.graph)
|
|
175
222
|
.incoming(parent.node.id)
|
|
176
|
-
.filter((input) => input.inputId ===
|
|
223
|
+
.filter((input) => input.inputId === callerPortId);
|
|
177
224
|
// Ambiguous authored inputs stay final-only even though ordinary
|
|
178
225
|
// execution retains its established first-provider projection.
|
|
179
226
|
if (inputs.length === 1 && trace(parent.graph, inputs[0]))
|
|
@@ -185,23 +232,35 @@ export function getProjectStreamingOutputWatchConnections({ project, graph, refe
|
|
|
185
232
|
return true;
|
|
186
233
|
}
|
|
187
234
|
if (source.type !== 'subGraph' && source.type !== 'referencedGraphAlias') {
|
|
235
|
+
if (onlyStreamCapableSources && !canEmitStreamingOutput(source, edge.outputId))
|
|
236
|
+
return false;
|
|
188
237
|
context.marked.add(edge);
|
|
189
238
|
return true;
|
|
190
239
|
}
|
|
191
240
|
if (!canForwardGraphCallerOutputPartials(source))
|
|
192
241
|
return false;
|
|
193
242
|
const caller = source;
|
|
194
|
-
const childProject =
|
|
243
|
+
const childProject = getCallerProject(context.project, caller, projects);
|
|
195
244
|
const child = childProject?.graphs[caller.data.graphId];
|
|
196
245
|
const childContext = child && contexts.get(child);
|
|
197
|
-
if (!child || !childContext)
|
|
246
|
+
if (!childProject || !child || !childContext)
|
|
198
247
|
return false;
|
|
199
|
-
const
|
|
248
|
+
const targetOutputId = getCallerBoundary(caller, childProject)?.outputs.find((output) => output.portId === edge.outputId)?.id ??
|
|
249
|
+
edge.outputId;
|
|
250
|
+
const outputs = Object.values(childContext.nodes).filter((node) => node.type === 'graphOutput' && !node.disabled && node.data.id === targetOutputId);
|
|
200
251
|
// Duplicate names have first-final-winner semantics, so cannot relay partials.
|
|
201
252
|
if (outputs.length !== 1)
|
|
202
253
|
return false;
|
|
203
254
|
const output = outputs[0];
|
|
204
255
|
const outputIsFrozen = isFrozen(childProject, child, output);
|
|
256
|
+
const previewCapability = getPreviewGraphOutputStreamingCapability?.(childProject, child, output.id);
|
|
257
|
+
if (previewCapability !== undefined) {
|
|
258
|
+
if (previewCapability && !outputIsFrozen && !output.isConditional && !output.isSplitRun) {
|
|
259
|
+
context.marked.add(edge);
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
205
264
|
const providers = childContext.incoming(output.id).filter((input) => input.inputId === 'value');
|
|
206
265
|
// As in GraphProcessor's effective connection projection, the first
|
|
207
266
|
// valid provider owns a single-input Graph Output in a malformed graph.
|
|
@@ -226,3 +285,54 @@ export function getProjectStreamingOutputWatchConnections({ project, graph, refe
|
|
|
226
285
|
trace(candidate, edge);
|
|
227
286
|
return contexts.get(graph)?.marked ?? new Set();
|
|
228
287
|
}
|
|
288
|
+
/** Derive safe boundary capability hints for every graph in one topology pass. */
|
|
289
|
+
export function getProjectStreamableGraphOutputNodeIdsByGraph({ project, referencedProjects, registry, }) {
|
|
290
|
+
// Graph IDs come from project files; keep unusual keys such as __proto__
|
|
291
|
+
// as data rather than assigning through Object.prototype.
|
|
292
|
+
const result = Object.create(null);
|
|
293
|
+
const nodes = [];
|
|
294
|
+
const probes = [];
|
|
295
|
+
for (const [graphId] of Object.entries(project.graphs)) {
|
|
296
|
+
result[graphId] = [];
|
|
297
|
+
const boundary = getGraphBoundary(project, graphId);
|
|
298
|
+
if (!boundary?.outputs.length)
|
|
299
|
+
continue;
|
|
300
|
+
const callerId = nanoid();
|
|
301
|
+
nodes.push({ id: callerId, type: 'subGraph', title: 'Probe', data: { graphId }, visualData: { x: 0, y: 0 } });
|
|
302
|
+
for (const output of boundary.outputs) {
|
|
303
|
+
const watchId = nanoid();
|
|
304
|
+
nodes.push({ id: watchId, type: 'watchStreamingOutput', title: 'Probe watch', data: {}, visualData: { x: 0, y: 0 } });
|
|
305
|
+
probes.push({
|
|
306
|
+
graphId,
|
|
307
|
+
outputNodeId: output.nodeId,
|
|
308
|
+
connection: {
|
|
309
|
+
outputNodeId: callerId,
|
|
310
|
+
outputId: output.portId,
|
|
311
|
+
inputNodeId: watchId,
|
|
312
|
+
inputId: 'stream',
|
|
313
|
+
},
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (probes.length === 0)
|
|
318
|
+
return result;
|
|
319
|
+
const probeGraphId = nanoid();
|
|
320
|
+
const probeGraph = {
|
|
321
|
+
metadata: { id: probeGraphId, name: 'Streaming preview probe' },
|
|
322
|
+
nodes,
|
|
323
|
+
connections: probes.map(({ connection }) => connection),
|
|
324
|
+
};
|
|
325
|
+
const probeProject = { ...project, graphs: { ...project.graphs, [probeGraphId]: probeGraph } };
|
|
326
|
+
const marked = getProjectStreamingOutputWatchConnections({
|
|
327
|
+
project: probeProject,
|
|
328
|
+
graph: probeGraph,
|
|
329
|
+
referencedProjects,
|
|
330
|
+
registry,
|
|
331
|
+
onlyStreamCapableSources: true,
|
|
332
|
+
});
|
|
333
|
+
for (const { graphId, outputNodeId, connection } of probes) {
|
|
334
|
+
if (marked.has(connection))
|
|
335
|
+
result[graphId].push(outputNodeId);
|
|
336
|
+
}
|
|
337
|
+
return result;
|
|
338
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Internal definition key; not a project metadata ID or a persisted reference. */
|
|
2
|
+
export function getSubgraphProjectKey(target) {
|
|
3
|
+
return `\u0000rivet-subgraph:${target.version}:${encodeURIComponent(target.projectId)}`;
|
|
4
|
+
}
|
|
5
|
+
export function isSubgraphProjectKey(key) {
|
|
6
|
+
return key.startsWith('\u0000rivet-subgraph:');
|
|
7
|
+
}
|
|
@@ -2,6 +2,7 @@ import { generateText, NoObjectGeneratedError, streamText } from 'ai';
|
|
|
2
2
|
import { consumeAiSdkStream } from '../chat/aiSdkStreaming.js';
|
|
3
3
|
import { ChatV2ProviderTimeoutError } from './chatV2Types.js';
|
|
4
4
|
import { isChatV2StructuredResponseFormat } from './chatV2ResponseFormat.js';
|
|
5
|
+
import { normalizeTemperature } from './temperature.js';
|
|
5
6
|
function keepPromiseHandled(value) {
|
|
6
7
|
const promise = Promise.resolve(value);
|
|
7
8
|
void promise.catch(() => undefined);
|
|
@@ -130,8 +131,9 @@ function buildTextArgs(options) {
|
|
|
130
131
|
args.tools = options.tools;
|
|
131
132
|
if (options.maxTokens !== undefined)
|
|
132
133
|
args.maxOutputTokens = options.maxTokens;
|
|
133
|
-
|
|
134
|
-
|
|
134
|
+
const temperature = normalizeTemperature(options.temperature);
|
|
135
|
+
if (temperature !== undefined)
|
|
136
|
+
args.temperature = temperature;
|
|
135
137
|
if (options.topP !== undefined)
|
|
136
138
|
args.topP = options.topP;
|
|
137
139
|
if (options.topK !== undefined)
|
|
@@ -196,10 +198,10 @@ async function* streamWithDeadlines(stream, options, firstOutputStartedAt) {
|
|
|
196
198
|
for (;;) {
|
|
197
199
|
const kind = hasUsefulOutput ? 'stream-inactivity' : 'first-output';
|
|
198
200
|
const configuredTimeout = hasUsefulOutput ? options.streamInactivityTimeoutMs : options.firstOutputTimeoutMs;
|
|
199
|
-
const timeoutMs = configuredTimeout == null
|
|
201
|
+
const timeoutMs = configuredTimeout == null ? undefined : Math.max(1, configuredTimeout - (Date.now() - lastUsefulOutputAt));
|
|
202
|
+
const timeout = timeoutMs == null
|
|
200
203
|
? undefined
|
|
201
|
-
:
|
|
202
|
-
const timeout = timeoutMs == null ? undefined : timeoutPromise(timeoutMs, kind, options.onTimeout);
|
|
204
|
+
: timeoutPromise(timeoutMs, kind, options.onTimeout);
|
|
203
205
|
let next;
|
|
204
206
|
try {
|
|
205
207
|
next = await (timeout == null ? iterator.next() : Promise.race([iterator.next(), timeout.promise]));
|
|
@@ -5,9 +5,9 @@ import { chatMessagesToModelMessages } from './messageConverter.js';
|
|
|
5
5
|
import { isChatV2ProviderTimeoutError } from './chatV2Types.js';
|
|
6
6
|
import { chatV2ToolsToAiSdk } from './toolConverter.js';
|
|
7
7
|
import { buildChatV2RequestPlan } from './chatV2RequestPlan.js';
|
|
8
|
-
import { getChatV2ProviderErrorStatusCode, normalizeChatV2ProviderError
|
|
8
|
+
import { getChatV2ProviderErrorStatusCode, normalizeChatV2ProviderError } from './chatV2Errors.js';
|
|
9
9
|
import { createLLMChatV2RetryAbortError, waitForLLMChatV2RetryCooldown } from './chatV2Retry.js';
|
|
10
|
-
import { createChatV2CommonOutputs, normalizeChatV2Usage
|
|
10
|
+
import { createChatV2CommonOutputs, normalizeChatV2Usage } from './chatV2Outputs.js';
|
|
11
11
|
import { materializeLLMResponse } from './llmResponseMaterializer.js';
|
|
12
12
|
/** Identifies legacy pipeline results that represent a terminal provider failure. */
|
|
13
13
|
export function isChatV2PipelineProviderFailureResult(result) {
|
|
@@ -64,6 +64,7 @@ async function runChatV2WithRetry(options, chatOptions, retryPlan, signal, trans
|
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
66
|
for (let attempt = 0;; attempt++) {
|
|
67
|
+
signal.throwIfAborted();
|
|
67
68
|
const callId = createObservedChatV2CallId(options);
|
|
68
69
|
const callStartedAt = Date.now();
|
|
69
70
|
let callWasObserved = false;
|
|
@@ -115,13 +116,16 @@ async function runChatV2WithRetry(options, chatOptions, retryPlan, signal, trans
|
|
|
115
116
|
const result = transportMode === 'generate'
|
|
116
117
|
? await generateChatV2(attemptChatOptions)
|
|
117
118
|
: await streamChatV2(attemptChatOptions);
|
|
119
|
+
signal.throwIfAborted();
|
|
118
120
|
await options.responseBodyCapture?.flush();
|
|
121
|
+
signal.throwIfAborted();
|
|
119
122
|
publishAndRetireResponseEvidence();
|
|
120
123
|
const statusCode = result.requestStatus ?? 200;
|
|
124
|
+
const statusSucceeded = statusCode >= 200 && statusCode < 300;
|
|
121
125
|
notifyChatV2CallFinished(options, {
|
|
122
126
|
callId,
|
|
123
127
|
attemptIndex: attempt,
|
|
124
|
-
outcome:
|
|
128
|
+
outcome: statusSucceeded ? 'success' : 'provider-failure',
|
|
125
129
|
result,
|
|
126
130
|
startedAt: callStartedAt,
|
|
127
131
|
durationMs: Math.max(0, Date.now() - callStartedAt),
|
|
@@ -129,16 +133,16 @@ async function runChatV2WithRetry(options, chatOptions, retryPlan, signal, trans
|
|
|
129
133
|
callWasObserved = true;
|
|
130
134
|
notifyProviderAttempt(options, {
|
|
131
135
|
attemptIndex: attempt,
|
|
132
|
-
outcome:
|
|
136
|
+
outcome: statusSucceeded ? 'success' : 'provider-failure',
|
|
133
137
|
status: statusCode,
|
|
134
|
-
...(
|
|
138
|
+
...(statusSucceeded ? {} : { error: buildNon200StatusError(statusCode) }),
|
|
135
139
|
});
|
|
136
140
|
if (!retryPlan.enabled || statusCode === 200) {
|
|
137
141
|
return { result };
|
|
138
142
|
}
|
|
139
143
|
const responseError = buildNon200StatusError(statusCode);
|
|
140
144
|
if (attempt >= retryPlan.repeatTimes) {
|
|
141
|
-
return { result, responseError };
|
|
145
|
+
return { result, ...(statusSucceeded ? {} : { responseError }) };
|
|
142
146
|
}
|
|
143
147
|
await prepareProviderRetry();
|
|
144
148
|
await waitForLLMChatV2RetryCooldown(retryPlan.cooldownMs, signal);
|
|
@@ -172,7 +176,7 @@ async function runChatV2WithRetry(options, chatOptions, retryPlan, signal, trans
|
|
|
172
176
|
// The provider may reject concurrently with graph cancellation. The
|
|
173
177
|
// cancellation wins: it must neither retry nor masquerade as a
|
|
174
178
|
// provider failure to profile fallback and run activity.
|
|
175
|
-
throw createLLMChatV2RetryAbortError();
|
|
179
|
+
throw signal.reason ?? createLLMChatV2RetryAbortError();
|
|
176
180
|
}
|
|
177
181
|
if (isChatV2ProviderTimeoutError(error) || !retryPlan.enabled || statusCode == null || statusCode === 200) {
|
|
178
182
|
throw error;
|
|
@@ -322,7 +326,8 @@ export async function runChatV2PipelineExecution(options) {
|
|
|
322
326
|
providerMetadata: chatResponse.result.providerMetadata,
|
|
323
327
|
requestStatus,
|
|
324
328
|
};
|
|
325
|
-
const providerRoundFailure = chatResponse.responseError ??
|
|
329
|
+
const providerRoundFailure = chatResponse.responseError ??
|
|
330
|
+
(requestStatus >= 200 && requestStatus < 300 ? undefined : buildNon200StatusError(requestStatus));
|
|
326
331
|
if (providerRoundFailure != null) {
|
|
327
332
|
const rawError = providerRoundFailure;
|
|
328
333
|
return {
|
|
@@ -5,6 +5,7 @@ import { cleanHeaders, getInputOrData } from '../../utils/inputs.js';
|
|
|
5
5
|
import { cloneRivetStoredValue } from '../StoredValueStore.js';
|
|
6
6
|
import { resolveChatV2Credential } from './chatV2ProviderProfile.js';
|
|
7
7
|
import { applyLLMChatV2ParallelToolCallProviderOptions } from './parallelToolCalls.js';
|
|
8
|
+
import { normalizeTemperature } from './temperature.js';
|
|
8
9
|
export function resolveLLMChatV2Headers(data, inputs) {
|
|
9
10
|
const resolvedHeaders = data.useHeadersInput && inputs['headers'] != null
|
|
10
11
|
? coerceTypeOptional(inputs['headers'], 'object')
|
|
@@ -159,9 +160,26 @@ function resolveStopSequences(data, inputs) {
|
|
|
159
160
|
return normalizeStopSequences(stopSequences);
|
|
160
161
|
}
|
|
161
162
|
export function resolveLLMChatV2GenerationParameters(data, inputs) {
|
|
163
|
+
const temperatureInput = data.useTemperatureInput ? inputs['temperature'] : undefined;
|
|
164
|
+
let temperature;
|
|
165
|
+
if (temperatureInput != null) {
|
|
166
|
+
const resolved = temperatureInput.type === 'string'
|
|
167
|
+
? temperatureInput.value.trim() === ''
|
|
168
|
+
? undefined
|
|
169
|
+
: Number(temperatureInput.value)
|
|
170
|
+
: coerceTypeOptional(temperatureInput, 'number');
|
|
171
|
+
// A connected malformed input must not silently fall back to node data.
|
|
172
|
+
if (typeof resolved !== 'number' || !Number.isFinite(resolved)) {
|
|
173
|
+
throw new Error('Temperature input must be a finite number.');
|
|
174
|
+
}
|
|
175
|
+
temperature = resolved;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
temperature = normalizeTemperature(data.temperature);
|
|
179
|
+
}
|
|
162
180
|
return {
|
|
163
181
|
maxTokens: getInputOrData(data, inputs, 'maxTokens', 'number'),
|
|
164
|
-
temperature
|
|
182
|
+
temperature,
|
|
165
183
|
topP: getInputOrData(data, inputs, 'topP', 'number'),
|
|
166
184
|
topK: getInputOrData(data, inputs, 'topK', 'number'),
|
|
167
185
|
presencePenalty: getInputOrData(data, inputs, 'presencePenalty', 'number'),
|
|
@@ -179,9 +179,10 @@ export function getCommonChatV2Editors(modelOptions) {
|
|
|
179
179
|
{
|
|
180
180
|
type: 'number',
|
|
181
181
|
label: 'Temperature',
|
|
182
|
-
helperMessage: '
|
|
182
|
+
helperMessage: 'Leave blank to use the provider default. Some reasoning models may ignore this setting.',
|
|
183
183
|
dataKey: 'temperature',
|
|
184
184
|
useInputToggleDataKey: 'useTemperatureInput',
|
|
185
|
+
allowEmpty: true,
|
|
185
186
|
min: 0,
|
|
186
187
|
max: 2,
|
|
187
188
|
step: 0.1,
|