@valerypopoff/rivet2-core 2.0.1 → 2.0.2
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 +153 -39
- package/dist/cjs/bundle.cjs.map +2 -2
- package/dist/esm/model/SubprocessorBridge.js +29 -19
- package/dist/esm/model/chat-v2/chatV2Pipeline.js +25 -9
- package/dist/esm/model/chat-v2/chatV2ResponseFormat.js +71 -1
- package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +2 -2
- package/dist/esm/model/chat-v2/toolContinuation.js +4 -1
- package/dist/esm/model/nodes/ContextNode.js +19 -8
- package/dist/esm/plugins/gentrace/plugin.js +4 -3
- package/dist/types/model/chat-v2/chatV2ResponseFormat.d.ts +2 -1
- package/dist/types/plugins/gentrace/plugin.d.ts +2 -1
- package/package.json +1 -1
package/dist/cjs/bundle.cjs
CHANGED
|
@@ -301,6 +301,7 @@ __export(src_exports, {
|
|
|
301
301
|
mcpDiscoveryNode: () => mcpDiscoveryNode,
|
|
302
302
|
mcpGetPromptNode: () => mcpGetPromptNode,
|
|
303
303
|
mcpToolCallNode: () => mcpToolCallNode,
|
|
304
|
+
mergeCustomProviderResponseFormatOptions: () => mergeCustomProviderResponseFormatOptions,
|
|
304
305
|
newId: () => newId,
|
|
305
306
|
nodeDefinition: () => nodeDefinition,
|
|
306
307
|
numberNode: () => numberNode,
|
|
@@ -651,6 +652,7 @@ __export(exports_exports, {
|
|
|
651
652
|
mcpDiscoveryNode: () => mcpDiscoveryNode,
|
|
652
653
|
mcpGetPromptNode: () => mcpGetPromptNode,
|
|
653
654
|
mcpToolCallNode: () => mcpToolCallNode,
|
|
655
|
+
mergeCustomProviderResponseFormatOptions: () => mergeCustomProviderResponseFormatOptions,
|
|
654
656
|
newId: () => newId,
|
|
655
657
|
nodeDefinition: () => nodeDefinition,
|
|
656
658
|
numberNode: () => numberNode,
|
|
@@ -2874,6 +2876,26 @@ function isControlFlowExcluded(value) {
|
|
|
2874
2876
|
}
|
|
2875
2877
|
|
|
2876
2878
|
// src/model/SubprocessorBridge.ts
|
|
2879
|
+
function subscribeOwnGraphRunLifecycle(processor, onLifecycleEvent) {
|
|
2880
|
+
let ownGraphRunId;
|
|
2881
|
+
const unsubscribeGraphStart = processor.on("graphStart", (event) => {
|
|
2882
|
+
ownGraphRunId ??= event.execution.graphRunId;
|
|
2883
|
+
});
|
|
2884
|
+
const onPossibleLifecycleEvent = (event) => {
|
|
2885
|
+
if (ownGraphRunId != null && event.execution.graphRunId === ownGraphRunId) {
|
|
2886
|
+
onLifecycleEvent();
|
|
2887
|
+
}
|
|
2888
|
+
};
|
|
2889
|
+
const unsubscribeGraphFinish = processor.on("graphFinish", onPossibleLifecycleEvent);
|
|
2890
|
+
const unsubscribeGraphAbort = processor.on("graphAbort", onPossibleLifecycleEvent);
|
|
2891
|
+
const unsubscribeGraphError = processor.on("graphError", onPossibleLifecycleEvent);
|
|
2892
|
+
return () => {
|
|
2893
|
+
unsubscribeGraphStart();
|
|
2894
|
+
unsubscribeGraphFinish();
|
|
2895
|
+
unsubscribeGraphAbort();
|
|
2896
|
+
unsubscribeGraphError();
|
|
2897
|
+
};
|
|
2898
|
+
}
|
|
2877
2899
|
function wireSubprocessorEvents(processor, parentEmitter, parentState) {
|
|
2878
2900
|
const unsubscribers = [
|
|
2879
2901
|
processor.on("nodeError", (event) => parentEmitter.emit("nodeError", event)),
|
|
@@ -2912,14 +2934,8 @@ function wireSubprocessorEvents(processor, parentEmitter, parentState) {
|
|
|
2912
2934
|
}
|
|
2913
2935
|
cleanedUp = true;
|
|
2914
2936
|
unsubscribers.forEach((unsubscribe) => unsubscribe());
|
|
2915
|
-
unsubscribeAny();
|
|
2916
|
-
unsubscribeGraphFinish();
|
|
2917
|
-
unsubscribeGraphAbort();
|
|
2918
|
-
unsubscribeGraphError();
|
|
2919
2937
|
};
|
|
2920
|
-
|
|
2921
|
-
const unsubscribeGraphAbort = processor.on("graphAbort", cleanup);
|
|
2922
|
-
const unsubscribeGraphError = processor.on("graphError", cleanup);
|
|
2938
|
+
unsubscribers.push(unsubscribeAny, subscribeOwnGraphRunLifecycle(processor, cleanup));
|
|
2923
2939
|
}
|
|
2924
2940
|
function wireSubprocessorLifecycle(processor, options2) {
|
|
2925
2941
|
var _a;
|
|
@@ -2937,26 +2953,24 @@ function wireSubprocessorLifecycle(processor, options2) {
|
|
|
2937
2953
|
};
|
|
2938
2954
|
(_a = options2.signal) == null ? void 0 : _a.addEventListener("abort", abortFromSignal, { once: true });
|
|
2939
2955
|
options2.parentAbortSignal.addEventListener("abort", abortFromParent, { once: true });
|
|
2940
|
-
const
|
|
2941
|
-
|
|
2956
|
+
const unsubscribers = [
|
|
2957
|
+
() => {
|
|
2958
|
+
var _a2;
|
|
2959
|
+
return (_a2 = options2.signal) == null ? void 0 : _a2.removeEventListener("abort", abortFromSignal);
|
|
2960
|
+
},
|
|
2961
|
+
() => options2.parentAbortSignal.removeEventListener("abort", abortFromParent),
|
|
2962
|
+
options2.onParentPause(pauseProcessor),
|
|
2963
|
+
options2.onParentResume(resumeProcessor)
|
|
2964
|
+
];
|
|
2942
2965
|
let cleanedUp = false;
|
|
2943
2966
|
const cleanup = () => {
|
|
2944
|
-
var _a2;
|
|
2945
2967
|
if (cleanedUp) {
|
|
2946
2968
|
return;
|
|
2947
2969
|
}
|
|
2948
2970
|
cleanedUp = true;
|
|
2949
|
-
(
|
|
2950
|
-
options2.parentAbortSignal.removeEventListener("abort", abortFromParent);
|
|
2951
|
-
unsubscribeParentPause();
|
|
2952
|
-
unsubscribeParentResume();
|
|
2953
|
-
unsubscribeGraphFinish();
|
|
2954
|
-
unsubscribeGraphAbort();
|
|
2955
|
-
unsubscribeGraphError();
|
|
2971
|
+
unsubscribers.forEach((unsubscribe) => unsubscribe());
|
|
2956
2972
|
};
|
|
2957
|
-
|
|
2958
|
-
const unsubscribeGraphAbort = processor.on("graphAbort", cleanup);
|
|
2959
|
-
const unsubscribeGraphError = processor.on("graphError", cleanup);
|
|
2973
|
+
unsubscribers.push(subscribeOwnGraphRunLifecycle(processor, cleanup));
|
|
2960
2974
|
}
|
|
2961
2975
|
|
|
2962
2976
|
// src/integrations/CodeRunner.ts
|
|
@@ -8412,6 +8426,40 @@ function normalizeOptionalString(value) {
|
|
|
8412
8426
|
const trimmed = value == null ? void 0 : value.trim();
|
|
8413
8427
|
return trimmed ? trimmed : void 0;
|
|
8414
8428
|
}
|
|
8429
|
+
function toJsonValue(value, path = "Response Schema", seen = /* @__PURE__ */ new WeakSet()) {
|
|
8430
|
+
if (value === void 0) {
|
|
8431
|
+
throw new Error(`${path} must be JSON-compatible; undefined values are not supported.`);
|
|
8432
|
+
}
|
|
8433
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") {
|
|
8434
|
+
return value;
|
|
8435
|
+
}
|
|
8436
|
+
if (typeof value === "number") {
|
|
8437
|
+
if (!Number.isFinite(value)) {
|
|
8438
|
+
throw new Error(`${path} must be JSON-compatible; non-finite numbers are not supported.`);
|
|
8439
|
+
}
|
|
8440
|
+
return value;
|
|
8441
|
+
}
|
|
8442
|
+
if (Array.isArray(value)) {
|
|
8443
|
+
return value.map((item, index) => toJsonValue(item, `${path}[${index}]`, seen));
|
|
8444
|
+
}
|
|
8445
|
+
if (typeof value === "object") {
|
|
8446
|
+
const prototype = Object.getPrototypeOf(value);
|
|
8447
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
8448
|
+
throw new Error(`${path} must be JSON-compatible; only plain objects are supported.`);
|
|
8449
|
+
}
|
|
8450
|
+
if (seen.has(value)) {
|
|
8451
|
+
throw new Error(`${path} must be JSON-compatible; circular references are not supported.`);
|
|
8452
|
+
}
|
|
8453
|
+
seen.add(value);
|
|
8454
|
+
const jsonObject = {};
|
|
8455
|
+
for (const [key, item] of Object.entries(value)) {
|
|
8456
|
+
jsonObject[key] = toJsonValue(item, `${path}.${key}`, seen);
|
|
8457
|
+
}
|
|
8458
|
+
seen.delete(value);
|
|
8459
|
+
return jsonObject;
|
|
8460
|
+
}
|
|
8461
|
+
throw new Error(`${path} must be JSON-compatible; ${typeof value} values are not supported.`);
|
|
8462
|
+
}
|
|
8415
8463
|
function resolveChatV2ResponseFormatParameters(data, inputs) {
|
|
8416
8464
|
const responseFormat = data.responseFormat ?? "";
|
|
8417
8465
|
if (!responseFormat) {
|
|
@@ -8452,11 +8500,47 @@ function createChatV2ResponseOutput(parameters) {
|
|
|
8452
8500
|
});
|
|
8453
8501
|
}
|
|
8454
8502
|
return import_ai.Output.object({
|
|
8455
|
-
schema: (0, import_ai.jsonSchema)(parameters.schema),
|
|
8503
|
+
schema: (0, import_ai.jsonSchema)(toJsonValue(parameters.schema)),
|
|
8456
8504
|
name: parameters.schemaName,
|
|
8457
8505
|
description: parameters.schemaDescription
|
|
8458
8506
|
});
|
|
8459
8507
|
}
|
|
8508
|
+
function mergeCustomProviderResponseFormatOptions(provider, providerOptions, parameters) {
|
|
8509
|
+
if (provider !== "custom" || parameters == null) {
|
|
8510
|
+
return providerOptions;
|
|
8511
|
+
}
|
|
8512
|
+
const customOptions = (providerOptions == null ? void 0 : providerOptions.custom) ?? {};
|
|
8513
|
+
if (parameters.responseFormat === "json") {
|
|
8514
|
+
return {
|
|
8515
|
+
...providerOptions,
|
|
8516
|
+
custom: {
|
|
8517
|
+
...customOptions,
|
|
8518
|
+
response_format: { type: "json_object" }
|
|
8519
|
+
}
|
|
8520
|
+
};
|
|
8521
|
+
}
|
|
8522
|
+
if (parameters.responseFormat !== "json_schema") {
|
|
8523
|
+
return providerOptions;
|
|
8524
|
+
}
|
|
8525
|
+
const jsonSchemaOptions = {
|
|
8526
|
+
name: parameters.schemaName,
|
|
8527
|
+
strict: true,
|
|
8528
|
+
schema: toJsonValue(parameters.schema)
|
|
8529
|
+
};
|
|
8530
|
+
if (parameters.schemaDescription != null) {
|
|
8531
|
+
jsonSchemaOptions.description = parameters.schemaDescription;
|
|
8532
|
+
}
|
|
8533
|
+
return {
|
|
8534
|
+
...providerOptions,
|
|
8535
|
+
custom: {
|
|
8536
|
+
...customOptions,
|
|
8537
|
+
response_format: {
|
|
8538
|
+
type: "json_schema",
|
|
8539
|
+
json_schema: jsonSchemaOptions
|
|
8540
|
+
}
|
|
8541
|
+
}
|
|
8542
|
+
};
|
|
8543
|
+
}
|
|
8460
8544
|
|
|
8461
8545
|
// src/model/chat-v2/chatV2FeatureCompatibility.ts
|
|
8462
8546
|
var LLM_CHAT_V2_TOOL_RESPONSE_FORMAT_CONFLICT_COPY = {
|
|
@@ -8835,9 +8919,13 @@ async function resolveLLMChatV2RuntimeConfig(params) {
|
|
|
8835
8919
|
const prompt = inputs["prompt"];
|
|
8836
8920
|
const systemPrompt = inputs["systemPrompt"];
|
|
8837
8921
|
const functions = data.useToolCalling && inputs["functions"] != null ? coerceTypeOptional(inputs["functions"], "gpt-function[]") : void 0;
|
|
8838
|
-
const providerOptions = resolveLLMChatV2RuntimeProviderOptions(data, inputs);
|
|
8839
8922
|
const toolChoice = resolveLLMChatV2ToolChoice(data);
|
|
8840
8923
|
const responseFormatParameters = resolveChatV2ResponseFormatParameters(data, inputs);
|
|
8924
|
+
const providerOptions = mergeCustomProviderResponseFormatOptions(
|
|
8925
|
+
provider,
|
|
8926
|
+
resolveLLMChatV2RuntimeProviderOptions(data, inputs),
|
|
8927
|
+
responseFormatParameters
|
|
8928
|
+
);
|
|
8841
8929
|
const generationParameters = resolveLLMChatV2GenerationParameters(data, inputs);
|
|
8842
8930
|
const runOptions = {
|
|
8843
8931
|
provider,
|
|
@@ -9542,13 +9630,7 @@ function buildCommonOutputs(requestMessages, response, functionCalls, usage, rea
|
|
|
9542
9630
|
};
|
|
9543
9631
|
}
|
|
9544
9632
|
if (options2.outputReasoning) {
|
|
9545
|
-
outputs["reasoning"] =
|
|
9546
|
-
type: "string[]",
|
|
9547
|
-
value: reasoning
|
|
9548
|
-
} : {
|
|
9549
|
-
type: "string",
|
|
9550
|
-
value: reasoning
|
|
9551
|
-
};
|
|
9633
|
+
outputs["reasoning"] = buildReasoningOutput(reasoning);
|
|
9552
9634
|
}
|
|
9553
9635
|
if (options2.outputRequestStatus) {
|
|
9554
9636
|
if (options2.retryOnNon200) {
|
|
@@ -9573,6 +9655,26 @@ function buildCommonOutputs(requestMessages, response, functionCalls, usage, rea
|
|
|
9573
9655
|
}
|
|
9574
9656
|
return outputs;
|
|
9575
9657
|
}
|
|
9658
|
+
function buildReasoningOutput(reasoning) {
|
|
9659
|
+
if (Array.isArray(reasoning)) {
|
|
9660
|
+
const nonEmptyReasoning = reasoning.filter((part) => typeof part === "string" && part.trim().length > 0);
|
|
9661
|
+
return nonEmptyReasoning.length > 0 ? {
|
|
9662
|
+
type: "string[]",
|
|
9663
|
+
value: nonEmptyReasoning
|
|
9664
|
+
} : {
|
|
9665
|
+
type: "control-flow-excluded",
|
|
9666
|
+
value: void 0
|
|
9667
|
+
};
|
|
9668
|
+
}
|
|
9669
|
+
const reasoningText = typeof reasoning === "string" ? reasoning : "";
|
|
9670
|
+
return reasoningText.trim().length > 0 ? {
|
|
9671
|
+
type: "string",
|
|
9672
|
+
value: reasoningText
|
|
9673
|
+
} : {
|
|
9674
|
+
type: "control-flow-excluded",
|
|
9675
|
+
value: void 0
|
|
9676
|
+
};
|
|
9677
|
+
}
|
|
9576
9678
|
function getProviderFailureMessage(error) {
|
|
9577
9679
|
if (error instanceof Error) {
|
|
9578
9680
|
return error.message;
|
|
@@ -9886,7 +9988,7 @@ function applyAccumulatedUsage(result, usage, outputUsage) {
|
|
|
9886
9988
|
}
|
|
9887
9989
|
function appendReasoningRound(accumulated, reasoning) {
|
|
9888
9990
|
const roundReasoning = Array.isArray(reasoning) ? reasoning : [reasoning];
|
|
9889
|
-
const nonEmptyReasoning = roundReasoning.map((part) => part.trim()).filter((part) => part.length > 0);
|
|
9991
|
+
const nonEmptyReasoning = roundReasoning.filter((part) => typeof part === "string").map((part) => part.trim()).filter((part) => part.length > 0);
|
|
9890
9992
|
if (nonEmptyReasoning.length === 0) {
|
|
9891
9993
|
return;
|
|
9892
9994
|
}
|
|
@@ -14061,20 +14163,29 @@ var ContextNodeImpl = class extends NodeImpl {
|
|
|
14061
14163
|
};
|
|
14062
14164
|
}
|
|
14063
14165
|
async process(inputs, context) {
|
|
14064
|
-
|
|
14065
|
-
|
|
14166
|
+
var _a;
|
|
14167
|
+
const contextValue = ((_a = context.contextValues) == null ? void 0 : _a[this.data.id]) == null ? void 0 : coerceTypeOptional(context.contextValues[this.data.id], this.data.dataType);
|
|
14168
|
+
if (contextValue != null) {
|
|
14066
14169
|
return {
|
|
14067
|
-
["data"]:
|
|
14170
|
+
["data"]: {
|
|
14171
|
+
type: this.data.dataType,
|
|
14172
|
+
value: contextValue
|
|
14173
|
+
}
|
|
14068
14174
|
};
|
|
14069
14175
|
}
|
|
14070
14176
|
let defaultValue;
|
|
14071
14177
|
if (this.data.useDefaultValueInput) {
|
|
14072
|
-
|
|
14073
|
-
|
|
14074
|
-
|
|
14178
|
+
const defaultInputValue = inputs["default"];
|
|
14179
|
+
defaultValue = defaultInputValue == null ? void 0 : coerceTypeOptional(defaultInputValue, this.data.dataType);
|
|
14180
|
+
}
|
|
14181
|
+
if (defaultValue == null) {
|
|
14182
|
+
defaultValue = coerceTypeOptional(inferType(this.data.defaultValue), this.data.dataType) ?? getDefaultValue(this.data.dataType);
|
|
14075
14183
|
}
|
|
14076
14184
|
return {
|
|
14077
|
-
["data"]:
|
|
14185
|
+
["data"]: {
|
|
14186
|
+
type: this.data.dataType,
|
|
14187
|
+
value: defaultValue
|
|
14188
|
+
}
|
|
14078
14189
|
};
|
|
14079
14190
|
}
|
|
14080
14191
|
};
|
|
@@ -24523,7 +24634,7 @@ function initializeGentrace(gentraceApiKey) {
|
|
|
24523
24634
|
apiKey: gentraceApiKey
|
|
24524
24635
|
});
|
|
24525
24636
|
}
|
|
24526
|
-
var runGentraceTests = async (gentracePipelineSlug, settings, project, graph, nativeApi) => {
|
|
24637
|
+
var runGentraceTests = async (gentracePipelineSlug, settings, project, graph, nativeApi, contextValues = {}) => {
|
|
24527
24638
|
var _a, _b, _c;
|
|
24528
24639
|
const gentraceApiKey = (_b = (_a = settings.pluginSettings) == null ? void 0 : _a.gentrace) == null ? void 0 : _b.gentraceApiKey;
|
|
24529
24640
|
if (!gentraceApiKey) {
|
|
@@ -24551,13 +24662,15 @@ var runGentraceTests = async (gentracePipelineSlug, settings, project, graph, na
|
|
|
24551
24662
|
const processor = new GraphProcessor(tempProject, graphId, globalRivetNodeRegistry);
|
|
24552
24663
|
processor.executor = "browser";
|
|
24553
24664
|
recorder.record(processor);
|
|
24665
|
+
const runContextValues = (0, import_lodash_es20.cloneDeep)(contextValues);
|
|
24554
24666
|
await processor.processGraph(
|
|
24555
24667
|
{
|
|
24556
24668
|
settings,
|
|
24557
24669
|
nativeApi,
|
|
24558
24670
|
tokenizer: new GptTokenizerTokenizer()
|
|
24559
24671
|
},
|
|
24560
|
-
rivetFormattedInputs
|
|
24672
|
+
rivetFormattedInputs,
|
|
24673
|
+
runContextValues
|
|
24561
24674
|
);
|
|
24562
24675
|
const fullRecording = recorder.getRecording();
|
|
24563
24676
|
const stepRuns = convertRecordingToStepRuns(fullRecording, project, graphId);
|
|
@@ -28694,6 +28807,7 @@ var Rivet = void 0;
|
|
|
28694
28807
|
mcpDiscoveryNode,
|
|
28695
28808
|
mcpGetPromptNode,
|
|
28696
28809
|
mcpToolCallNode,
|
|
28810
|
+
mergeCustomProviderResponseFormatOptions,
|
|
28697
28811
|
newId,
|
|
28698
28812
|
nodeDefinition,
|
|
28699
28813
|
numberNode,
|