@langchain/core 0.1.55-rc.0 → 0.1.56

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.
Files changed (52) hide show
  1. package/dist/agents.d.ts +1 -1
  2. package/dist/caches.d.ts +1 -1
  3. package/dist/language_models/chat_models.d.ts +14 -3
  4. package/dist/messages/ai.cjs +213 -0
  5. package/dist/messages/ai.d.ts +37 -0
  6. package/dist/messages/ai.js +207 -0
  7. package/dist/messages/base.cjs +212 -0
  8. package/dist/messages/base.d.ts +137 -0
  9. package/dist/messages/base.js +201 -0
  10. package/dist/messages/chat.cjs +71 -0
  11. package/dist/messages/chat.d.ts +28 -0
  12. package/dist/messages/chat.js +66 -0
  13. package/dist/messages/function.cjs +46 -0
  14. package/dist/messages/function.d.ts +24 -0
  15. package/dist/messages/function.js +41 -0
  16. package/dist/messages/human.cjs +36 -0
  17. package/dist/messages/human.d.ts +17 -0
  18. package/dist/messages/human.js +31 -0
  19. package/dist/messages/index.cjs +27 -633
  20. package/dist/messages/index.d.ts +8 -273
  21. package/dist/messages/index.js +10 -611
  22. package/dist/messages/system.cjs +36 -0
  23. package/dist/messages/system.d.ts +17 -0
  24. package/dist/messages/system.js +31 -0
  25. package/dist/messages/tool.cjs +101 -0
  26. package/dist/messages/tool.d.ts +101 -0
  27. package/dist/messages/tool.js +95 -0
  28. package/dist/messages/utils.cjs +172 -0
  29. package/dist/messages/utils.d.ts +31 -0
  30. package/dist/messages/utils.js +163 -0
  31. package/dist/output_parsers/json.cjs +6 -93
  32. package/dist/output_parsers/json.d.ts +2 -2
  33. package/dist/output_parsers/json.js +2 -88
  34. package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs +79 -13
  35. package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.ts +18 -0
  36. package/dist/output_parsers/openai_tools/json_output_tools_parsers.js +75 -12
  37. package/dist/output_parsers/transform.cjs +7 -6
  38. package/dist/output_parsers/transform.d.ts +1 -1
  39. package/dist/output_parsers/transform.js +3 -2
  40. package/dist/utils/function_calling.cjs +18 -6
  41. package/dist/utils/function_calling.d.ts +2 -1
  42. package/dist/utils/function_calling.js +16 -5
  43. package/dist/utils/json.cjs +93 -0
  44. package/dist/utils/json.d.ts +2 -0
  45. package/dist/utils/json.js +88 -0
  46. package/dist/utils/testing/index.cjs +3 -0
  47. package/dist/utils/testing/index.js +3 -0
  48. package/messages/tool.cjs +1 -0
  49. package/messages/tool.d.cts +1 -0
  50. package/messages/tool.d.ts +1 -0
  51. package/messages/tool.js +1 -0
  52. package/package.json +14 -1
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parsePartialJson = exports.parseJsonMarkdown = void 0;
4
+ function parseJsonMarkdown(s, parser = parsePartialJson) {
5
+ // eslint-disable-next-line no-param-reassign
6
+ s = s.trim();
7
+ const match = /```(json)?(.*)```/s.exec(s);
8
+ if (!match) {
9
+ return parser(s);
10
+ }
11
+ else {
12
+ return parser(match[2]);
13
+ }
14
+ }
15
+ exports.parseJsonMarkdown = parseJsonMarkdown;
16
+ // Adapted from https://github.com/KillianLucas/open-interpreter/blob/main/interpreter/core/llm/utils/parse_partial_json.py
17
+ // MIT License
18
+ function parsePartialJson(s) {
19
+ // If the input is undefined, return null to indicate failure.
20
+ if (typeof s === "undefined") {
21
+ return null;
22
+ }
23
+ // Attempt to parse the string as-is.
24
+ try {
25
+ return JSON.parse(s);
26
+ }
27
+ catch (error) {
28
+ // Pass
29
+ }
30
+ // Initialize variables.
31
+ let new_s = "";
32
+ const stack = [];
33
+ let isInsideString = false;
34
+ let escaped = false;
35
+ // Process each character in the string one at a time.
36
+ for (let char of s) {
37
+ if (isInsideString) {
38
+ if (char === '"' && !escaped) {
39
+ isInsideString = false;
40
+ }
41
+ else if (char === "\n" && !escaped) {
42
+ char = "\\n"; // Replace the newline character with the escape sequence.
43
+ }
44
+ else if (char === "\\") {
45
+ escaped = !escaped;
46
+ }
47
+ else {
48
+ escaped = false;
49
+ }
50
+ }
51
+ else {
52
+ if (char === '"') {
53
+ isInsideString = true;
54
+ escaped = false;
55
+ }
56
+ else if (char === "{") {
57
+ stack.push("}");
58
+ }
59
+ else if (char === "[") {
60
+ stack.push("]");
61
+ }
62
+ else if (char === "}" || char === "]") {
63
+ if (stack && stack[stack.length - 1] === char) {
64
+ stack.pop();
65
+ }
66
+ else {
67
+ // Mismatched closing character; the input is malformed.
68
+ return null;
69
+ }
70
+ }
71
+ }
72
+ // Append the processed character to the new string.
73
+ new_s += char;
74
+ }
75
+ // If we're still inside a string at the end of processing,
76
+ // we need to close the string.
77
+ if (isInsideString) {
78
+ new_s += '"';
79
+ }
80
+ // Close any remaining open structures in the reverse order that they were opened.
81
+ for (let i = stack.length - 1; i >= 0; i -= 1) {
82
+ new_s += stack[i];
83
+ }
84
+ // Attempt to parse the modified string as JSON.
85
+ try {
86
+ return JSON.parse(new_s);
87
+ }
88
+ catch (error) {
89
+ // If we still can't parse the string as JSON, return null to indicate failure.
90
+ return null;
91
+ }
92
+ }
93
+ exports.parsePartialJson = parsePartialJson;
@@ -0,0 +1,2 @@
1
+ export declare function parseJsonMarkdown(s: string, parser?: typeof parsePartialJson): any;
2
+ export declare function parsePartialJson(s: string): any;
@@ -0,0 +1,88 @@
1
+ export function parseJsonMarkdown(s, parser = parsePartialJson) {
2
+ // eslint-disable-next-line no-param-reassign
3
+ s = s.trim();
4
+ const match = /```(json)?(.*)```/s.exec(s);
5
+ if (!match) {
6
+ return parser(s);
7
+ }
8
+ else {
9
+ return parser(match[2]);
10
+ }
11
+ }
12
+ // Adapted from https://github.com/KillianLucas/open-interpreter/blob/main/interpreter/core/llm/utils/parse_partial_json.py
13
+ // MIT License
14
+ export function parsePartialJson(s) {
15
+ // If the input is undefined, return null to indicate failure.
16
+ if (typeof s === "undefined") {
17
+ return null;
18
+ }
19
+ // Attempt to parse the string as-is.
20
+ try {
21
+ return JSON.parse(s);
22
+ }
23
+ catch (error) {
24
+ // Pass
25
+ }
26
+ // Initialize variables.
27
+ let new_s = "";
28
+ const stack = [];
29
+ let isInsideString = false;
30
+ let escaped = false;
31
+ // Process each character in the string one at a time.
32
+ for (let char of s) {
33
+ if (isInsideString) {
34
+ if (char === '"' && !escaped) {
35
+ isInsideString = false;
36
+ }
37
+ else if (char === "\n" && !escaped) {
38
+ char = "\\n"; // Replace the newline character with the escape sequence.
39
+ }
40
+ else if (char === "\\") {
41
+ escaped = !escaped;
42
+ }
43
+ else {
44
+ escaped = false;
45
+ }
46
+ }
47
+ else {
48
+ if (char === '"') {
49
+ isInsideString = true;
50
+ escaped = false;
51
+ }
52
+ else if (char === "{") {
53
+ stack.push("}");
54
+ }
55
+ else if (char === "[") {
56
+ stack.push("]");
57
+ }
58
+ else if (char === "}" || char === "]") {
59
+ if (stack && stack[stack.length - 1] === char) {
60
+ stack.pop();
61
+ }
62
+ else {
63
+ // Mismatched closing character; the input is malformed.
64
+ return null;
65
+ }
66
+ }
67
+ }
68
+ // Append the processed character to the new string.
69
+ new_s += char;
70
+ }
71
+ // If we're still inside a string at the end of processing,
72
+ // we need to close the string.
73
+ if (isInsideString) {
74
+ new_s += '"';
75
+ }
76
+ // Close any remaining open structures in the reverse order that they were opened.
77
+ for (let i = stack.length - 1; i >= 0; i -= 1) {
78
+ new_s += stack[i];
79
+ }
80
+ // Attempt to parse the modified string as JSON.
81
+ try {
82
+ return JSON.parse(new_s);
83
+ }
84
+ catch (error) {
85
+ // If we still can't parse the string as JSON, return null to indicate failure.
86
+ return null;
87
+ }
88
+ }
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ /* eslint-disable no-promise-executor-return */
3
+ /* eslint-disable @typescript-eslint/no-explicit-any */
4
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.SingleRunExtractor = exports.SyntheticEmbeddings = exports.FakeEmbeddings = exports.FakeTool = exports.FakeTracer = exports.FakeListChatMessageHistory = exports.FakeChatMessageHistory = exports.FakeListChatModel = exports.FakeRetriever = exports.FakeStreamingChatModel = exports.FakeChatModel = exports.FakeStreamingLLM = exports.FakeLLM = exports.FakeRunnable = exports.FakeSplitIntoListParser = void 0;
4
7
  const chat_history_js_1 = require("../../chat_history.cjs");
@@ -1,3 +1,6 @@
1
+ /* eslint-disable no-promise-executor-return */
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ /* eslint-disable @typescript-eslint/no-unused-vars */
1
4
  import { BaseChatMessageHistory, BaseListChatMessageHistory, } from "../../chat_history.js";
2
5
  import { Document } from "../../documents/document.js";
3
6
  import { BaseChatModel, } from "../../language_models/chat_models.js";
@@ -0,0 +1 @@
1
+ module.exports = require('../dist/messages/tool.cjs');
@@ -0,0 +1 @@
1
+ export * from '../dist/messages/tool.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/messages/tool.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/messages/tool.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.1.55-rc.0",
3
+ "version": "0.1.56",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {
@@ -237,6 +237,15 @@
237
237
  "import": "./messages.js",
238
238
  "require": "./messages.cjs"
239
239
  },
240
+ "./messages/tool": {
241
+ "types": {
242
+ "import": "./messages/tool.d.ts",
243
+ "require": "./messages/tool.d.cts",
244
+ "default": "./messages/tool.d.ts"
245
+ },
246
+ "import": "./messages/tool.js",
247
+ "require": "./messages/tool.cjs"
248
+ },
240
249
  "./output_parsers": {
241
250
  "types": {
242
251
  "import": "./output_parsers.d.ts",
@@ -620,6 +629,10 @@
620
629
  "messages.js",
621
630
  "messages.d.ts",
622
631
  "messages.d.cts",
632
+ "messages/tool.cjs",
633
+ "messages/tool.js",
634
+ "messages/tool.d.ts",
635
+ "messages/tool.d.cts",
623
636
  "output_parsers.cjs",
624
637
  "output_parsers.js",
625
638
  "output_parsers.d.ts",