@stackfactor/agent-utils 1.0.17 → 1.0.19

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.
@@ -1 +1 @@
1
- {"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";wBA2VQ,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,KACV,GAAG;sBAyBG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;wCAmfF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,KACpB,GAAG;oCAxYO,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDA6rBF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CA7vB8B,GAAG,KAAG,MAAM;;AAwzBzD,wBAOE"}
1
+ {"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";wBAgWQ,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,KACV,GAAG;sBAyBG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;wCAmfF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,KACpB,GAAG;oCAxYO,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDA6rBF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CA7vB8B,GAAG,KAAG,MAAM;;AAwzBzD,wBAOE"}
@@ -9,7 +9,7 @@ const google_genai_1 = require("@langchain/google-genai");
9
9
  const openai_2 = require("openai");
10
10
  const genai_1 = require("@google/genai");
11
11
  const const_js_1 = __importDefault(require("./const.js"));
12
- const langchain_1 = __importDefault(require("langchain"));
12
+ const langchain_1 = require("langchain");
13
13
  const errorHandling_js_1 = __importDefault(require("./errorHandling.js"));
14
14
  const logger_js_1 = __importDefault(require("./logger.js"));
15
15
  const zod_to_json_schema_1 = require("zod-to-json-schema");
@@ -31,33 +31,39 @@ Do NOT include raw newlines, tabs, or unescaped quotes inside JSON string values
31
31
  * @returns A formatted string describing all validation failures
32
32
  */
33
33
  const formatZodErrors = (zodError) => {
34
- const errors = zodError.issues && Array.isArray(zodError.issues)
35
- ? zodError.issues.map((err) => {
36
- const path = err.path.length > 0 ? err.path.join(".") : "root";
37
- // Provide more context based on error type
38
- switch (err.code) {
39
- case "invalid_type":
40
- return `Field "${path}": Expected ${err.expected}, but received ${err.received}`;
41
- case "invalid_literal":
42
- return `Field "${path}": Expected literal value ${JSON.stringify(err.expected)}, but received ${JSON.stringify(err.received)}`;
43
- case "unrecognized_keys":
44
- return `Field "${path}": Unrecognized keys: ${err.keys.join(", ")}`;
45
- case "invalid_union":
46
- return `Field "${path}": Invalid union - none of the expected types matched`;
47
- case "invalid_enum_value":
48
- return `Field "${path}": Invalid enum value. Expected one of: ${err.options.join(", ")}`;
49
- case "invalid_string":
50
- return `Field "${path}": Invalid string format (${err.validation})`;
51
- case "too_small":
52
- return `Field "${path}": Value is too small (minimum: ${err.minimum})`;
53
- case "too_big":
54
- return `Field "${path}": Value is too large (maximum: ${err.maximum})`;
55
- default:
56
- return `Field "${path}": ${err.message}`;
57
- }
58
- })
59
- : ["Schema validation error"];
60
- return `Schema validation failed:\n - ${errors.join("\n - ")}`;
34
+ try {
35
+ const errors = zodError.issues && Array.isArray(zodError.issues)
36
+ ? zodError.issues.map((err) => {
37
+ const path = err.path.length > 0 ? err.path.join(".") : "root";
38
+ // Provide more context based on error type
39
+ switch (err.code) {
40
+ case "invalid_type":
41
+ return `Field "${path}": Expected ${err.expected}, but received ${err.received}`;
42
+ case "invalid_literal":
43
+ return `Field "${path}": Expected literal value ${JSON.stringify(err.expected)}, but received ${JSON.stringify(err.received)}`;
44
+ case "unrecognized_keys":
45
+ return `Field "${path}": Unrecognized keys: ${err.keys.join(", ")}`;
46
+ case "invalid_union":
47
+ return `Field "${path}": Invalid union - none of the expected types matched`;
48
+ case "invalid_enum_value":
49
+ return `Field "${path}": Invalid enum value. Expected one of: ${err.options.join(", ")}`;
50
+ case "invalid_string":
51
+ return `Field "${path}": Invalid string format (${err.validation})`;
52
+ case "too_small":
53
+ return `Field "${path}": Value is too small (minimum: ${err.minimum})`;
54
+ case "too_big":
55
+ return `Field "${path}": Value is too large (maximum: ${err.maximum})`;
56
+ default:
57
+ return `Field "${path}": ${err.message}`;
58
+ }
59
+ })
60
+ : ["Schema validation error"];
61
+ return `Schema validation failed:\n - ${errors.join("\n - ")}`;
62
+ }
63
+ catch {
64
+ // Fallback in case of unexpected error structure
65
+ return `Schema validation failed with an unexpected error format`;
66
+ }
61
67
  };
62
68
  /**
63
69
  * Validates a parsed JavaScript value against a Zod schema using `safeParse`. On
@@ -319,7 +325,7 @@ const getLLMModel = (modelName, config, schema = null) => {
319
325
  * @returns A configured LangChain agent instance ready to be run with `runAgent`
320
326
  */
321
327
  const createAgent = (name, modelName, systemPrompt, tools = [], responseFormat, config) => {
322
- const agent = langchain_1.default.createAgent({
328
+ const agent = (0, langchain_1.createAgent)({
323
329
  name: name,
324
330
  model: getLLMModel(modelName, config),
325
331
  systemPrompt: systemPrompt.trim(),
@@ -1 +1 @@
1
- {"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";wBA2VQ,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,KACV,GAAG;sBAyBG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;wCAmfF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,KACpB,GAAG;oCAxYO,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDA6rBF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CA7vB8B,GAAG,KAAG,MAAM;;AAwzBzD,wBAOE"}
1
+ {"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";wBAgWQ,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,KACV,GAAG;sBAyBG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;wCAmfF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,KACpB,GAAG;oCAxYO,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDA6rBF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CA7vB8B,GAAG,KAAG,MAAM;;AAwzBzD,wBAOE"}
@@ -4,7 +4,7 @@ import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
4
4
  import { OpenAI } from "openai";
5
5
  import { GoogleGenAI } from "@google/genai";
6
6
  import constants from "./const.js";
7
- import langChain from "langchain";
7
+ import { createAgent as createLangChainAgent } from "langchain";
8
8
  import errorHandlingHelper from "./errorHandling.js";
9
9
  import logger from "./logger.js";
10
10
  import { zodToJsonSchema } from "zod-to-json-schema";
@@ -26,33 +26,39 @@ Do NOT include raw newlines, tabs, or unescaped quotes inside JSON string values
26
26
  * @returns A formatted string describing all validation failures
27
27
  */
28
28
  const formatZodErrors = (zodError) => {
29
- const errors = zodError.issues && Array.isArray(zodError.issues)
30
- ? zodError.issues.map((err) => {
31
- const path = err.path.length > 0 ? err.path.join(".") : "root";
32
- // Provide more context based on error type
33
- switch (err.code) {
34
- case "invalid_type":
35
- return `Field "${path}": Expected ${err.expected}, but received ${err.received}`;
36
- case "invalid_literal":
37
- return `Field "${path}": Expected literal value ${JSON.stringify(err.expected)}, but received ${JSON.stringify(err.received)}`;
38
- case "unrecognized_keys":
39
- return `Field "${path}": Unrecognized keys: ${err.keys.join(", ")}`;
40
- case "invalid_union":
41
- return `Field "${path}": Invalid union - none of the expected types matched`;
42
- case "invalid_enum_value":
43
- return `Field "${path}": Invalid enum value. Expected one of: ${err.options.join(", ")}`;
44
- case "invalid_string":
45
- return `Field "${path}": Invalid string format (${err.validation})`;
46
- case "too_small":
47
- return `Field "${path}": Value is too small (minimum: ${err.minimum})`;
48
- case "too_big":
49
- return `Field "${path}": Value is too large (maximum: ${err.maximum})`;
50
- default:
51
- return `Field "${path}": ${err.message}`;
52
- }
53
- })
54
- : ["Schema validation error"];
55
- return `Schema validation failed:\n - ${errors.join("\n - ")}`;
29
+ try {
30
+ const errors = zodError.issues && Array.isArray(zodError.issues)
31
+ ? zodError.issues.map((err) => {
32
+ const path = err.path.length > 0 ? err.path.join(".") : "root";
33
+ // Provide more context based on error type
34
+ switch (err.code) {
35
+ case "invalid_type":
36
+ return `Field "${path}": Expected ${err.expected}, but received ${err.received}`;
37
+ case "invalid_literal":
38
+ return `Field "${path}": Expected literal value ${JSON.stringify(err.expected)}, but received ${JSON.stringify(err.received)}`;
39
+ case "unrecognized_keys":
40
+ return `Field "${path}": Unrecognized keys: ${err.keys.join(", ")}`;
41
+ case "invalid_union":
42
+ return `Field "${path}": Invalid union - none of the expected types matched`;
43
+ case "invalid_enum_value":
44
+ return `Field "${path}": Invalid enum value. Expected one of: ${err.options.join(", ")}`;
45
+ case "invalid_string":
46
+ return `Field "${path}": Invalid string format (${err.validation})`;
47
+ case "too_small":
48
+ return `Field "${path}": Value is too small (minimum: ${err.minimum})`;
49
+ case "too_big":
50
+ return `Field "${path}": Value is too large (maximum: ${err.maximum})`;
51
+ default:
52
+ return `Field "${path}": ${err.message}`;
53
+ }
54
+ })
55
+ : ["Schema validation error"];
56
+ return `Schema validation failed:\n - ${errors.join("\n - ")}`;
57
+ }
58
+ catch {
59
+ // Fallback in case of unexpected error structure
60
+ return `Schema validation failed with an unexpected error format`;
61
+ }
56
62
  };
57
63
  /**
58
64
  * Validates a parsed JavaScript value against a Zod schema using `safeParse`. On
@@ -314,7 +320,7 @@ const getLLMModel = (modelName, config, schema = null) => {
314
320
  * @returns A configured LangChain agent instance ready to be run with `runAgent`
315
321
  */
316
322
  const createAgent = (name, modelName, systemPrompt, tools = [], responseFormat, config) => {
317
- const agent = langChain.createAgent({
323
+ const agent = createLangChainAgent({
318
324
  name: name,
319
325
  model: getLLMModel(modelName, config),
320
326
  systemPrompt: systemPrompt.trim(),
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "restricted"
5
5
  },
6
- "version": "1.0.17",
6
+ "version": "1.0.19",
7
7
  "description": "",
8
8
  "main": "dist/cjs/index.js",
9
9
  "module": "dist/esm/index.js",