@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.
- package/dist/cjs/langChain.d.ts.map +1 -1
- package/dist/cjs/langChain.js +35 -29
- package/dist/esm/langChain.d.ts.map +1 -1
- package/dist/esm/langChain.js +35 -29
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";
|
|
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"}
|
package/dist/cjs/langChain.js
CHANGED
|
@@ -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 =
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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.
|
|
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":";
|
|
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"}
|
package/dist/esm/langChain.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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 =
|
|
323
|
+
const agent = createLangChainAgent({
|
|
318
324
|
name: name,
|
|
319
325
|
model: getLLMModel(modelName, config),
|
|
320
326
|
systemPrompt: systemPrompt.trim(),
|