@alpic80/rivet-core 1.24.2-aidon.11 → 1.24.2-aidon.13
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 +188 -26
- package/dist/cjs/bundle.cjs.map +2 -2
- package/dist/esm/model/nodes/ChatNodeBase.js +20 -2
- package/dist/esm/model/nodes/MCPDiscoveryNode.js +12 -0
- package/dist/esm/model/nodes/ToolNode.js +1 -0
- package/dist/esm/plugins/aidon/nodes/ChatAidonNode.js +159 -33
- package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +2 -0
- package/dist/esm/utils/chatMessageToOpenAIChatCompletionMessage.js +8 -0
- package/dist/types/integrations/mcp/MCPProvider.d.ts +8 -0
- package/dist/types/model/DataValue.d.ts +6 -0
- package/dist/types/model/nodes/ChatNodeBase.d.ts +2 -0
- package/dist/types/utils/openai.d.ts +8 -1
- package/package.json +2 -2
package/dist/cjs/bundle.cjs
CHANGED
|
@@ -2925,6 +2925,14 @@ async function chatMessageToOpenAIChatCompletionMessage(message, options2) {
|
|
|
2925
2925
|
if (typeof part === "string") {
|
|
2926
2926
|
return { type: "text", text: part };
|
|
2927
2927
|
}
|
|
2928
|
+
if (part.type === "file") {
|
|
2929
|
+
return {
|
|
2930
|
+
type: "file",
|
|
2931
|
+
filename: part.filename || "file.pdf",
|
|
2932
|
+
mediaType: part.mediaType,
|
|
2933
|
+
data: part.data.toString()
|
|
2934
|
+
};
|
|
2935
|
+
}
|
|
2928
2936
|
const url = part.type === "url" ? part.url : `data:${part.mediaType};base64,${await uint8ArrayToBase64(part.data)}`;
|
|
2929
2937
|
return {
|
|
2930
2938
|
type: "image_url",
|
|
@@ -3008,6 +3016,14 @@ var ChatNodeBase = {
|
|
|
3008
3016
|
description: "The endpoint to use for the OpenAI API. You can use this to replace with any OpenAI-compatible API. Leave blank for the default: https://api.openai.com/api/v1/chat/completions"
|
|
3009
3017
|
});
|
|
3010
3018
|
}
|
|
3019
|
+
if (data.useApiKeyInput) {
|
|
3020
|
+
inputs.push({
|
|
3021
|
+
dataType: "string",
|
|
3022
|
+
id: "apikey",
|
|
3023
|
+
title: "API Key",
|
|
3024
|
+
description: "The API Key to use for the OpenAI API. You can use this to replace the default OpenAI key in settings. Leave blank for the default key."
|
|
3025
|
+
});
|
|
3026
|
+
}
|
|
3011
3027
|
inputs.push({
|
|
3012
3028
|
id: "systemPrompt",
|
|
3013
3029
|
title: "System Prompt",
|
|
@@ -3556,6 +3572,13 @@ var ChatNodeBase = {
|
|
|
3556
3572
|
useInputToggleDataKey: "useEndpointInput",
|
|
3557
3573
|
helperMessage: "The endpoint to use for the OpenAI API. You can use this to replace with any OpenAI-compatible API. Leave blank for the default: https://api.openai.com/api/v1/chat/completions"
|
|
3558
3574
|
},
|
|
3575
|
+
{
|
|
3576
|
+
type: "string",
|
|
3577
|
+
label: "API Key",
|
|
3578
|
+
dataKey: "apikey",
|
|
3579
|
+
useInputToggleDataKey: "useApiKeyInput",
|
|
3580
|
+
helperMessage: "The API Key to use for the OpenAI API. You can use this to replace the default OpenAI key in settings. Leave blank for the default key."
|
|
3581
|
+
},
|
|
3559
3582
|
{
|
|
3560
3583
|
type: "string",
|
|
3561
3584
|
label: "Custom Model",
|
|
@@ -3626,6 +3649,7 @@ var ChatNodeBase = {
|
|
|
3626
3649
|
const frequencyPenalty = getInputOrData(data, inputs, "frequencyPenalty", "number");
|
|
3627
3650
|
const numberOfChoices = getInputOrData(data, inputs, "numberOfChoices", "number");
|
|
3628
3651
|
const endpoint = getInputOrData(data, inputs, "endpoint");
|
|
3652
|
+
const apiKey = getInputOrData(data, inputs, "apikey");
|
|
3629
3653
|
const overrideModel = getInputOrData(data, inputs, "overrideModel");
|
|
3630
3654
|
const seed = getInputOrData(data, inputs, "seed", "number");
|
|
3631
3655
|
const responseFormat = getInputOrData(data, inputs, "responseFormat");
|
|
@@ -3711,6 +3735,7 @@ var ChatNodeBase = {
|
|
|
3711
3735
|
...additionalHeaders,
|
|
3712
3736
|
...resolvedEndpointAndHeaders.headers
|
|
3713
3737
|
});
|
|
3738
|
+
const configuredApiKey = apiKey || context.settings.openAiKey || "";
|
|
3714
3739
|
let inputTokenCount = 0;
|
|
3715
3740
|
const tokenizerInfo = {
|
|
3716
3741
|
node,
|
|
@@ -3793,7 +3818,7 @@ var ChatNodeBase = {
|
|
|
3793
3818
|
if (isO1Beta || audio) {
|
|
3794
3819
|
const response = await chatCompletions({
|
|
3795
3820
|
auth: {
|
|
3796
|
-
apiKey:
|
|
3821
|
+
apiKey: configuredApiKey,
|
|
3797
3822
|
organization: context.settings.openAiOrganization
|
|
3798
3823
|
},
|
|
3799
3824
|
headers: allAdditionalHeaders,
|
|
@@ -3882,7 +3907,7 @@ var ChatNodeBase = {
|
|
|
3882
3907
|
}
|
|
3883
3908
|
const chunks = streamChatCompletions({
|
|
3884
3909
|
auth: {
|
|
3885
|
-
apiKey:
|
|
3910
|
+
apiKey: configuredApiKey,
|
|
3886
3911
|
organization: context.settings.openAiOrganization
|
|
3887
3912
|
},
|
|
3888
3913
|
headers: allAdditionalHeaders,
|
|
@@ -8354,6 +8379,7 @@ var GptFunctionNodeImpl = class extends NodeImpl {
|
|
|
8354
8379
|
["function"]: {
|
|
8355
8380
|
type: "gpt-function",
|
|
8356
8381
|
value: {
|
|
8382
|
+
namespace: "internal",
|
|
8357
8383
|
name,
|
|
8358
8384
|
description,
|
|
8359
8385
|
parameters: schema,
|
|
@@ -14044,6 +14070,14 @@ Headers: ${this.data.headers}` : "";
|
|
|
14044
14070
|
if (!context.mcpProvider) {
|
|
14045
14071
|
throw new Error("MCP Provider not found");
|
|
14046
14072
|
}
|
|
14073
|
+
const config = {
|
|
14074
|
+
name,
|
|
14075
|
+
version,
|
|
14076
|
+
transportType,
|
|
14077
|
+
// serverUrl: this.data.serverUrl,
|
|
14078
|
+
serverId: this.data.serverId
|
|
14079
|
+
// headers: this.data.headers?.trim()
|
|
14080
|
+
};
|
|
14047
14081
|
if (transportType === "http") {
|
|
14048
14082
|
const serverUrl = getInputOrData(this.data, inputs, "serverUrl", "string");
|
|
14049
14083
|
if (!serverUrl || serverUrl === "") {
|
|
@@ -14068,6 +14102,8 @@ Headers: ${this.data.headers}` : "";
|
|
|
14068
14102
|
} else if ((_a = this.data.headers) == null ? void 0 : _a.trim()) {
|
|
14069
14103
|
headers = JSON.parse(this.data.headers);
|
|
14070
14104
|
}
|
|
14105
|
+
config.serverUrl = serverUrl;
|
|
14106
|
+
config.headers = headers;
|
|
14071
14107
|
tools = await context.mcpProvider.getHTTPTools({ name, version }, serverUrl, headers);
|
|
14072
14108
|
prompts = await context.mcpProvider.getHTTPrompts({ name, version }, serverUrl, headers);
|
|
14073
14109
|
} else if (transportType === "stdio") {
|
|
@@ -14085,9 +14121,11 @@ Headers: ${this.data.headers}` : "";
|
|
|
14085
14121
|
}
|
|
14086
14122
|
const output = {};
|
|
14087
14123
|
const gptFunctions = tools.map((tool) => ({
|
|
14124
|
+
namespace: "mcp",
|
|
14088
14125
|
name: tool.name,
|
|
14089
14126
|
description: tool.description ?? "",
|
|
14090
14127
|
parameters: tool.inputSchema,
|
|
14128
|
+
config,
|
|
14091
14129
|
strict: false
|
|
14092
14130
|
}));
|
|
14093
14131
|
if (this.data.useToolsOutput) {
|
|
@@ -16666,13 +16704,13 @@ var ChatAidonNodeImpl = class extends ChatNodeImpl {
|
|
|
16666
16704
|
};
|
|
16667
16705
|
return chatNode2;
|
|
16668
16706
|
}
|
|
16669
|
-
removeInvalidInputs(inputs) {
|
|
16670
|
-
|
|
16671
|
-
|
|
16672
|
-
|
|
16673
|
-
|
|
16674
|
-
|
|
16675
|
-
}
|
|
16707
|
+
// removeInvalidInputs(inputs: Inputs): Inputs {
|
|
16708
|
+
// if (!inputs['toolSchemas' as PortId]) {
|
|
16709
|
+
// const { ['functions' as PortId]: _, ...rest } = inputs;
|
|
16710
|
+
// return rest;
|
|
16711
|
+
// }
|
|
16712
|
+
// return inputs;
|
|
16713
|
+
// }
|
|
16676
16714
|
convertToolSchemaToSchemaDetail(toolSchema) {
|
|
16677
16715
|
const { name, description, parameters } = toolSchema;
|
|
16678
16716
|
const { headers, requestInBody, routeMap, url } = parameters;
|
|
@@ -16759,42 +16797,164 @@ var ChatAidonNodeImpl = class extends ChatNodeImpl {
|
|
|
16759
16797
|
}
|
|
16760
16798
|
return data;
|
|
16761
16799
|
}
|
|
16800
|
+
async callOpenApiTool(inputs, functionCall, data) {
|
|
16801
|
+
const toolSchemas = coerceTypeOptional(inputs["toolSchemas"], "gpt-function[]");
|
|
16802
|
+
const toolSchema = toolSchemas.find((detail) => detail.name === functionCall.name);
|
|
16803
|
+
if (!toolSchema) {
|
|
16804
|
+
throw new Error(`Function ${functionCall.name} not found in any schema`);
|
|
16805
|
+
}
|
|
16806
|
+
const schemaDetail = this.convertToolSchemaToSchemaDetail(toolSchema);
|
|
16807
|
+
const path = this.extractPath(schemaDetail, functionCall.name, functionCall.arguments);
|
|
16808
|
+
if (schemaDetail.requestInBody) {
|
|
16809
|
+
data = await this.callToolPost(schemaDetail, path, functionCall.arguments, data);
|
|
16810
|
+
} else {
|
|
16811
|
+
data = await this.callToolGet(schemaDetail, path, functionCall.arguments, data);
|
|
16812
|
+
}
|
|
16813
|
+
return data;
|
|
16814
|
+
}
|
|
16815
|
+
async callMcpTool(context, functionCall, funct, data) {
|
|
16816
|
+
if (funct.config === void 0) {
|
|
16817
|
+
throw new Error(`MCP function ${functionCall.name} is missing MCP configuration`);
|
|
16818
|
+
}
|
|
16819
|
+
const mcpConfig = funct.config;
|
|
16820
|
+
const name = mcpConfig.name;
|
|
16821
|
+
const version = mcpConfig.version;
|
|
16822
|
+
const transportType = mcpConfig.transportType;
|
|
16823
|
+
const toolCall = {
|
|
16824
|
+
name: functionCall.name,
|
|
16825
|
+
arguments: functionCall.arguments
|
|
16826
|
+
};
|
|
16827
|
+
let toolResponse = void 0;
|
|
16828
|
+
try {
|
|
16829
|
+
if (!context.mcpProvider) {
|
|
16830
|
+
throw new Error("MCP Provider not found");
|
|
16831
|
+
}
|
|
16832
|
+
if (transportType === "http") {
|
|
16833
|
+
const serverUrl = mcpConfig.serverUrl;
|
|
16834
|
+
if (!serverUrl || serverUrl === "") {
|
|
16835
|
+
throw new MCPError("SERVER_NOT_FOUND" /* SERVER_NOT_FOUND */, "No server URL was provided");
|
|
16836
|
+
}
|
|
16837
|
+
if (!serverUrl.includes("/mcp")) {
|
|
16838
|
+
throw new MCPError(
|
|
16839
|
+
"SERVER_COMMUNICATION_FAILED" /* SERVER_COMMUNICATION_FAILED */,
|
|
16840
|
+
"Include /mcp in your server URL. For example: http://localhost:8080/mcp"
|
|
16841
|
+
);
|
|
16842
|
+
}
|
|
16843
|
+
const headers = mcpConfig.headers;
|
|
16844
|
+
toolResponse = await context.mcpProvider.httpToolCall({ name, version }, serverUrl, headers, toolCall);
|
|
16845
|
+
} else if (transportType === "stdio") {
|
|
16846
|
+
const serverId = mcpConfig.serverId ?? "";
|
|
16847
|
+
const mcpConfiguration = await loadMCPConfiguration(context);
|
|
16848
|
+
if (!mcpConfiguration.mcpServers[serverId]) {
|
|
16849
|
+
throw new MCPError("SERVER_NOT_FOUND" /* SERVER_NOT_FOUND */, `Server ${serverId} not found in MCP config`);
|
|
16850
|
+
}
|
|
16851
|
+
const serverConfig = {
|
|
16852
|
+
config: mcpConfiguration.mcpServers[serverId],
|
|
16853
|
+
serverId
|
|
16854
|
+
};
|
|
16855
|
+
toolResponse = await context.mcpProvider.stdioToolCall({ name, version }, serverConfig, toolCall);
|
|
16856
|
+
}
|
|
16857
|
+
} catch (err) {
|
|
16858
|
+
const { message } = getError(err);
|
|
16859
|
+
if (context.executor === "browser") {
|
|
16860
|
+
throw new Error("Failed to create Client without a node executor");
|
|
16861
|
+
}
|
|
16862
|
+
console.log(message);
|
|
16863
|
+
throw err;
|
|
16864
|
+
}
|
|
16865
|
+
if (toolResponse) {
|
|
16866
|
+
return toolResponse;
|
|
16867
|
+
} else {
|
|
16868
|
+
return data;
|
|
16869
|
+
}
|
|
16870
|
+
}
|
|
16871
|
+
async callInternalTool(context, functionCall, data) {
|
|
16872
|
+
let handler;
|
|
16873
|
+
const matchingGraph = Object.values(context.project.graphs).find(
|
|
16874
|
+
(graph) => {
|
|
16875
|
+
var _a, _b;
|
|
16876
|
+
return (_b = (_a = graph.metadata) == null ? void 0 : _a.name) == null ? void 0 : _b.includes("Tools/" + functionCall.name);
|
|
16877
|
+
}
|
|
16878
|
+
);
|
|
16879
|
+
if (matchingGraph) {
|
|
16880
|
+
handler = { key: void 0, value: matchingGraph.metadata.id };
|
|
16881
|
+
}
|
|
16882
|
+
if (!handler) {
|
|
16883
|
+
throw new Error(`No handler found for tool call: ${functionCall.name}`);
|
|
16884
|
+
}
|
|
16885
|
+
const subgraphInputs = {
|
|
16886
|
+
_function_name: {
|
|
16887
|
+
type: "string",
|
|
16888
|
+
value: functionCall.name
|
|
16889
|
+
},
|
|
16890
|
+
_arguments: {
|
|
16891
|
+
type: "object",
|
|
16892
|
+
value: functionCall.arguments
|
|
16893
|
+
}
|
|
16894
|
+
};
|
|
16895
|
+
for (const [argName, argument] of Object.entries(functionCall.arguments ?? {})) {
|
|
16896
|
+
subgraphInputs[argName] = {
|
|
16897
|
+
type: "any",
|
|
16898
|
+
value: argument
|
|
16899
|
+
};
|
|
16900
|
+
}
|
|
16901
|
+
const handlerGraphId = handler.value;
|
|
16902
|
+
const subprocessor = context.createSubProcessor(handlerGraphId, { signal: context.signal });
|
|
16903
|
+
data = await subprocessor.processGraph(context, subgraphInputs, context.contextValues);
|
|
16904
|
+
return data;
|
|
16905
|
+
}
|
|
16762
16906
|
// Override the process function
|
|
16763
16907
|
async process(inputs, context) {
|
|
16764
|
-
inputs = this.removeInvalidInputs(inputs);
|
|
16765
16908
|
let outputs = await super.process(inputs, context);
|
|
16766
|
-
|
|
16767
|
-
|
|
16768
|
-
|
|
16769
|
-
|
|
16770
|
-
|
|
16909
|
+
let messages = outputs["all-messages"];
|
|
16910
|
+
let iterations = 0;
|
|
16911
|
+
const maxIterations = 20;
|
|
16912
|
+
while (true) {
|
|
16913
|
+
if (iterations >= maxIterations) {
|
|
16914
|
+
throw new Error(`Max tool call iterations (${maxIterations}) exceeded`);
|
|
16915
|
+
}
|
|
16916
|
+
const funcCallOutput = outputs["function-call"] ?? outputs["function-calls"];
|
|
16917
|
+
const funcCalls = (funcCallOutput == null ? void 0 : funcCallOutput.type) === "object[]" ? funcCallOutput.value : void 0;
|
|
16918
|
+
if (!funcCalls)
|
|
16919
|
+
break;
|
|
16920
|
+
console.log(`Need to call ${funcCalls.length} tools this iteration...`);
|
|
16921
|
+
iterations++;
|
|
16922
|
+
const functions = coerceTypeOptional(inputs["functions"], "gpt-function[]");
|
|
16771
16923
|
const functionCalls = funcCalls.map((functionCall) => ({
|
|
16772
16924
|
name: functionCall.name,
|
|
16773
16925
|
arguments: functionCall.arguments,
|
|
16774
16926
|
id: functionCall.id
|
|
16775
16927
|
}));
|
|
16776
16928
|
for (const functionCall of functionCalls) {
|
|
16777
|
-
const
|
|
16778
|
-
if (!
|
|
16779
|
-
throw new Error(`Function ${functionCall.name} not found in
|
|
16929
|
+
const funct = functions.find((fctn) => fctn.name === functionCall.name);
|
|
16930
|
+
if (!funct) {
|
|
16931
|
+
throw new Error(`Function ${functionCall.name} not found in functions input`);
|
|
16780
16932
|
}
|
|
16781
|
-
const schemaDetail = this.convertToolSchemaToSchemaDetail(toolSchema);
|
|
16782
|
-
const path = this.extractPath(schemaDetail, functionCall.name, functionCall.arguments);
|
|
16783
16933
|
let data = {};
|
|
16784
|
-
|
|
16785
|
-
|
|
16786
|
-
|
|
16787
|
-
|
|
16934
|
+
console.log(`Calling tool ${functionCall.name} in namespace ${funct.namespace}...`);
|
|
16935
|
+
switch (funct.namespace) {
|
|
16936
|
+
case "openapi":
|
|
16937
|
+
data = await this.callOpenApiTool(inputs, functionCall, data);
|
|
16938
|
+
break;
|
|
16939
|
+
case "mcp":
|
|
16940
|
+
data = await this.callMcpTool(context, functionCall, funct, data);
|
|
16941
|
+
break;
|
|
16942
|
+
case "internal":
|
|
16943
|
+
default:
|
|
16944
|
+
data = await this.callInternalTool(context, functionCall, data);
|
|
16945
|
+
break;
|
|
16788
16946
|
}
|
|
16947
|
+
console.log(`Tool call result for ${functionCall.name} is ${JSON.stringify(data)}...`);
|
|
16789
16948
|
messages["value"].push({
|
|
16790
16949
|
type: "function",
|
|
16791
|
-
name: functionCall.id,
|
|
16950
|
+
name: functionCall.id ?? functionCall.name,
|
|
16792
16951
|
message: JSON.stringify(data)
|
|
16793
16952
|
});
|
|
16794
16953
|
}
|
|
16795
|
-
inputs = (0, import_lodash_es18.omit)(inputs, ["
|
|
16954
|
+
inputs = (0, import_lodash_es18.omit)(inputs, ["prompt"]);
|
|
16796
16955
|
inputs["prompt"] = messages;
|
|
16797
16956
|
outputs = await super.process(inputs, context);
|
|
16957
|
+
messages = outputs["all-messages"];
|
|
16798
16958
|
}
|
|
16799
16959
|
return outputs;
|
|
16800
16960
|
}
|
|
@@ -17928,6 +18088,8 @@ async function chatMessageContentToClaude3ChatMessage(content) {
|
|
|
17928
18088
|
};
|
|
17929
18089
|
case "url":
|
|
17930
18090
|
throw new Error("unable to convert urls for Claude");
|
|
18091
|
+
case "file":
|
|
18092
|
+
throw new Error("unable to convert files for Claude");
|
|
17931
18093
|
case "document":
|
|
17932
18094
|
return {
|
|
17933
18095
|
type: "document",
|