@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 CHANGED
@@ -688,63 +688,13 @@ var LoopExecutor = class {
688
688
  import { isNil as isNil2 } from "lodash-es";
689
689
  import { ChatOpenAI } from "@langchain/openai";
690
690
  import { SystemMessage, HumanMessage } from "@langchain/core/messages";
691
-
692
- // src/nodes/llm/api-validator.ts
693
- var APIValidator;
694
- ((APIValidator2) => {
695
- APIValidator2.isValidFormat = (apiHost) => {
696
- if (!apiHost || typeof apiHost !== "string") {
697
- return false;
698
- }
699
- try {
700
- const url = new URL(apiHost);
701
- return url.protocol === "http:" || url.protocol === "https:";
702
- } catch (error) {
703
- return false;
704
- }
705
- };
706
- APIValidator2.isExist = async (apiHost) => {
707
- try {
708
- const controller = new AbortController();
709
- const timeoutId = setTimeout(() => controller.abort(), 5e3);
710
- await fetch(apiHost, {
711
- method: "HEAD",
712
- // Use HEAD to minimize data transfer
713
- signal: controller.signal,
714
- // Disable following redirects to get the actual host response
715
- redirect: "manual"
716
- });
717
- clearTimeout(timeoutId);
718
- return true;
719
- } catch (error) {
720
- if (error.name === "AbortError") {
721
- return false;
722
- }
723
- const errorMessage = error.message?.toLowerCase() || "";
724
- const networkFailurePatterns = [
725
- "network error",
726
- "connection refused",
727
- "dns",
728
- "resolve",
729
- "timeout",
730
- "unreachable"
731
- ];
732
- const isNetworkFailure = networkFailurePatterns.some(
733
- (pattern) => errorMessage.includes(pattern)
734
- );
735
- return !isNetworkFailure;
736
- }
737
- };
738
- })(APIValidator || (APIValidator = {}));
739
-
740
- // src/nodes/llm/index.ts
741
691
  var LLMExecutor = class {
742
692
  constructor() {
743
693
  this.type = FlowGramNode.LLM;
744
694
  }
745
695
  async execute(context) {
746
696
  const inputs = context.inputs;
747
- await this.checkInputs(inputs);
697
+ this.checkInputs(inputs);
748
698
  const { modelName, temperature, apiKey, apiHost, systemPrompt, prompt } = inputs;
749
699
  const model = new ChatOpenAI({
750
700
  modelName,
@@ -752,7 +702,8 @@ var LLMExecutor = class {
752
702
  apiKey,
753
703
  configuration: {
754
704
  baseURL: apiHost
755
- }
705
+ },
706
+ maxRetries: 3
756
707
  });
757
708
  const messages = [];
758
709
  if (systemPrompt) {
@@ -776,7 +727,7 @@ var LLMExecutor = class {
776
727
  }
777
728
  };
778
729
  }
779
- async checkInputs(inputs) {
730
+ checkInputs(inputs) {
780
731
  const { modelName, temperature, apiKey, apiHost, prompt } = inputs;
781
732
  const missingInputs = [];
782
733
  if (!modelName) missingInputs.push("modelName");
@@ -787,12 +738,15 @@ var LLMExecutor = class {
787
738
  if (missingInputs.length > 0) {
788
739
  throw new Error(`LLM node missing required inputs: "${missingInputs.join('", "')}"`);
789
740
  }
790
- if (!APIValidator.isValidFormat(apiHost)) {
741
+ this.checkApiHost(apiHost);
742
+ }
743
+ checkApiHost(apiHost) {
744
+ if (!apiHost || typeof apiHost !== "string") {
791
745
  throw new Error(`Invalid API host format - ${apiHost}`);
792
746
  }
793
- const apiHostExists = await APIValidator.isExist(apiHost);
794
- if (!apiHostExists) {
795
- throw new Error(`Unreachable API host - ${apiHost}`);
747
+ const url = new URL(apiHost);
748
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
749
+ throw new Error(`Invalid API host protocol - ${url.protocol}`);
796
750
  }
797
751
  }
798
752
  };