@langchain/core 1.1.1 → 1.1.3
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/CHANGELOG.md +16 -0
- package/dist/agents.d.cts +0 -2
- package/dist/agents.d.ts +0 -2
- package/dist/callbacks/base.d.cts +22 -60
- package/dist/callbacks/base.d.ts +22 -60
- package/dist/callbacks/dispatch/index.d.cts +1 -3
- package/dist/callbacks/dispatch/index.d.ts +1 -3
- package/dist/callbacks/dispatch/web.d.cts +1 -3
- package/dist/callbacks/dispatch/web.d.ts +1 -3
- package/dist/callbacks/manager.d.cts +2 -12
- package/dist/callbacks/manager.d.ts +2 -12
- package/dist/chat_history.cjs +1 -1
- package/dist/chat_history.d.cts +0 -1
- package/dist/chat_history.d.ts +0 -1
- package/dist/chat_history.js +1 -1
- package/dist/document_loaders/langsmith.d.cts +0 -3
- package/dist/document_loaders/langsmith.d.ts +0 -3
- package/dist/documents/document.d.cts +3 -12
- package/dist/documents/document.d.ts +3 -12
- package/dist/example_selectors/length_based.d.cts +1 -1
- package/dist/example_selectors/length_based.d.ts +1 -1
- package/dist/indexing/base.d.cts +0 -1
- package/dist/indexing/base.d.ts +0 -1
- package/dist/indexing/record_manager.d.cts +0 -1
- package/dist/indexing/record_manager.d.ts +0 -1
- package/dist/language_models/base.d.cts +8 -38
- package/dist/language_models/base.d.ts +8 -38
- package/dist/language_models/chat_models.cjs +1 -1
- package/dist/language_models/chat_models.d.cts +6 -33
- package/dist/language_models/chat_models.d.ts +6 -33
- package/dist/language_models/chat_models.js +1 -1
- package/dist/language_models/llms.d.cts +0 -6
- package/dist/language_models/llms.d.ts +0 -6
- package/dist/load/import_type.d.cts +0 -1
- package/dist/load/import_type.d.ts +0 -1
- package/dist/load/map_keys.cjs +4 -5
- package/dist/load/map_keys.cjs.map +1 -1
- package/dist/load/map_keys.d.cts +0 -1
- package/dist/load/map_keys.d.ts +0 -1
- package/dist/load/map_keys.js +3 -3
- package/dist/load/map_keys.js.map +1 -1
- package/dist/load/serializable.d.cts +0 -1
- package/dist/load/serializable.d.ts +0 -1
- package/dist/memory.d.cts +0 -3
- package/dist/memory.d.ts +0 -3
- package/dist/messages/ai.cjs +6 -48
- package/dist/messages/ai.cjs.map +1 -1
- package/dist/messages/ai.js +6 -48
- package/dist/messages/ai.js.map +1 -1
- package/dist/messages/base.cjs +3 -2
- package/dist/messages/base.cjs.map +1 -1
- package/dist/messages/base.d.cts +1 -13
- package/dist/messages/base.d.ts +1 -13
- package/dist/messages/base.js +3 -2
- package/dist/messages/base.js.map +1 -1
- package/dist/messages/content/data.d.cts +2 -7
- package/dist/messages/content/data.d.ts +2 -7
- package/dist/messages/content/index.d.cts +1 -4
- package/dist/messages/content/index.d.ts +1 -4
- package/dist/messages/content/multimodal.d.cts +0 -1
- package/dist/messages/content/multimodal.d.ts +0 -1
- package/dist/messages/content/tools.d.cts +0 -1
- package/dist/messages/content/tools.d.ts +0 -1
- package/dist/messages/index.cjs +4 -2
- package/dist/messages/index.d.cts +2 -2
- package/dist/messages/index.d.ts +2 -2
- package/dist/messages/index.js +5 -4
- package/dist/messages/tool.d.cts +2 -9
- package/dist/messages/tool.d.ts +2 -9
- package/dist/messages/transformers.cjs +2 -2
- package/dist/messages/transformers.d.cts +0 -3
- package/dist/messages/transformers.d.ts +0 -3
- package/dist/messages/transformers.js +2 -2
- package/dist/messages/utils.cjs +77 -4
- package/dist/messages/utils.cjs.map +1 -1
- package/dist/messages/utils.d.cts +35 -7
- package/dist/messages/utils.d.ts +35 -7
- package/dist/messages/utils.js +77 -5
- package/dist/messages/utils.js.map +1 -1
- package/dist/node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.cjs +169 -0
- package/dist/node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.js +168 -0
- package/dist/node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.js.map +1 -0
- package/dist/node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.cjs +122 -0
- package/dist/node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.js +121 -0
- package/dist/node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.js.map +1 -0
- package/dist/node_modules/.pnpm/decamelize@6.0.1/node_modules/decamelize/index.cjs +18 -0
- package/dist/node_modules/.pnpm/decamelize@6.0.1/node_modules/decamelize/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/decamelize@6.0.1/node_modules/decamelize/index.js +17 -0
- package/dist/node_modules/.pnpm/decamelize@6.0.1/node_modules/decamelize/index.js.map +1 -0
- package/dist/node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.cjs +27 -0
- package/dist/node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.js +26 -0
- package/dist/node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.js.map +1 -0
- package/dist/node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.cjs +141 -0
- package/dist/node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.js +141 -0
- package/dist/node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.js.map +1 -0
- package/dist/output_parsers/json.cjs.map +1 -1
- package/dist/output_parsers/json.d.cts +1 -5
- package/dist/output_parsers/json.d.ts +1 -5
- package/dist/output_parsers/json.js.map +1 -1
- package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.cts +2 -6
- package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.ts +2 -6
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.cts +10 -34
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.ts +10 -34
- package/dist/output_parsers/transform.d.cts +0 -1
- package/dist/output_parsers/transform.d.ts +0 -1
- package/dist/outputs.d.cts +0 -6
- package/dist/outputs.d.ts +0 -6
- package/dist/prompts/base.d.cts +2 -10
- package/dist/prompts/base.d.ts +2 -10
- package/dist/prompts/chat.cjs +2 -2
- package/dist/prompts/chat.d.cts +13 -51
- package/dist/prompts/chat.d.ts +13 -51
- package/dist/prompts/chat.js +2 -2
- package/dist/prompts/few_shot.d.cts +1 -5
- package/dist/prompts/few_shot.d.ts +1 -5
- package/dist/prompts/image.d.cts +2 -10
- package/dist/prompts/image.d.ts +2 -10
- package/dist/prompts/prompt.d.cts +4 -15
- package/dist/prompts/prompt.d.ts +4 -16
- package/dist/prompts/serde.d.cts +0 -1
- package/dist/prompts/serde.d.ts +0 -1
- package/dist/prompts/string.d.cts +1 -5
- package/dist/prompts/string.d.ts +1 -5
- package/dist/prompts/structured.d.cts +3 -16
- package/dist/prompts/structured.d.ts +3 -16
- package/dist/retrievers/document_compressors/index.d.cts +0 -1
- package/dist/retrievers/document_compressors/index.d.ts +0 -1
- package/dist/retrievers/index.d.cts +2 -6
- package/dist/retrievers/index.d.ts +2 -6
- package/dist/runnables/base.cjs +7 -7
- package/dist/runnables/base.cjs.map +1 -1
- package/dist/runnables/base.d.cts +12 -64
- package/dist/runnables/base.d.ts +12 -64
- package/dist/runnables/base.js +1 -1
- package/dist/runnables/branch.d.cts +0 -2
- package/dist/runnables/branch.d.ts +0 -2
- package/dist/runnables/config.d.cts +0 -1
- package/dist/runnables/config.d.ts +0 -1
- package/dist/runnables/graph.d.cts +1 -5
- package/dist/runnables/graph.d.ts +1 -5
- package/dist/runnables/graph_mermaid.cjs +2 -1
- package/dist/runnables/graph_mermaid.cjs.map +1 -1
- package/dist/runnables/graph_mermaid.js +3 -1
- package/dist/runnables/graph_mermaid.js.map +1 -1
- package/dist/runnables/history.cjs +1 -1
- package/dist/runnables/history.d.cts +4 -12
- package/dist/runnables/history.d.ts +4 -12
- package/dist/runnables/history.js +1 -1
- package/dist/runnables/passthrough.d.cts +0 -2
- package/dist/runnables/passthrough.d.ts +0 -2
- package/dist/runnables/router.d.cts +0 -1
- package/dist/runnables/router.d.ts +0 -1
- package/dist/runnables/types.d.cts +2 -9
- package/dist/runnables/types.d.ts +2 -9
- package/dist/runnables/utils.cjs +5 -0
- package/dist/runnables/utils.cjs.map +1 -1
- package/dist/runnables/utils.js +5 -1
- package/dist/runnables/utils.js.map +1 -1
- package/dist/singletons/async_local_storage/context.d.cts +0 -2
- package/dist/singletons/async_local_storage/context.d.ts +0 -2
- package/dist/singletons/async_local_storage/globals.d.cts +0 -1
- package/dist/singletons/async_local_storage/globals.d.ts +0 -1
- package/dist/singletons/callbacks.cjs.map +1 -1
- package/dist/singletons/callbacks.js.map +1 -1
- package/dist/stores.d.cts +0 -1
- package/dist/stores.d.ts +0 -1
- package/dist/structured_query/utils.d.cts +1 -4
- package/dist/structured_query/utils.d.ts +1 -4
- package/dist/tools/index.d.cts +1 -6
- package/dist/tools/index.d.ts +1 -6
- package/dist/tools/types.d.cts +3 -13
- package/dist/tools/types.d.ts +3 -13
- package/dist/tracers/base.d.cts +1 -20
- package/dist/tracers/base.d.ts +1 -20
- package/dist/tracers/console.cjs +3 -3
- package/dist/tracers/console.cjs.map +1 -1
- package/dist/tracers/console.d.cts +0 -2
- package/dist/tracers/console.d.ts +0 -2
- package/dist/tracers/console.js +3 -3
- package/dist/tracers/console.js.map +1 -1
- package/dist/tracers/event_stream.d.cts +0 -4
- package/dist/tracers/event_stream.d.ts +0 -4
- package/dist/tracers/log_stream.d.cts +0 -6
- package/dist/tracers/log_stream.d.ts +0 -6
- package/dist/types/_internal.d.cts +0 -3
- package/dist/types/_internal.d.ts +0 -3
- package/dist/types/type-utils.d.cts +0 -2
- package/dist/types/type-utils.d.ts +0 -2
- package/dist/utils/async_caller.cjs +2 -7
- package/dist/utils/async_caller.cjs.map +1 -1
- package/dist/utils/async_caller.d.cts +0 -3
- package/dist/utils/async_caller.d.ts +0 -3
- package/dist/utils/async_caller.js +1 -6
- package/dist/utils/async_caller.js.map +1 -1
- package/dist/utils/env.d.cts +0 -4
- package/dist/utils/env.d.ts +0 -4
- package/dist/utils/event_source_parse.d.cts +1 -4
- package/dist/utils/event_source_parse.d.ts +1 -4
- package/dist/utils/function_calling.d.cts +1 -3
- package/dist/utils/function_calling.d.ts +1 -3
- package/dist/utils/json.cjs +182 -22
- package/dist/utils/json.cjs.map +1 -1
- package/dist/utils/json.d.cts +1 -3
- package/dist/utils/json.d.ts +1 -3
- package/dist/utils/json.js +182 -22
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/stream.d.cts +1 -13
- package/dist/utils/stream.d.ts +1 -13
- package/dist/utils/testing/chat_models.d.cts +3 -11
- package/dist/utils/testing/chat_models.d.ts +3 -11
- package/dist/utils/testing/message_history.cjs +1 -1
- package/dist/utils/testing/message_history.js +1 -1
- package/dist/utils/testing/retrievers.d.cts +1 -3
- package/dist/utils/testing/retrievers.d.ts +1 -3
- package/dist/utils/testing/vectorstores.d.cts +0 -1
- package/dist/utils/testing/vectorstores.d.ts +0 -1
- package/dist/utils/types/index.cjs +4 -0
- package/dist/utils/types/index.d.cts +2 -4
- package/dist/utils/types/index.d.ts +2 -4
- package/dist/utils/types/index.js +4 -2
- package/dist/utils/types/zod.cjs +24 -0
- package/dist/utils/types/zod.cjs.map +1 -1
- package/dist/utils/types/zod.d.cts +4 -4
- package/dist/utils/types/zod.d.ts +4 -4
- package/dist/utils/types/zod.js +23 -1
- package/dist/utils/types/zod.js.map +1 -1
- package/dist/vectorstores.d.cts +5 -17
- package/dist/vectorstores.d.ts +5 -17
- package/package.json +6 -6
package/dist/utils/json.js
CHANGED
|
@@ -12,33 +12,193 @@ function parseJsonMarkdown(s, parser = parsePartialJson) {
|
|
|
12
12
|
if (closingFenceIndex !== -1) finalContent = contentAfterFence.substring(0, closingFenceIndex);
|
|
13
13
|
return parser(finalContent.trim());
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Recursive descent partial JSON parser.
|
|
17
|
+
* @param s - The string to parse.
|
|
18
|
+
* @returns The parsed value.
|
|
19
|
+
* @throws Error if the input is a malformed JSON string.
|
|
20
|
+
*/
|
|
21
|
+
function strictParsePartialJson(s) {
|
|
17
22
|
try {
|
|
18
23
|
return JSON.parse(s);
|
|
19
24
|
} catch {}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
const buffer = s.trim();
|
|
26
|
+
if (buffer.length === 0) throw new Error("Unexpected end of JSON input");
|
|
27
|
+
let pos = 0;
|
|
28
|
+
function skipWhitespace() {
|
|
29
|
+
while (pos < buffer.length && /\s/.test(buffer[pos])) pos += 1;
|
|
30
|
+
}
|
|
31
|
+
function parseString() {
|
|
32
|
+
if (buffer[pos] !== "\"") throw new Error(`Expected '"' at position ${pos}, got '${buffer[pos]}'`);
|
|
33
|
+
pos += 1;
|
|
34
|
+
let result = "";
|
|
35
|
+
let escaped = false;
|
|
36
|
+
while (pos < buffer.length) {
|
|
37
|
+
const char = buffer[pos];
|
|
38
|
+
if (escaped) {
|
|
39
|
+
if (char === "n") result += "\n";
|
|
40
|
+
else if (char === "t") result += " ";
|
|
41
|
+
else if (char === "r") result += "\r";
|
|
42
|
+
else if (char === "\\") result += "\\";
|
|
43
|
+
else if (char === "\"") result += "\"";
|
|
44
|
+
else if (char === "b") result += "\b";
|
|
45
|
+
else if (char === "f") result += "\f";
|
|
46
|
+
else if (char === "/") result += "/";
|
|
47
|
+
else if (char === "u") {
|
|
48
|
+
const hex = buffer.substring(pos + 1, pos + 5);
|
|
49
|
+
if (/^[0-9A-Fa-f]{0,4}$/.test(hex)) {
|
|
50
|
+
if (hex.length === 4) result += String.fromCharCode(Number.parseInt(hex, 16));
|
|
51
|
+
else result += `u${hex}`;
|
|
52
|
+
pos += hex.length;
|
|
53
|
+
} else throw new Error(`Invalid unicode escape sequence '\\u${hex}' at position ${pos}`);
|
|
54
|
+
} else throw new Error(`Invalid escape sequence '\\${char}' at position ${pos}`);
|
|
55
|
+
escaped = false;
|
|
56
|
+
} else if (char === "\\") escaped = true;
|
|
57
|
+
else if (char === "\"") {
|
|
58
|
+
pos += 1;
|
|
59
|
+
return result;
|
|
60
|
+
} else result += char;
|
|
61
|
+
pos += 1;
|
|
62
|
+
}
|
|
63
|
+
if (escaped) result += "\\";
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
function parseNumber() {
|
|
67
|
+
const start = pos;
|
|
68
|
+
let numStr = "";
|
|
69
|
+
if (buffer[pos] === "-") {
|
|
70
|
+
numStr += "-";
|
|
71
|
+
pos += 1;
|
|
72
|
+
}
|
|
73
|
+
if (pos < buffer.length && buffer[pos] === "0") {
|
|
74
|
+
numStr += "0";
|
|
75
|
+
pos += 1;
|
|
76
|
+
if (buffer[pos] >= "0" && buffer[pos] <= "9") throw new Error(`Invalid number at position ${start}`);
|
|
77
|
+
}
|
|
78
|
+
if (pos < buffer.length && buffer[pos] >= "1" && buffer[pos] <= "9") while (pos < buffer.length && buffer[pos] >= "0" && buffer[pos] <= "9") {
|
|
79
|
+
numStr += buffer[pos];
|
|
80
|
+
pos += 1;
|
|
81
|
+
}
|
|
82
|
+
if (pos < buffer.length && buffer[pos] === ".") {
|
|
83
|
+
numStr += ".";
|
|
84
|
+
pos += 1;
|
|
85
|
+
while (pos < buffer.length && buffer[pos] >= "0" && buffer[pos] <= "9") {
|
|
86
|
+
numStr += buffer[pos];
|
|
87
|
+
pos += 1;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (pos < buffer.length && (buffer[pos] === "e" || buffer[pos] === "E")) {
|
|
91
|
+
numStr += buffer[pos];
|
|
92
|
+
pos += 1;
|
|
93
|
+
if (pos < buffer.length && (buffer[pos] === "+" || buffer[pos] === "-")) {
|
|
94
|
+
numStr += buffer[pos];
|
|
95
|
+
pos += 1;
|
|
96
|
+
}
|
|
97
|
+
while (pos < buffer.length && buffer[pos] >= "0" && buffer[pos] <= "9") {
|
|
98
|
+
numStr += buffer[pos];
|
|
99
|
+
pos += 1;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (numStr === "-") return -0;
|
|
103
|
+
const num = Number.parseFloat(numStr);
|
|
104
|
+
if (Number.isNaN(num)) {
|
|
105
|
+
pos = start;
|
|
106
|
+
throw new Error(`Invalid number '${numStr}' at position ${start}`);
|
|
107
|
+
}
|
|
108
|
+
return num;
|
|
109
|
+
}
|
|
110
|
+
function parseValue() {
|
|
111
|
+
skipWhitespace();
|
|
112
|
+
if (pos >= buffer.length) throw new Error(`Unexpected end of input at position ${pos}`);
|
|
113
|
+
const char = buffer[pos];
|
|
114
|
+
if (char === "{") return parseObject();
|
|
115
|
+
if (char === "[") return parseArray();
|
|
116
|
+
if (char === "\"") return parseString();
|
|
117
|
+
if ("null".startsWith(buffer.substring(pos, pos + 4))) {
|
|
118
|
+
pos += Math.min(4, buffer.length - pos);
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
if ("true".startsWith(buffer.substring(pos, pos + 4))) {
|
|
122
|
+
pos += Math.min(4, buffer.length - pos);
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
if ("false".startsWith(buffer.substring(pos, pos + 5))) {
|
|
126
|
+
pos += Math.min(5, buffer.length - pos);
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
if (char === "-" || char >= "0" && char <= "9") return parseNumber();
|
|
130
|
+
throw new Error(`Unexpected character '${char}' at position ${pos}`);
|
|
37
131
|
}
|
|
38
|
-
|
|
39
|
-
|
|
132
|
+
function parseArray() {
|
|
133
|
+
if (buffer[pos] !== "[") throw new Error(`Expected '[' at position ${pos}, got '${buffer[pos]}'`);
|
|
134
|
+
const arr = [];
|
|
135
|
+
pos += 1;
|
|
136
|
+
skipWhitespace();
|
|
137
|
+
if (pos >= buffer.length) return arr;
|
|
138
|
+
if (buffer[pos] === "]") {
|
|
139
|
+
pos += 1;
|
|
140
|
+
return arr;
|
|
141
|
+
}
|
|
142
|
+
while (pos < buffer.length) {
|
|
143
|
+
skipWhitespace();
|
|
144
|
+
if (pos >= buffer.length) return arr;
|
|
145
|
+
arr.push(parseValue());
|
|
146
|
+
skipWhitespace();
|
|
147
|
+
if (pos >= buffer.length) return arr;
|
|
148
|
+
if (buffer[pos] === "]") {
|
|
149
|
+
pos += 1;
|
|
150
|
+
return arr;
|
|
151
|
+
} else if (buffer[pos] === ",") {
|
|
152
|
+
pos += 1;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
throw new Error(`Expected ',' or ']' at position ${pos}, got '${buffer[pos]}'`);
|
|
156
|
+
}
|
|
157
|
+
return arr;
|
|
158
|
+
}
|
|
159
|
+
function parseObject() {
|
|
160
|
+
if (buffer[pos] !== "{") throw new Error(`Expected '{' at position ${pos}, got '${buffer[pos]}'`);
|
|
161
|
+
const obj = {};
|
|
162
|
+
pos += 1;
|
|
163
|
+
skipWhitespace();
|
|
164
|
+
if (pos >= buffer.length) return obj;
|
|
165
|
+
if (buffer[pos] === "}") {
|
|
166
|
+
pos += 1;
|
|
167
|
+
return obj;
|
|
168
|
+
}
|
|
169
|
+
while (pos < buffer.length) {
|
|
170
|
+
skipWhitespace();
|
|
171
|
+
if (pos >= buffer.length) return obj;
|
|
172
|
+
const key = parseString();
|
|
173
|
+
skipWhitespace();
|
|
174
|
+
if (pos >= buffer.length) return obj;
|
|
175
|
+
if (buffer[pos] !== ":") throw new Error(`Expected ':' at position ${pos}, got '${buffer[pos]}'`);
|
|
176
|
+
pos += 1;
|
|
177
|
+
skipWhitespace();
|
|
178
|
+
if (pos >= buffer.length) return obj;
|
|
179
|
+
obj[key] = parseValue();
|
|
180
|
+
skipWhitespace();
|
|
181
|
+
if (pos >= buffer.length) return obj;
|
|
182
|
+
if (buffer[pos] === "}") {
|
|
183
|
+
pos += 1;
|
|
184
|
+
return obj;
|
|
185
|
+
} else if (buffer[pos] === ",") {
|
|
186
|
+
pos += 1;
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
throw new Error(`Expected ',' or '}' at position ${pos}, got '${buffer[pos]}'`);
|
|
190
|
+
}
|
|
191
|
+
return obj;
|
|
192
|
+
}
|
|
193
|
+
const value = parseValue();
|
|
194
|
+
skipWhitespace();
|
|
195
|
+
if (pos < buffer.length) throw new Error(`Unexpected character '${buffer[pos]}' at position ${pos}`);
|
|
196
|
+
return value;
|
|
197
|
+
}
|
|
198
|
+
function parsePartialJson(s) {
|
|
40
199
|
try {
|
|
41
|
-
|
|
200
|
+
if (typeof s === "undefined") return null;
|
|
201
|
+
return strictParsePartialJson(s);
|
|
42
202
|
} catch {
|
|
43
203
|
return null;
|
|
44
204
|
}
|
package/dist/utils/json.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.js","names":["s: string"],"sources":["../../src/utils/json.ts"],"sourcesContent":["export function parseJsonMarkdown(s: string, parser = parsePartialJson) {\n // eslint-disable-next-line no-param-reassign\n s = s.trim();\n\n const firstFenceIndex = s.indexOf(\"```\");\n if (firstFenceIndex === -1) {\n return parser(s);\n }\n\n let contentAfterFence = s.substring(firstFenceIndex + 3);\n\n if (contentAfterFence.startsWith(\"json\\n\")) {\n contentAfterFence = contentAfterFence.substring(5);\n } else if (contentAfterFence.startsWith(\"json\")) {\n contentAfterFence = contentAfterFence.substring(4);\n } else if (contentAfterFence.startsWith(\"\\n\")) {\n contentAfterFence = contentAfterFence.substring(1);\n }\n\n const closingFenceIndex = contentAfterFence.indexOf(\"```\");\n let finalContent = contentAfterFence;\n if (closingFenceIndex !== -1) {\n finalContent = contentAfterFence.substring(0, closingFenceIndex);\n }\n\n return parser(finalContent.trim());\n}\n\n// Adapted from https://github.com/KillianLucas/open-interpreter/blob/main/interpreter/core/llm/utils/parse_partial_json.py\n// MIT License\nexport function parsePartialJson(s: string) {\n // If the input is undefined, return null to indicate failure.\n if (typeof s === \"undefined\") {\n return null;\n }\n\n // Attempt to parse the string as-is.\n try {\n return JSON.parse(s);\n } catch {\n // Pass\n }\n\n // Initialize variables.\n let new_s = \"\";\n const stack = [];\n let isInsideString = false;\n let escaped = false;\n\n // Process each character in the string one at a time.\n for (let char of s) {\n if (isInsideString) {\n if (char === '\"' && !escaped) {\n isInsideString = false;\n } else if (char === \"\\n\" && !escaped) {\n char = \"\\\\n\"; // Replace the newline character with the escape sequence.\n } else if (char === \"\\\\\") {\n escaped = !escaped;\n } else {\n escaped = false;\n }\n } else {\n if (char === '\"') {\n isInsideString = true;\n escaped = false;\n } else if (char === \"{\") {\n stack.push(\"}\");\n } else if (char === \"[\") {\n stack.push(\"]\");\n } else if (char === \"}\" || char === \"]\") {\n if (stack && stack[stack.length - 1] === char) {\n stack.pop();\n } else {\n // Mismatched closing character; the input is malformed.\n return null;\n }\n }\n }\n\n // Append the processed character to the new string.\n new_s += char;\n }\n\n // If we're still inside a string at the end of processing,\n // we need to close the string.\n if (isInsideString) {\n new_s += '\"';\n }\n\n // Close any remaining open structures in the reverse order that they were opened.\n for (let i = stack.length - 1; i >= 0; i -= 1) {\n new_s += stack[i];\n }\n\n // Attempt to parse the modified string as JSON.\n try {\n return JSON.parse(new_s);\n } catch {\n // If we still can't parse the string as JSON, return null to indicate failure.\n return null;\n }\n}\n"],"mappings":";AAAA,SAAgB,kBAAkBA,GAAW,SAAS,kBAAkB;CAEtE,IAAI,EAAE,MAAM;CAEZ,MAAM,kBAAkB,EAAE,QAAQ,MAAM;AACxC,KAAI,oBAAoB,GACtB,QAAO,OAAO,EAAE;CAGlB,IAAI,oBAAoB,EAAE,UAAU,kBAAkB,EAAE;AAExD,KAAI,kBAAkB,WAAW,SAAS,EACxC,oBAAoB,kBAAkB,UAAU,EAAE;UACzC,kBAAkB,WAAW,OAAO,EAC7C,oBAAoB,kBAAkB,UAAU,EAAE;UACzC,kBAAkB,WAAW,KAAK,EAC3C,oBAAoB,kBAAkB,UAAU,EAAE;CAGpD,MAAM,oBAAoB,kBAAkB,QAAQ,MAAM;CAC1D,IAAI,eAAe;AACnB,KAAI,sBAAsB,IACxB,eAAe,kBAAkB,UAAU,GAAG,kBAAkB;AAGlE,QAAO,OAAO,aAAa,MAAM,CAAC;AACnC;AAID,SAAgB,iBAAiBA,GAAW;AAE1C,KAAI,OAAO,MAAM,YACf,QAAO;AAIT,KAAI;AACF,SAAO,KAAK,MAAM,EAAE;CACrB,QAAO,CAEP;CAGD,IAAI,QAAQ;CACZ,MAAM,QAAQ,CAAE;CAChB,IAAI,iBAAiB;CACrB,IAAI,UAAU;AAGd,MAAK,IAAI,QAAQ,GAAG;AAClB,MAAI,eACF,KAAI,SAAS,QAAO,CAAC,SACnB,iBAAiB;WACR,SAAS,QAAQ,CAAC,SAC3B,OAAO;WACE,SAAS,MAClB,UAAU,CAAC;OAEX,UAAU;WAGR,SAAS,MAAK;GAChB,iBAAiB;GACjB,UAAU;EACX,WAAU,SAAS,KAClB,MAAM,KAAK,IAAI;WACN,SAAS,KAClB,MAAM,KAAK,IAAI;WACN,SAAS,OAAO,SAAS,IAClC,KAAI,SAAS,MAAM,MAAM,SAAS,OAAO,MACvC,MAAM,KAAK;MAGX,QAAO;EAMb,SAAS;CACV;AAID,KAAI,gBACF,SAAS;AAIX,MAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK,GAC1C,SAAS,MAAM;AAIjB,KAAI;AACF,SAAO,KAAK,MAAM,MAAM;CACzB,QAAO;AAEN,SAAO;CACR;AACF"}
|
|
1
|
+
{"version":3,"file":"json.js","names":["s: string","arr: unknown[]","obj: Record<string, unknown>"],"sources":["../../src/utils/json.ts"],"sourcesContent":["export function parseJsonMarkdown(s: string, parser = parsePartialJson) {\n // eslint-disable-next-line no-param-reassign\n s = s.trim();\n\n const firstFenceIndex = s.indexOf(\"```\");\n if (firstFenceIndex === -1) {\n return parser(s);\n }\n\n let contentAfterFence = s.substring(firstFenceIndex + 3);\n\n if (contentAfterFence.startsWith(\"json\\n\")) {\n contentAfterFence = contentAfterFence.substring(5);\n } else if (contentAfterFence.startsWith(\"json\")) {\n contentAfterFence = contentAfterFence.substring(4);\n } else if (contentAfterFence.startsWith(\"\\n\")) {\n contentAfterFence = contentAfterFence.substring(1);\n }\n\n const closingFenceIndex = contentAfterFence.indexOf(\"```\");\n let finalContent = contentAfterFence;\n if (closingFenceIndex !== -1) {\n finalContent = contentAfterFence.substring(0, closingFenceIndex);\n }\n\n return parser(finalContent.trim());\n}\n\n/**\n * Recursive descent partial JSON parser.\n * @param s - The string to parse.\n * @returns The parsed value.\n * @throws Error if the input is a malformed JSON string.\n */\nexport function strictParsePartialJson(s: string): unknown {\n try {\n return JSON.parse(s);\n } catch {\n // Continue to partial parsing\n }\n\n const buffer = s.trim();\n if (buffer.length === 0) throw new Error(\"Unexpected end of JSON input\");\n\n let pos = 0;\n\n function skipWhitespace(): void {\n while (pos < buffer.length && /\\s/.test(buffer[pos])) {\n pos += 1;\n }\n }\n\n function parseString(): string {\n if (buffer[pos] !== '\"') {\n throw new Error(`Expected '\"' at position ${pos}, got '${buffer[pos]}'`);\n }\n\n pos += 1;\n let result = \"\";\n let escaped = false;\n\n while (pos < buffer.length) {\n const char = buffer[pos];\n\n if (escaped) {\n if (char === \"n\") {\n result += \"\\n\";\n } else if (char === \"t\") {\n result += \"\\t\";\n } else if (char === \"r\") {\n result += \"\\r\";\n } else if (char === \"\\\\\") {\n result += \"\\\\\";\n } else if (char === '\"') {\n result += '\"';\n } else if (char === \"b\") {\n result += \"\\b\";\n } else if (char === \"f\") {\n result += \"\\f\";\n } else if (char === \"/\") {\n result += \"/\";\n } else if (char === \"u\") {\n const hex = buffer.substring(pos + 1, pos + 5);\n if (/^[0-9A-Fa-f]{0,4}$/.test(hex)) {\n if (hex.length === 4) {\n result += String.fromCharCode(Number.parseInt(hex, 16));\n } else {\n result += `u${hex}`;\n }\n\n pos += hex.length;\n } else {\n throw new Error(\n `Invalid unicode escape sequence '\\\\u${hex}' at position ${pos}`\n );\n }\n } else {\n throw new Error(\n `Invalid escape sequence '\\\\${char}' at position ${pos}`\n );\n }\n escaped = false;\n } else if (char === \"\\\\\") {\n escaped = true;\n } else if (char === '\"') {\n pos += 1;\n return result;\n } else {\n result += char;\n }\n\n pos += 1;\n }\n\n if (escaped) result += \"\\\\\";\n return result;\n }\n\n function parseNumber(): number {\n const start = pos;\n let numStr = \"\";\n\n if (buffer[pos] === \"-\") {\n numStr += \"-\";\n pos += 1;\n }\n\n if (pos < buffer.length && buffer[pos] === \"0\") {\n numStr += \"0\";\n pos += 1;\n\n if (buffer[pos] >= \"0\" && buffer[pos] <= \"9\") {\n throw new Error(`Invalid number at position ${start}`);\n }\n }\n\n if (pos < buffer.length && buffer[pos] >= \"1\" && buffer[pos] <= \"9\") {\n while (pos < buffer.length && buffer[pos] >= \"0\" && buffer[pos] <= \"9\") {\n numStr += buffer[pos];\n pos += 1;\n }\n }\n\n if (pos < buffer.length && buffer[pos] === \".\") {\n numStr += \".\";\n pos += 1;\n while (pos < buffer.length && buffer[pos] >= \"0\" && buffer[pos] <= \"9\") {\n numStr += buffer[pos];\n pos += 1;\n }\n }\n\n if (pos < buffer.length && (buffer[pos] === \"e\" || buffer[pos] === \"E\")) {\n numStr += buffer[pos];\n pos += 1;\n if (pos < buffer.length && (buffer[pos] === \"+\" || buffer[pos] === \"-\")) {\n numStr += buffer[pos];\n pos += 1;\n }\n while (pos < buffer.length && buffer[pos] >= \"0\" && buffer[pos] <= \"9\") {\n numStr += buffer[pos];\n pos += 1;\n }\n }\n\n if (numStr === \"-\") return -0;\n\n const num = Number.parseFloat(numStr);\n\n if (Number.isNaN(num)) {\n pos = start;\n throw new Error(`Invalid number '${numStr}' at position ${start}`);\n }\n\n return num;\n }\n\n function parseValue(): unknown {\n skipWhitespace();\n\n if (pos >= buffer.length) {\n throw new Error(`Unexpected end of input at position ${pos}`);\n }\n\n const char = buffer[pos];\n\n if (char === \"{\") return parseObject();\n if (char === \"[\") return parseArray();\n if (char === '\"') return parseString();\n\n if (\"null\".startsWith(buffer.substring(pos, pos + 4))) {\n pos += Math.min(4, buffer.length - pos);\n return null;\n }\n\n if (\"true\".startsWith(buffer.substring(pos, pos + 4))) {\n pos += Math.min(4, buffer.length - pos);\n return true;\n }\n\n if (\"false\".startsWith(buffer.substring(pos, pos + 5))) {\n pos += Math.min(5, buffer.length - pos);\n return false;\n }\n\n if (char === \"-\" || (char >= \"0\" && char <= \"9\")) {\n return parseNumber();\n }\n\n throw new Error(`Unexpected character '${char}' at position ${pos}`);\n }\n\n function parseArray(): unknown[] {\n if (buffer[pos] !== \"[\") {\n throw new Error(`Expected '[' at position ${pos}, got '${buffer[pos]}'`);\n }\n\n const arr: unknown[] = [];\n\n pos += 1;\n skipWhitespace();\n\n if (pos >= buffer.length) return arr;\n if (buffer[pos] === \"]\") {\n pos += 1;\n return arr;\n }\n\n while (pos < buffer.length) {\n skipWhitespace();\n if (pos >= buffer.length) return arr;\n\n arr.push(parseValue());\n\n skipWhitespace();\n if (pos >= buffer.length) return arr;\n\n if (buffer[pos] === \"]\") {\n pos += 1;\n return arr;\n } else if (buffer[pos] === \",\") {\n pos += 1;\n continue;\n }\n\n throw new Error(\n `Expected ',' or ']' at position ${pos}, got '${buffer[pos]}'`\n );\n }\n\n return arr;\n }\n\n function parseObject(): Record<string, unknown> {\n if (buffer[pos] !== \"{\") {\n throw new Error(`Expected '{' at position ${pos}, got '${buffer[pos]}'`);\n }\n\n const obj: Record<string, unknown> = {};\n pos += 1;\n skipWhitespace();\n\n if (pos >= buffer.length) return obj;\n if (buffer[pos] === \"}\") {\n pos += 1;\n return obj;\n }\n\n while (pos < buffer.length) {\n skipWhitespace();\n if (pos >= buffer.length) return obj;\n\n const key = parseString();\n\n skipWhitespace();\n if (pos >= buffer.length) return obj;\n\n if (buffer[pos] !== \":\") {\n throw new Error(\n `Expected ':' at position ${pos}, got '${buffer[pos]}'`\n );\n }\n pos += 1;\n\n skipWhitespace();\n if (pos >= buffer.length) return obj;\n\n obj[key] = parseValue();\n\n skipWhitespace();\n if (pos >= buffer.length) return obj;\n\n if (buffer[pos] === \"}\") {\n pos += 1;\n return obj;\n } else if (buffer[pos] === \",\") {\n pos += 1;\n continue;\n }\n\n throw new Error(\n `Expected ',' or '}' at position ${pos}, got '${buffer[pos]}'`\n );\n }\n\n return obj;\n }\n\n const value = parseValue();\n skipWhitespace();\n\n if (pos < buffer.length) {\n throw new Error(`Unexpected character '${buffer[pos]}' at position ${pos}`);\n }\n\n return value;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function parsePartialJson(s: string): any | null {\n // Attempt to parse the modified string as JSON.\n try {\n if (typeof s === \"undefined\") return null;\n return strictParsePartialJson(s);\n } catch {\n // If we still can't parse the string as JSON, return null to indicate failure.\n return null;\n }\n}\n"],"mappings":";AAAA,SAAgB,kBAAkBA,GAAW,SAAS,kBAAkB;CAEtE,IAAI,EAAE,MAAM;CAEZ,MAAM,kBAAkB,EAAE,QAAQ,MAAM;AACxC,KAAI,oBAAoB,GACtB,QAAO,OAAO,EAAE;CAGlB,IAAI,oBAAoB,EAAE,UAAU,kBAAkB,EAAE;AAExD,KAAI,kBAAkB,WAAW,SAAS,EACxC,oBAAoB,kBAAkB,UAAU,EAAE;UACzC,kBAAkB,WAAW,OAAO,EAC7C,oBAAoB,kBAAkB,UAAU,EAAE;UACzC,kBAAkB,WAAW,KAAK,EAC3C,oBAAoB,kBAAkB,UAAU,EAAE;CAGpD,MAAM,oBAAoB,kBAAkB,QAAQ,MAAM;CAC1D,IAAI,eAAe;AACnB,KAAI,sBAAsB,IACxB,eAAe,kBAAkB,UAAU,GAAG,kBAAkB;AAGl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K;AAG5E,QAAO;AACR;AAGD,SAAgB,iBAAiBF,GAAuB;AAEtD,KAAI;AACF,MAAI,OAAO,MAAM,YAAa,QAAO;AACrC,SAAO,uBAAuB,EAAE;CACjC,QAAO;AAEN,SAAO;CACR;AACF"}
|
package/dist/utils/stream.d.cts
CHANGED
|
@@ -1,29 +1,19 @@
|
|
|
1
1
|
import { IterableReadableStreamInterface } from "../types/_internal.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/stream.d.ts
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
* Support async iterator syntax for ReadableStreams in all environments.
|
|
7
|
-
* Source: https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
|
|
8
|
-
*/
|
|
9
4
|
declare class IterableReadableStream<T> extends ReadableStream<T> implements IterableReadableStreamInterface<T> {
|
|
10
5
|
reader: ReadableStreamDefaultReader<T>;
|
|
11
6
|
ensureReader(): void;
|
|
12
7
|
next(): Promise<IteratorResult<T>>;
|
|
13
8
|
return(): Promise<IteratorResult<T>>;
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
9
|
throw(e: any): Promise<IteratorResult<T>>;
|
|
16
10
|
[Symbol.asyncIterator](): this;
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
18
|
-
// @ts-ignore Not present in Node 18 types, required in latest Node 22
|
|
19
11
|
[Symbol.asyncDispose](): Promise<void>;
|
|
20
12
|
static fromReadableStream<T>(stream: ReadableStream<T>): IterableReadableStream<T>;
|
|
21
13
|
static fromAsyncGenerator<T>(generator: AsyncGenerator<T>): IterableReadableStream<T>;
|
|
22
14
|
}
|
|
23
15
|
declare function atee<T>(iter: AsyncGenerator<T>, length?: number): AsyncGenerator<T>[];
|
|
24
|
-
declare function concat<
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
-
T extends Array<any> | string | number | Record<string, any> | any>(first: T, second: T): T;
|
|
16
|
+
declare function concat<T extends Array<any> | string | number | Record<string, any> | any>(first: T, second: T): T;
|
|
27
17
|
declare class AsyncGeneratorWithSetup<S = unknown, T = unknown, TReturn = unknown, TNext = unknown> implements AsyncGenerator<T, TReturn, TNext> {
|
|
28
18
|
private generator;
|
|
29
19
|
setup: Promise<S>;
|
|
@@ -41,8 +31,6 @@ declare class AsyncGeneratorWithSetup<S = unknown, T = unknown, TReturn = unknow
|
|
|
41
31
|
return(value?: TReturn | PromiseLike<TReturn>): Promise<IteratorResult<T>>;
|
|
42
32
|
throw(e: Error): Promise<IteratorResult<T>>;
|
|
43
33
|
[Symbol.asyncIterator](): this;
|
|
44
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
45
|
-
// @ts-ignore Not present in Node 18 types, required in latest Node 22
|
|
46
34
|
[Symbol.asyncDispose](): Promise<void>;
|
|
47
35
|
}
|
|
48
36
|
declare function pipeGeneratorWithSetup<S, A extends unknown[], T, TReturn, TNext, U, UReturn, UNext>(to: (g: AsyncGenerator<T, TReturn, TNext>, s: S, ...args: A) => AsyncGenerator<U, UReturn, UNext>, generator: AsyncGenerator<T, TReturn, TNext>, startSetup: () => Promise<S>, signal: AbortSignal | undefined, ...args: A): Promise<{
|
package/dist/utils/stream.d.ts
CHANGED
|
@@ -1,29 +1,19 @@
|
|
|
1
1
|
import { IterableReadableStreamInterface } from "../types/_internal.js";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/stream.d.ts
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
* Support async iterator syntax for ReadableStreams in all environments.
|
|
7
|
-
* Source: https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
|
|
8
|
-
*/
|
|
9
4
|
declare class IterableReadableStream<T> extends ReadableStream<T> implements IterableReadableStreamInterface<T> {
|
|
10
5
|
reader: ReadableStreamDefaultReader<T>;
|
|
11
6
|
ensureReader(): void;
|
|
12
7
|
next(): Promise<IteratorResult<T>>;
|
|
13
8
|
return(): Promise<IteratorResult<T>>;
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
9
|
throw(e: any): Promise<IteratorResult<T>>;
|
|
16
10
|
[Symbol.asyncIterator](): this;
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
18
|
-
// @ts-ignore Not present in Node 18 types, required in latest Node 22
|
|
19
11
|
[Symbol.asyncDispose](): Promise<void>;
|
|
20
12
|
static fromReadableStream<T>(stream: ReadableStream<T>): IterableReadableStream<T>;
|
|
21
13
|
static fromAsyncGenerator<T>(generator: AsyncGenerator<T>): IterableReadableStream<T>;
|
|
22
14
|
}
|
|
23
15
|
declare function atee<T>(iter: AsyncGenerator<T>, length?: number): AsyncGenerator<T>[];
|
|
24
|
-
declare function concat<
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
-
T extends Array<any> | string | number | Record<string, any> | any>(first: T, second: T): T;
|
|
16
|
+
declare function concat<T extends Array<any> | string | number | Record<string, any> | any>(first: T, second: T): T;
|
|
27
17
|
declare class AsyncGeneratorWithSetup<S = unknown, T = unknown, TReturn = unknown, TNext = unknown> implements AsyncGenerator<T, TReturn, TNext> {
|
|
28
18
|
private generator;
|
|
29
19
|
setup: Promise<S>;
|
|
@@ -41,8 +31,6 @@ declare class AsyncGeneratorWithSetup<S = unknown, T = unknown, TReturn = unknow
|
|
|
41
31
|
return(value?: TReturn | PromiseLike<TReturn>): Promise<IteratorResult<T>>;
|
|
42
32
|
throw(e: Error): Promise<IteratorResult<T>>;
|
|
43
33
|
[Symbol.asyncIterator](): this;
|
|
44
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
45
|
-
// @ts-ignore Not present in Node 18 types, required in latest Node 22
|
|
46
34
|
[Symbol.asyncDispose](): Promise<void>;
|
|
47
35
|
}
|
|
48
36
|
declare function pipeGeneratorWithSetup<S, A extends unknown[], T, TReturn, TNext, U, UReturn, UNext>(to: (g: AsyncGenerator<T, TReturn, TNext>, s: S, ...args: A) => AsyncGenerator<U, UReturn, UNext>, generator: AsyncGenerator<T, TReturn, TNext>, startSetup: () => Promise<S>, signal: AbortSignal | undefined, ...args: A): Promise<{
|
|
@@ -15,7 +15,7 @@ import { BaseLLMParams } from "../../language_models/llms.cjs";
|
|
|
15
15
|
interface ToolSpec {
|
|
16
16
|
name: string;
|
|
17
17
|
description?: string;
|
|
18
|
-
schema: InteropZodType | Record<string, unknown>;
|
|
18
|
+
schema: InteropZodType | Record<string, unknown>;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Interface specific to the Fake Streaming Chat model.
|
|
@@ -115,16 +115,8 @@ declare class FakeListChatModel extends BaseChatModel<FakeListChatModelCallOptio
|
|
|
115
115
|
_createResponseChunk(text: string): ChatGenerationChunk;
|
|
116
116
|
_currentResponse(): string;
|
|
117
117
|
_incrementResponse(): void;
|
|
118
|
-
withStructuredOutput<
|
|
119
|
-
|
|
120
|
-
RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, false> | InteropZodType<RunOutput>
|
|
121
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
122
|
-
| Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
|
|
123
|
-
withStructuredOutput<
|
|
124
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
125
|
-
RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, true> | InteropZodType<RunOutput>
|
|
126
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
127
|
-
| Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
|
|
118
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, false> | InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
|
|
119
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, true> | InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
|
|
128
120
|
raw: BaseMessage;
|
|
129
121
|
parsed: RunOutput;
|
|
130
122
|
}>;
|
|
@@ -16,7 +16,7 @@ import { BaseLLMParams } from "../../language_models/llms.js";
|
|
|
16
16
|
interface ToolSpec {
|
|
17
17
|
name: string;
|
|
18
18
|
description?: string;
|
|
19
|
-
schema: InteropZodType | Record<string, unknown>;
|
|
19
|
+
schema: InteropZodType | Record<string, unknown>;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Interface specific to the Fake Streaming Chat model.
|
|
@@ -116,16 +116,8 @@ declare class FakeListChatModel extends BaseChatModel<FakeListChatModelCallOptio
|
|
|
116
116
|
_createResponseChunk(text: string): ChatGenerationChunk;
|
|
117
117
|
_currentResponse(): string;
|
|
118
118
|
_incrementResponse(): void;
|
|
119
|
-
withStructuredOutput<
|
|
120
|
-
|
|
121
|
-
RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, false> | InteropZodType<RunOutput>
|
|
122
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
123
|
-
| Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
|
|
124
|
-
withStructuredOutput<
|
|
125
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
126
|
-
RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, true> | InteropZodType<RunOutput>
|
|
127
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
128
|
-
| Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
|
|
119
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, false> | InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
|
|
120
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, true> | InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
|
|
129
121
|
raw: BaseMessage;
|
|
130
122
|
parsed: RunOutput;
|
|
131
123
|
}>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_ai = require('../../messages/ai.cjs');
|
|
2
1
|
const require_human = require('../../messages/human.cjs');
|
|
2
|
+
const require_ai = require('../../messages/ai.cjs');
|
|
3
3
|
const require_tracers_base = require('../../tracers/base.cjs');
|
|
4
4
|
require('../../messages/index.cjs');
|
|
5
5
|
const require_chat_history = require('../../chat_history.cjs');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AIMessage } from "../../messages/ai.js";
|
|
2
1
|
import { HumanMessage } from "../../messages/human.js";
|
|
2
|
+
import { AIMessage } from "../../messages/ai.js";
|
|
3
3
|
import { BaseTracer } from "../../tracers/base.js";
|
|
4
4
|
import "../../messages/index.js";
|
|
5
5
|
import { BaseChatMessageHistory, BaseListChatMessageHistory } from "../../chat_history.js";
|
|
@@ -8,9 +8,7 @@ declare class FakeRetriever extends BaseRetriever {
|
|
|
8
8
|
constructor(fields?: {
|
|
9
9
|
output: Document[];
|
|
10
10
|
});
|
|
11
|
-
_getRelevantDocuments(_query: string
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
-
): Promise<Document<Record<string, any>>[]>;
|
|
11
|
+
_getRelevantDocuments(_query: string): Promise<Document<Record<string, any>>[]>;
|
|
14
12
|
}
|
|
15
13
|
//#endregion
|
|
16
14
|
export { FakeRetriever };
|
|
@@ -8,9 +8,7 @@ declare class FakeRetriever extends BaseRetriever {
|
|
|
8
8
|
constructor(fields?: {
|
|
9
9
|
output: Document[];
|
|
10
10
|
});
|
|
11
|
-
_getRelevantDocuments(_query: string
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
-
): Promise<Document<Record<string, any>>[]>;
|
|
11
|
+
_getRelevantDocuments(_query: string): Promise<Document<Record<string, any>>[]>;
|
|
14
12
|
}
|
|
15
13
|
//#endregion
|
|
16
14
|
export { FakeRetriever };
|
|
@@ -26,8 +26,10 @@ require_rolldown_runtime.__export(types_exports, {
|
|
|
26
26
|
isZodArrayV4: () => require_zod.isZodArrayV4,
|
|
27
27
|
isZodLiteralV3: () => require_zod.isZodLiteralV3,
|
|
28
28
|
isZodLiteralV4: () => require_zod.isZodLiteralV4,
|
|
29
|
+
isZodNullableV4: () => require_zod.isZodNullableV4,
|
|
29
30
|
isZodObjectV3: () => require_zod.isZodObjectV3,
|
|
30
31
|
isZodObjectV4: () => require_zod.isZodObjectV4,
|
|
32
|
+
isZodOptionalV4: () => require_zod.isZodOptionalV4,
|
|
31
33
|
isZodSchema: () => require_zod.isZodSchema,
|
|
32
34
|
isZodSchemaV3: () => require_zod.isZodSchemaV3,
|
|
33
35
|
isZodSchemaV4: () => require_zod.isZodSchemaV4
|
|
@@ -56,8 +58,10 @@ exports.isSimpleStringZodSchema = require_zod.isSimpleStringZodSchema;
|
|
|
56
58
|
exports.isZodArrayV4 = require_zod.isZodArrayV4;
|
|
57
59
|
exports.isZodLiteralV3 = require_zod.isZodLiteralV3;
|
|
58
60
|
exports.isZodLiteralV4 = require_zod.isZodLiteralV4;
|
|
61
|
+
exports.isZodNullableV4 = require_zod.isZodNullableV4;
|
|
59
62
|
exports.isZodObjectV3 = require_zod.isZodObjectV3;
|
|
60
63
|
exports.isZodObjectV4 = require_zod.isZodObjectV4;
|
|
64
|
+
exports.isZodOptionalV4 = require_zod.isZodOptionalV4;
|
|
61
65
|
exports.isZodSchema = require_zod.isZodSchema;
|
|
62
66
|
exports.isZodSchemaV3 = require_zod.isZodSchemaV3;
|
|
63
67
|
exports.isZodSchemaV4 = require_zod.isZodSchemaV4;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InferInteropZodInput, InferInteropZodOutput, InteropZodDefault, InteropZodIssue, InteropZodLiteral, InteropZodObject, InteropZodObjectShape, InteropZodOptional, InteropZodType, Mutable, ZodDefaultV3, ZodDefaultV4, ZodObjectV3, ZodObjectV4, ZodOptionalV3, ZodOptionalV4, ZodStringV3, ZodStringV4, extendInteropZodObject, getInteropZodDefaultGetter, getInteropZodObjectShape, getSchemaDescription, interopParse, interopParseAsync, interopSafeParse, interopSafeParseAsync, interopZodObjectMakeFieldsOptional, interopZodObjectPartial, interopZodObjectPassthrough, interopZodObjectStrict, interopZodTransformInputSchema, isInteropZodError, isInteropZodLiteral, isInteropZodObject, isInteropZodSchema, isShapelessZodSchema, isSimpleStringZodSchema, isZodArrayV4, isZodLiteralV3, isZodLiteralV4, isZodObjectV3, isZodObjectV4, isZodSchema, isZodSchemaV3, isZodSchemaV4 } from "./zod.cjs";
|
|
1
|
+
import { InferInteropZodInput, InferInteropZodOutput, InteropZodDefault, InteropZodIssue, InteropZodLiteral, InteropZodObject, InteropZodObjectShape, InteropZodOptional, InteropZodType, Mutable, ZodDefaultV3, ZodDefaultV4, ZodNullableV4, ZodObjectV3, ZodObjectV4, ZodOptionalV3, ZodOptionalV4, ZodStringV3, ZodStringV4, extendInteropZodObject, getInteropZodDefaultGetter, getInteropZodObjectShape, getSchemaDescription, interopParse, interopParseAsync, interopSafeParse, interopSafeParseAsync, interopZodObjectMakeFieldsOptional, interopZodObjectPartial, interopZodObjectPassthrough, interopZodObjectStrict, interopZodTransformInputSchema, isInteropZodError, isInteropZodLiteral, isInteropZodObject, isInteropZodSchema, isShapelessZodSchema, isSimpleStringZodSchema, isZodArrayV4, isZodLiteralV3, isZodLiteralV4, isZodNullableV4, isZodObjectV3, isZodObjectV4, isZodOptionalV4, isZodSchema, isZodSchemaV3, isZodSchemaV4 } from "./zod.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/types/index.d.ts
|
|
4
4
|
|
|
@@ -6,11 +6,9 @@ import { InferInteropZodInput, InferInteropZodOutput, InteropZodDefault, Interop
|
|
|
6
6
|
* Represents a string value with autocompleted, but not required, suggestions.
|
|
7
7
|
*/
|
|
8
8
|
type StringWithAutocomplete<T> = T | (string & Record<never, never>);
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
9
|
type InputValues<K extends string = string> = Record<K, any>;
|
|
11
10
|
type PartialValues<K extends string = string> = Record<K, string | (() => Promise<string>) | (() => string)>;
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
11
|
type ChainValues = Record<string, any>;
|
|
14
12
|
//#endregion
|
|
15
|
-
export { ChainValues, InferInteropZodInput, InferInteropZodOutput, InputValues, InteropZodDefault, InteropZodIssue, InteropZodLiteral, InteropZodObject, InteropZodObjectShape, InteropZodOptional, InteropZodType, Mutable, PartialValues, StringWithAutocomplete, ZodDefaultV3, ZodDefaultV4, ZodObjectV3, ZodObjectV4, ZodOptionalV3, ZodOptionalV4, ZodStringV3, ZodStringV4, extendInteropZodObject, getInteropZodDefaultGetter, getInteropZodObjectShape, getSchemaDescription, interopParse, interopParseAsync, interopSafeParse, interopSafeParseAsync, interopZodObjectMakeFieldsOptional, interopZodObjectPartial, interopZodObjectPassthrough, interopZodObjectStrict, interopZodTransformInputSchema, isInteropZodError, isInteropZodLiteral, isInteropZodObject, isInteropZodSchema, isShapelessZodSchema, isSimpleStringZodSchema, isZodArrayV4, isZodLiteralV3, isZodLiteralV4, isZodObjectV3, isZodObjectV4, isZodSchema, isZodSchemaV3, isZodSchemaV4 };
|
|
13
|
+
export { ChainValues, InferInteropZodInput, InferInteropZodOutput, InputValues, InteropZodDefault, InteropZodIssue, InteropZodLiteral, InteropZodObject, InteropZodObjectShape, InteropZodOptional, InteropZodType, Mutable, PartialValues, StringWithAutocomplete, ZodDefaultV3, ZodDefaultV4, ZodNullableV4, ZodObjectV3, ZodObjectV4, ZodOptionalV3, ZodOptionalV4, ZodStringV3, ZodStringV4, extendInteropZodObject, getInteropZodDefaultGetter, getInteropZodObjectShape, getSchemaDescription, interopParse, interopParseAsync, interopSafeParse, interopSafeParseAsync, interopZodObjectMakeFieldsOptional, interopZodObjectPartial, interopZodObjectPassthrough, interopZodObjectStrict, interopZodTransformInputSchema, isInteropZodError, isInteropZodLiteral, isInteropZodObject, isInteropZodSchema, isShapelessZodSchema, isSimpleStringZodSchema, isZodArrayV4, isZodLiteralV3, isZodLiteralV4, isZodNullableV4, isZodObjectV3, isZodObjectV4, isZodOptionalV4, isZodSchema, isZodSchemaV3, isZodSchemaV4 };
|
|
16
14
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InferInteropZodInput, InferInteropZodOutput, InteropZodDefault, InteropZodIssue, InteropZodLiteral, InteropZodObject, InteropZodObjectShape, InteropZodOptional, InteropZodType, Mutable, ZodDefaultV3, ZodDefaultV4, ZodObjectV3, ZodObjectV4, ZodOptionalV3, ZodOptionalV4, ZodStringV3, ZodStringV4, extendInteropZodObject, getInteropZodDefaultGetter, getInteropZodObjectShape, getSchemaDescription, interopParse, interopParseAsync, interopSafeParse, interopSafeParseAsync, interopZodObjectMakeFieldsOptional, interopZodObjectPartial, interopZodObjectPassthrough, interopZodObjectStrict, interopZodTransformInputSchema, isInteropZodError, isInteropZodLiteral, isInteropZodObject, isInteropZodSchema, isShapelessZodSchema, isSimpleStringZodSchema, isZodArrayV4, isZodLiteralV3, isZodLiteralV4, isZodObjectV3, isZodObjectV4, isZodSchema, isZodSchemaV3, isZodSchemaV4 } from "./zod.js";
|
|
1
|
+
import { InferInteropZodInput, InferInteropZodOutput, InteropZodDefault, InteropZodIssue, InteropZodLiteral, InteropZodObject, InteropZodObjectShape, InteropZodOptional, InteropZodType, Mutable, ZodDefaultV3, ZodDefaultV4, ZodNullableV4, ZodObjectV3, ZodObjectV4, ZodOptionalV3, ZodOptionalV4, ZodStringV3, ZodStringV4, extendInteropZodObject, getInteropZodDefaultGetter, getInteropZodObjectShape, getSchemaDescription, interopParse, interopParseAsync, interopSafeParse, interopSafeParseAsync, interopZodObjectMakeFieldsOptional, interopZodObjectPartial, interopZodObjectPassthrough, interopZodObjectStrict, interopZodTransformInputSchema, isInteropZodError, isInteropZodLiteral, isInteropZodObject, isInteropZodSchema, isShapelessZodSchema, isSimpleStringZodSchema, isZodArrayV4, isZodLiteralV3, isZodLiteralV4, isZodNullableV4, isZodObjectV3, isZodObjectV4, isZodOptionalV4, isZodSchema, isZodSchemaV3, isZodSchemaV4 } from "./zod.js";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/types/index.d.ts
|
|
4
4
|
|
|
@@ -6,11 +6,9 @@ import { InferInteropZodInput, InferInteropZodOutput, InteropZodDefault, Interop
|
|
|
6
6
|
* Represents a string value with autocompleted, but not required, suggestions.
|
|
7
7
|
*/
|
|
8
8
|
type StringWithAutocomplete<T> = T | (string & Record<never, never>);
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
9
|
type InputValues<K extends string = string> = Record<K, any>;
|
|
11
10
|
type PartialValues<K extends string = string> = Record<K, string | (() => Promise<string>) | (() => string)>;
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
11
|
type ChainValues = Record<string, any>;
|
|
14
12
|
//#endregion
|
|
15
|
-
export { ChainValues, InferInteropZodInput, InferInteropZodOutput, InputValues, InteropZodDefault, InteropZodIssue, InteropZodLiteral, InteropZodObject, InteropZodObjectShape, InteropZodOptional, InteropZodType, Mutable, PartialValues, StringWithAutocomplete, ZodDefaultV3, ZodDefaultV4, ZodObjectV3, ZodObjectV4, ZodOptionalV3, ZodOptionalV4, ZodStringV3, ZodStringV4, extendInteropZodObject, getInteropZodDefaultGetter, getInteropZodObjectShape, getSchemaDescription, interopParse, interopParseAsync, interopSafeParse, interopSafeParseAsync, interopZodObjectMakeFieldsOptional, interopZodObjectPartial, interopZodObjectPassthrough, interopZodObjectStrict, interopZodTransformInputSchema, isInteropZodError, isInteropZodLiteral, isInteropZodObject, isInteropZodSchema, isShapelessZodSchema, isSimpleStringZodSchema, isZodArrayV4, isZodLiteralV3, isZodLiteralV4, isZodObjectV3, isZodObjectV4, isZodSchema, isZodSchemaV3, isZodSchemaV4 };
|
|
13
|
+
export { ChainValues, InferInteropZodInput, InferInteropZodOutput, InputValues, InteropZodDefault, InteropZodIssue, InteropZodLiteral, InteropZodObject, InteropZodObjectShape, InteropZodOptional, InteropZodType, Mutable, PartialValues, StringWithAutocomplete, ZodDefaultV3, ZodDefaultV4, ZodNullableV4, ZodObjectV3, ZodObjectV4, ZodOptionalV3, ZodOptionalV4, ZodStringV3, ZodStringV4, extendInteropZodObject, getInteropZodDefaultGetter, getInteropZodObjectShape, getSchemaDescription, interopParse, interopParseAsync, interopSafeParse, interopSafeParseAsync, interopZodObjectMakeFieldsOptional, interopZodObjectPartial, interopZodObjectPassthrough, interopZodObjectStrict, interopZodTransformInputSchema, isInteropZodError, isInteropZodLiteral, isInteropZodObject, isInteropZodSchema, isShapelessZodSchema, isSimpleStringZodSchema, isZodArrayV4, isZodLiteralV3, isZodLiteralV4, isZodNullableV4, isZodObjectV3, isZodObjectV4, isZodOptionalV4, isZodSchema, isZodSchemaV3, isZodSchemaV4 };
|
|
16
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __export } from "../../_virtual/rolldown_runtime.js";
|
|
2
|
-
import { extendInteropZodObject, getInteropZodDefaultGetter, getInteropZodObjectShape, getSchemaDescription, interopParse, interopParseAsync, interopSafeParse, interopSafeParseAsync, interopZodObjectMakeFieldsOptional, interopZodObjectPartial, interopZodObjectPassthrough, interopZodObjectStrict, interopZodTransformInputSchema, isInteropZodError, isInteropZodLiteral, isInteropZodObject, isInteropZodSchema, isShapelessZodSchema, isSimpleStringZodSchema, isZodArrayV4, isZodLiteralV3, isZodLiteralV4, isZodObjectV3, isZodObjectV4, isZodSchema, isZodSchemaV3, isZodSchemaV4 } from "./zod.js";
|
|
2
|
+
import { extendInteropZodObject, getInteropZodDefaultGetter, getInteropZodObjectShape, getSchemaDescription, interopParse, interopParseAsync, interopSafeParse, interopSafeParseAsync, interopZodObjectMakeFieldsOptional, interopZodObjectPartial, interopZodObjectPassthrough, interopZodObjectStrict, interopZodTransformInputSchema, isInteropZodError, isInteropZodLiteral, isInteropZodObject, isInteropZodSchema, isShapelessZodSchema, isSimpleStringZodSchema, isZodArrayV4, isZodLiteralV3, isZodLiteralV4, isZodNullableV4, isZodObjectV3, isZodObjectV4, isZodOptionalV4, isZodSchema, isZodSchemaV3, isZodSchemaV4 } from "./zod.js";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/types/index.ts
|
|
5
5
|
var types_exports = {};
|
|
@@ -26,13 +26,15 @@ __export(types_exports, {
|
|
|
26
26
|
isZodArrayV4: () => isZodArrayV4,
|
|
27
27
|
isZodLiteralV3: () => isZodLiteralV3,
|
|
28
28
|
isZodLiteralV4: () => isZodLiteralV4,
|
|
29
|
+
isZodNullableV4: () => isZodNullableV4,
|
|
29
30
|
isZodObjectV3: () => isZodObjectV3,
|
|
30
31
|
isZodObjectV4: () => isZodObjectV4,
|
|
32
|
+
isZodOptionalV4: () => isZodOptionalV4,
|
|
31
33
|
isZodSchema: () => isZodSchema,
|
|
32
34
|
isZodSchemaV3: () => isZodSchemaV3,
|
|
33
35
|
isZodSchemaV4: () => isZodSchemaV4
|
|
34
36
|
});
|
|
35
37
|
|
|
36
38
|
//#endregion
|
|
37
|
-
export { extendInteropZodObject, getInteropZodDefaultGetter, getInteropZodObjectShape, getSchemaDescription, interopParse, interopParseAsync, interopSafeParse, interopSafeParseAsync, interopZodObjectMakeFieldsOptional, interopZodObjectPartial, interopZodObjectPassthrough, interopZodObjectStrict, interopZodTransformInputSchema, isInteropZodError, isInteropZodLiteral, isInteropZodObject, isInteropZodSchema, isShapelessZodSchema, isSimpleStringZodSchema, isZodArrayV4, isZodLiteralV3, isZodLiteralV4, isZodObjectV3, isZodObjectV4, isZodSchema, isZodSchemaV3, isZodSchemaV4, types_exports };
|
|
39
|
+
export { extendInteropZodObject, getInteropZodDefaultGetter, getInteropZodObjectShape, getSchemaDescription, interopParse, interopParseAsync, interopSafeParse, interopSafeParseAsync, interopZodObjectMakeFieldsOptional, interopZodObjectPartial, interopZodObjectPassthrough, interopZodObjectStrict, interopZodTransformInputSchema, isInteropZodError, isInteropZodLiteral, isInteropZodObject, isInteropZodSchema, isShapelessZodSchema, isSimpleStringZodSchema, isZodArrayV4, isZodLiteralV3, isZodLiteralV4, isZodNullableV4, isZodObjectV3, isZodObjectV4, isZodOptionalV4, isZodSchema, isZodSchemaV3, isZodSchemaV4, types_exports };
|
|
38
40
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/types/zod.cjs
CHANGED
|
@@ -230,6 +230,16 @@ function isZodArrayV4(obj) {
|
|
|
230
230
|
if (typeof obj === "object" && obj !== null && "_zod" in obj && typeof obj._zod === "object" && obj._zod !== null && "def" in obj._zod && typeof obj._zod.def === "object" && obj._zod.def !== null && "type" in obj._zod.def && obj._zod.def.type === "array") return true;
|
|
231
231
|
return false;
|
|
232
232
|
}
|
|
233
|
+
function isZodOptionalV4(obj) {
|
|
234
|
+
if (!isZodSchemaV4(obj)) return false;
|
|
235
|
+
if (typeof obj === "object" && obj !== null && "_zod" in obj && typeof obj._zod === "object" && obj._zod !== null && "def" in obj._zod && typeof obj._zod.def === "object" && obj._zod.def !== null && "type" in obj._zod.def && obj._zod.def.type === "optional") return true;
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
function isZodNullableV4(obj) {
|
|
239
|
+
if (!isZodSchemaV4(obj)) return false;
|
|
240
|
+
if (typeof obj === "object" && obj !== null && "_zod" in obj && typeof obj._zod === "object" && obj._zod !== null && "def" in obj._zod && typeof obj._zod.def === "object" && obj._zod.def !== null && "type" in obj._zod.def && obj._zod.def.type === "nullable") return true;
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
233
243
|
/**
|
|
234
244
|
* Determines if the provided value is an InteropZodObject (Zod v3 or v4 object schema).
|
|
235
245
|
*
|
|
@@ -419,6 +429,18 @@ function interopZodTransformInputSchemaImpl(schema, recursive, cache) {
|
|
|
419
429
|
...outputSchema._zod.def,
|
|
420
430
|
element: elementSchema
|
|
421
431
|
});
|
|
432
|
+
} else if (isZodOptionalV4(outputSchema)) {
|
|
433
|
+
const innerSchema = interopZodTransformInputSchemaImpl(outputSchema._zod.def.innerType, recursive, cache);
|
|
434
|
+
outputSchema = (0, zod_v4_core.clone)(outputSchema, {
|
|
435
|
+
...outputSchema._zod.def,
|
|
436
|
+
innerType: innerSchema
|
|
437
|
+
});
|
|
438
|
+
} else if (isZodNullableV4(outputSchema)) {
|
|
439
|
+
const innerSchema = interopZodTransformInputSchemaImpl(outputSchema._zod.def.innerType, recursive, cache);
|
|
440
|
+
outputSchema = (0, zod_v4_core.clone)(outputSchema, {
|
|
441
|
+
...outputSchema._zod.def,
|
|
442
|
+
innerType: innerSchema
|
|
443
|
+
});
|
|
422
444
|
}
|
|
423
445
|
}
|
|
424
446
|
const meta = zod_v4_core.globalRegistry.get(schema);
|
|
@@ -503,8 +525,10 @@ exports.isSimpleStringZodSchema = isSimpleStringZodSchema;
|
|
|
503
525
|
exports.isZodArrayV4 = isZodArrayV4;
|
|
504
526
|
exports.isZodLiteralV3 = isZodLiteralV3;
|
|
505
527
|
exports.isZodLiteralV4 = isZodLiteralV4;
|
|
528
|
+
exports.isZodNullableV4 = isZodNullableV4;
|
|
506
529
|
exports.isZodObjectV3 = isZodObjectV3;
|
|
507
530
|
exports.isZodObjectV4 = isZodObjectV4;
|
|
531
|
+
exports.isZodOptionalV4 = isZodOptionalV4;
|
|
508
532
|
exports.isZodSchema = isZodSchema;
|
|
509
533
|
exports.isZodSchemaV3 = isZodSchemaV3;
|
|
510
534
|
exports.isZodSchemaV4 = isZodSchemaV4;
|