@flowgram.ai/runtime-js 0.2.26 → 0.2.27
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/esm/index.js +11 -57
- package/dist/esm/index.js.map +1 -1
- package/dist/index.js +11 -57
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -729,63 +729,13 @@ var LoopExecutor = class {
|
|
|
729
729
|
var import_lodash_es2 = require("lodash-es");
|
|
730
730
|
var import_openai = require("@langchain/openai");
|
|
731
731
|
var import_messages = require("@langchain/core/messages");
|
|
732
|
-
|
|
733
|
-
// src/nodes/llm/api-validator.ts
|
|
734
|
-
var APIValidator;
|
|
735
|
-
((APIValidator2) => {
|
|
736
|
-
APIValidator2.isValidFormat = (apiHost) => {
|
|
737
|
-
if (!apiHost || typeof apiHost !== "string") {
|
|
738
|
-
return false;
|
|
739
|
-
}
|
|
740
|
-
try {
|
|
741
|
-
const url = new URL(apiHost);
|
|
742
|
-
return url.protocol === "http:" || url.protocol === "https:";
|
|
743
|
-
} catch (error) {
|
|
744
|
-
return false;
|
|
745
|
-
}
|
|
746
|
-
};
|
|
747
|
-
APIValidator2.isExist = async (apiHost) => {
|
|
748
|
-
try {
|
|
749
|
-
const controller = new AbortController();
|
|
750
|
-
const timeoutId = setTimeout(() => controller.abort(), 5e3);
|
|
751
|
-
await fetch(apiHost, {
|
|
752
|
-
method: "HEAD",
|
|
753
|
-
// Use HEAD to minimize data transfer
|
|
754
|
-
signal: controller.signal,
|
|
755
|
-
// Disable following redirects to get the actual host response
|
|
756
|
-
redirect: "manual"
|
|
757
|
-
});
|
|
758
|
-
clearTimeout(timeoutId);
|
|
759
|
-
return true;
|
|
760
|
-
} catch (error) {
|
|
761
|
-
if (error.name === "AbortError") {
|
|
762
|
-
return false;
|
|
763
|
-
}
|
|
764
|
-
const errorMessage = error.message?.toLowerCase() || "";
|
|
765
|
-
const networkFailurePatterns = [
|
|
766
|
-
"network error",
|
|
767
|
-
"connection refused",
|
|
768
|
-
"dns",
|
|
769
|
-
"resolve",
|
|
770
|
-
"timeout",
|
|
771
|
-
"unreachable"
|
|
772
|
-
];
|
|
773
|
-
const isNetworkFailure = networkFailurePatterns.some(
|
|
774
|
-
(pattern) => errorMessage.includes(pattern)
|
|
775
|
-
);
|
|
776
|
-
return !isNetworkFailure;
|
|
777
|
-
}
|
|
778
|
-
};
|
|
779
|
-
})(APIValidator || (APIValidator = {}));
|
|
780
|
-
|
|
781
|
-
// src/nodes/llm/index.ts
|
|
782
732
|
var LLMExecutor = class {
|
|
783
733
|
constructor() {
|
|
784
734
|
this.type = FlowGramNode.LLM;
|
|
785
735
|
}
|
|
786
736
|
async execute(context) {
|
|
787
737
|
const inputs = context.inputs;
|
|
788
|
-
|
|
738
|
+
this.checkInputs(inputs);
|
|
789
739
|
const { modelName, temperature, apiKey, apiHost, systemPrompt, prompt } = inputs;
|
|
790
740
|
const model = new import_openai.ChatOpenAI({
|
|
791
741
|
modelName,
|
|
@@ -793,7 +743,8 @@ var LLMExecutor = class {
|
|
|
793
743
|
apiKey,
|
|
794
744
|
configuration: {
|
|
795
745
|
baseURL: apiHost
|
|
796
|
-
}
|
|
746
|
+
},
|
|
747
|
+
maxRetries: 3
|
|
797
748
|
});
|
|
798
749
|
const messages = [];
|
|
799
750
|
if (systemPrompt) {
|
|
@@ -817,7 +768,7 @@ var LLMExecutor = class {
|
|
|
817
768
|
}
|
|
818
769
|
};
|
|
819
770
|
}
|
|
820
|
-
|
|
771
|
+
checkInputs(inputs) {
|
|
821
772
|
const { modelName, temperature, apiKey, apiHost, prompt } = inputs;
|
|
822
773
|
const missingInputs = [];
|
|
823
774
|
if (!modelName) missingInputs.push("modelName");
|
|
@@ -828,12 +779,15 @@ var LLMExecutor = class {
|
|
|
828
779
|
if (missingInputs.length > 0) {
|
|
829
780
|
throw new Error(`LLM node missing required inputs: "${missingInputs.join('", "')}"`);
|
|
830
781
|
}
|
|
831
|
-
|
|
782
|
+
this.checkApiHost(apiHost);
|
|
783
|
+
}
|
|
784
|
+
checkApiHost(apiHost) {
|
|
785
|
+
if (!apiHost || typeof apiHost !== "string") {
|
|
832
786
|
throw new Error(`Invalid API host format - ${apiHost}`);
|
|
833
787
|
}
|
|
834
|
-
const
|
|
835
|
-
if (
|
|
836
|
-
throw new Error(`
|
|
788
|
+
const url = new URL(apiHost);
|
|
789
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
790
|
+
throw new Error(`Invalid API host protocol - ${url.protocol}`);
|
|
837
791
|
}
|
|
838
792
|
}
|
|
839
793
|
};
|