@langchain/core 0.3.59 → 0.3.61
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/caches/base.cjs +28 -5
- package/dist/caches/base.d.ts +13 -1
- package/dist/caches/base.js +25 -2
- package/dist/callbacks/base.cjs +19 -9
- package/dist/callbacks/base.d.ts +37 -22
- package/dist/callbacks/dispatch/index.cjs +1 -2
- package/dist/callbacks/dispatch/web.cjs +1 -2
- package/dist/callbacks/manager.cjs +4 -4
- package/dist/callbacks/manager.d.ts +2 -2
- package/dist/errors/index.cjs +1 -2
- package/dist/example_selectors/conditional.cjs +3 -3
- package/dist/indexing/base.cjs +19 -7
- package/dist/indexing/base.d.ts +3 -0
- package/dist/indexing/base.js +14 -2
- package/dist/language_models/base.cjs +2 -2
- package/dist/language_models/chat_models.cjs +2 -2
- package/dist/load/import_map.cjs +17 -7
- package/dist/load/index.cjs +18 -9
- package/dist/load/map_keys.cjs +3 -4
- package/dist/load/serializable.cjs +2 -2
- package/dist/memory.cjs +2 -2
- package/dist/messages/ai.cjs +3 -3
- package/dist/messages/base.cjs +10 -10
- package/dist/messages/chat.cjs +3 -3
- package/dist/messages/content_blocks.cjs +9 -10
- package/dist/messages/function.cjs +3 -3
- package/dist/messages/human.cjs +3 -3
- package/dist/messages/system.cjs +3 -3
- package/dist/messages/tool.cjs +5 -5
- package/dist/messages/transformers.cjs +4 -5
- package/dist/messages/utils.cjs +6 -7
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs +4 -4
- package/dist/output_parsers/xml.cjs +2 -2
- package/dist/prompts/base.cjs +36 -3
- package/dist/runnables/base.cjs +7 -5
- package/dist/runnables/base.d.ts +1 -1
- package/dist/runnables/base.js +3 -1
- package/dist/runnables/config.cjs +6 -6
- package/dist/runnables/graph_mermaid.cjs +2 -3
- package/dist/runnables/iter.cjs +5 -5
- package/dist/runnables/iter.d.ts +1 -1
- package/dist/runnables/utils.cjs +2 -2
- package/dist/runnables/wrappers.cjs +1 -2
- package/dist/runnables/wrappers.d.ts +1 -1
- package/dist/singletons/async_local_storage/context.cjs +3 -3
- package/dist/singletons/callbacks.cjs +3 -4
- package/dist/singletons/callbacks.d.ts +1 -1
- package/dist/structured_query/utils.cjs +7 -8
- package/dist/tools/index.cjs +2 -2
- package/dist/tools/types.cjs +4 -5
- package/dist/tools/utils.cjs +3 -3
- package/dist/tracers/base.cjs +2 -2
- package/dist/tracers/base.d.ts +84 -84
- package/dist/tracers/initialize.cjs +2 -3
- package/dist/utils/async_caller.cjs +9 -9
- package/dist/utils/async_caller.js +9 -9
- package/dist/utils/env.cjs +4 -4
- package/dist/utils/event_source_parse.cjs +5 -5
- package/dist/utils/fast-json-patch/index.cjs +17 -7
- package/dist/utils/fast-json-patch/index.d.ts +4 -4
- package/dist/utils/fast-json-patch/src/core.cjs +8 -8
- package/dist/utils/fast-json-patch/src/duplex.cjs +4 -5
- package/dist/utils/fast-json-patch/src/helpers.cjs +10 -10
- package/dist/utils/fast-json-patch/src/helpers.d.ts +3 -3
- package/dist/utils/function_calling.cjs +3 -3
- package/dist/utils/hash.cjs +3 -1
- package/dist/utils/hash.d.ts +7 -0
- package/dist/utils/hash.js +1 -0
- package/dist/utils/js-sha1/hash.cjs +17 -0
- package/dist/utils/js-sha1/hash.d.ts +4 -0
- package/dist/utils/js-sha1/hash.js +17 -0
- package/dist/utils/js-sha256/hash.cjs +448 -0
- package/dist/utils/js-sha256/hash.d.ts +1 -0
- package/dist/utils/js-sha256/hash.js +445 -0
- package/dist/utils/json.cjs +2 -3
- package/dist/utils/json_schema.cjs +11 -4
- package/dist/utils/json_schema.js +9 -2
- package/dist/utils/math.cjs +6 -7
- package/dist/utils/ml-distance/distances.cjs +1 -2
- package/dist/utils/ml-distance/similarities.cjs +1 -2
- package/dist/utils/ml-distance-euclidean/euclidean.cjs +2 -3
- package/dist/utils/sax-js/sax.cjs +35 -35
- package/dist/utils/sax-js/sax.js +35 -35
- package/dist/utils/signal.cjs +1 -2
- package/dist/utils/stream.cjs +4 -4
- package/dist/utils/tiktoken.cjs +2 -3
- package/dist/utils/types/zod.cjs +251 -56
- package/dist/utils/types/zod.d.ts +40 -1
- package/dist/utils/types/zod.js +230 -39
- package/package.json +30 -4
- package/utils/hash/insecure.cjs +1 -0
- package/utils/hash/insecure.d.cts +1 -0
- package/utils/hash/insecure.d.ts +1 -0
- package/utils/hash/insecure.js +1 -0
- package/utils/hash/sha256.cjs +1 -0
- package/utils/hash/sha256.d.cts +1 -0
- package/utils/hash/sha256.d.ts +1 -0
- package/utils/hash/sha256.js +1 -0
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// Inlined to deal with portability issues with importing crypto module
|
|
3
|
+
/**
|
|
4
|
+
* [js-sha256]{@link https://github.com/emn178/js-sha256}
|
|
5
|
+
*
|
|
6
|
+
* @version 0.11.1
|
|
7
|
+
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
8
|
+
* @copyright Chen, Yi-Cyuan 2014-2025
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
/*jslint bitwise: true */
|
|
12
|
+
"use strict";
|
|
13
|
+
var HEX_CHARS = "0123456789abcdef".split("");
|
|
14
|
+
var EXTRA = [-2147483648, 8388608, 32768, 128];
|
|
15
|
+
var SHIFT = [24, 16, 8, 0];
|
|
16
|
+
var K = [
|
|
17
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
|
|
18
|
+
0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
|
19
|
+
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
|
|
20
|
+
0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
21
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
|
|
22
|
+
0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
|
23
|
+
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
|
|
24
|
+
0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
25
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
|
|
26
|
+
0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
|
27
|
+
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
28
|
+
];
|
|
29
|
+
var OUTPUT_TYPES = ["hex", "array", "digest", "arrayBuffer"];
|
|
30
|
+
var blocks = [];
|
|
31
|
+
function Sha256(is224, sharedMemory) {
|
|
32
|
+
if (sharedMemory) {
|
|
33
|
+
blocks[0] =
|
|
34
|
+
blocks[16] =
|
|
35
|
+
blocks[1] =
|
|
36
|
+
blocks[2] =
|
|
37
|
+
blocks[3] =
|
|
38
|
+
blocks[4] =
|
|
39
|
+
blocks[5] =
|
|
40
|
+
blocks[6] =
|
|
41
|
+
blocks[7] =
|
|
42
|
+
blocks[8] =
|
|
43
|
+
blocks[9] =
|
|
44
|
+
blocks[10] =
|
|
45
|
+
blocks[11] =
|
|
46
|
+
blocks[12] =
|
|
47
|
+
blocks[13] =
|
|
48
|
+
blocks[14] =
|
|
49
|
+
blocks[15] =
|
|
50
|
+
0;
|
|
51
|
+
this.blocks = blocks;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
55
|
+
}
|
|
56
|
+
if (is224) {
|
|
57
|
+
this.h0 = 0xc1059ed8;
|
|
58
|
+
this.h1 = 0x367cd507;
|
|
59
|
+
this.h2 = 0x3070dd17;
|
|
60
|
+
this.h3 = 0xf70e5939;
|
|
61
|
+
this.h4 = 0xffc00b31;
|
|
62
|
+
this.h5 = 0x68581511;
|
|
63
|
+
this.h6 = 0x64f98fa7;
|
|
64
|
+
this.h7 = 0xbefa4fa4;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// 256
|
|
68
|
+
this.h0 = 0x6a09e667;
|
|
69
|
+
this.h1 = 0xbb67ae85;
|
|
70
|
+
this.h2 = 0x3c6ef372;
|
|
71
|
+
this.h3 = 0xa54ff53a;
|
|
72
|
+
this.h4 = 0x510e527f;
|
|
73
|
+
this.h5 = 0x9b05688c;
|
|
74
|
+
this.h6 = 0x1f83d9ab;
|
|
75
|
+
this.h7 = 0x5be0cd19;
|
|
76
|
+
}
|
|
77
|
+
this.block = this.start = this.bytes = this.hBytes = 0;
|
|
78
|
+
this.finalized = this.hashed = false;
|
|
79
|
+
this.first = true;
|
|
80
|
+
this.is224 = is224;
|
|
81
|
+
}
|
|
82
|
+
Sha256.prototype.update = function (message) {
|
|
83
|
+
if (this.finalized) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
var notString, type = typeof message;
|
|
87
|
+
if (type !== "string") {
|
|
88
|
+
if (type === "object") {
|
|
89
|
+
if (message === null) {
|
|
90
|
+
throw new Error(ERROR);
|
|
91
|
+
}
|
|
92
|
+
else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
|
93
|
+
message = new Uint8Array(message);
|
|
94
|
+
}
|
|
95
|
+
else if (!Array.isArray(message)) {
|
|
96
|
+
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
|
|
97
|
+
throw new Error(ERROR);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
throw new Error(ERROR);
|
|
103
|
+
}
|
|
104
|
+
notString = true;
|
|
105
|
+
}
|
|
106
|
+
var code, index = 0, i, length = message.length, blocks = this.blocks;
|
|
107
|
+
while (index < length) {
|
|
108
|
+
if (this.hashed) {
|
|
109
|
+
this.hashed = false;
|
|
110
|
+
blocks[0] = this.block;
|
|
111
|
+
this.block =
|
|
112
|
+
blocks[16] =
|
|
113
|
+
blocks[1] =
|
|
114
|
+
blocks[2] =
|
|
115
|
+
blocks[3] =
|
|
116
|
+
blocks[4] =
|
|
117
|
+
blocks[5] =
|
|
118
|
+
blocks[6] =
|
|
119
|
+
blocks[7] =
|
|
120
|
+
blocks[8] =
|
|
121
|
+
blocks[9] =
|
|
122
|
+
blocks[10] =
|
|
123
|
+
blocks[11] =
|
|
124
|
+
blocks[12] =
|
|
125
|
+
blocks[13] =
|
|
126
|
+
blocks[14] =
|
|
127
|
+
blocks[15] =
|
|
128
|
+
0;
|
|
129
|
+
}
|
|
130
|
+
if (notString) {
|
|
131
|
+
for (i = this.start; index < length && i < 64; ++index) {
|
|
132
|
+
blocks[i >>> 2] |= message[index] << SHIFT[i++ & 3];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
for (i = this.start; index < length && i < 64; ++index) {
|
|
137
|
+
code = message.charCodeAt(index);
|
|
138
|
+
if (code < 0x80) {
|
|
139
|
+
blocks[i >>> 2] |= code << SHIFT[i++ & 3];
|
|
140
|
+
}
|
|
141
|
+
else if (code < 0x800) {
|
|
142
|
+
blocks[i >>> 2] |= (0xc0 | (code >>> 6)) << SHIFT[i++ & 3];
|
|
143
|
+
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
144
|
+
}
|
|
145
|
+
else if (code < 0xd800 || code >= 0xe000) {
|
|
146
|
+
blocks[i >>> 2] |= (0xe0 | (code >>> 12)) << SHIFT[i++ & 3];
|
|
147
|
+
blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
|
|
148
|
+
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
code =
|
|
152
|
+
0x10000 +
|
|
153
|
+
(((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
|
154
|
+
blocks[i >>> 2] |= (0xf0 | (code >>> 18)) << SHIFT[i++ & 3];
|
|
155
|
+
blocks[i >>> 2] |= (0x80 | ((code >>> 12) & 0x3f)) << SHIFT[i++ & 3];
|
|
156
|
+
blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
|
|
157
|
+
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
this.lastByteIndex = i;
|
|
162
|
+
this.bytes += i - this.start;
|
|
163
|
+
if (i >= 64) {
|
|
164
|
+
this.block = blocks[16];
|
|
165
|
+
this.start = i - 64;
|
|
166
|
+
this.hash();
|
|
167
|
+
this.hashed = true;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
this.start = i;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (this.bytes > 4294967295) {
|
|
174
|
+
this.hBytes += (this.bytes / 4294967296) << 0;
|
|
175
|
+
this.bytes = this.bytes % 4294967296;
|
|
176
|
+
}
|
|
177
|
+
return this;
|
|
178
|
+
};
|
|
179
|
+
Sha256.prototype.finalize = function () {
|
|
180
|
+
if (this.finalized) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
this.finalized = true;
|
|
184
|
+
var blocks = this.blocks, i = this.lastByteIndex;
|
|
185
|
+
blocks[16] = this.block;
|
|
186
|
+
blocks[i >>> 2] |= EXTRA[i & 3];
|
|
187
|
+
this.block = blocks[16];
|
|
188
|
+
if (i >= 56) {
|
|
189
|
+
if (!this.hashed) {
|
|
190
|
+
this.hash();
|
|
191
|
+
}
|
|
192
|
+
blocks[0] = this.block;
|
|
193
|
+
blocks[16] =
|
|
194
|
+
blocks[1] =
|
|
195
|
+
blocks[2] =
|
|
196
|
+
blocks[3] =
|
|
197
|
+
blocks[4] =
|
|
198
|
+
blocks[5] =
|
|
199
|
+
blocks[6] =
|
|
200
|
+
blocks[7] =
|
|
201
|
+
blocks[8] =
|
|
202
|
+
blocks[9] =
|
|
203
|
+
blocks[10] =
|
|
204
|
+
blocks[11] =
|
|
205
|
+
blocks[12] =
|
|
206
|
+
blocks[13] =
|
|
207
|
+
blocks[14] =
|
|
208
|
+
blocks[15] =
|
|
209
|
+
0;
|
|
210
|
+
}
|
|
211
|
+
blocks[14] = (this.hBytes << 3) | (this.bytes >>> 29);
|
|
212
|
+
blocks[15] = this.bytes << 3;
|
|
213
|
+
this.hash();
|
|
214
|
+
};
|
|
215
|
+
Sha256.prototype.hash = function () {
|
|
216
|
+
var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6, h = this.h7, blocks = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc;
|
|
217
|
+
for (j = 16; j < 64; ++j) {
|
|
218
|
+
// rightrotate
|
|
219
|
+
t1 = blocks[j - 15];
|
|
220
|
+
s0 = ((t1 >>> 7) | (t1 << 25)) ^ ((t1 >>> 18) | (t1 << 14)) ^ (t1 >>> 3);
|
|
221
|
+
t1 = blocks[j - 2];
|
|
222
|
+
s1 = ((t1 >>> 17) | (t1 << 15)) ^ ((t1 >>> 19) | (t1 << 13)) ^ (t1 >>> 10);
|
|
223
|
+
blocks[j] = (blocks[j - 16] + s0 + blocks[j - 7] + s1) << 0;
|
|
224
|
+
}
|
|
225
|
+
bc = b & c;
|
|
226
|
+
for (j = 0; j < 64; j += 4) {
|
|
227
|
+
if (this.first) {
|
|
228
|
+
if (this.is224) {
|
|
229
|
+
ab = 300032;
|
|
230
|
+
t1 = blocks[0] - 1413257819;
|
|
231
|
+
h = (t1 - 150054599) << 0;
|
|
232
|
+
d = (t1 + 24177077) << 0;
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
ab = 704751109;
|
|
236
|
+
t1 = blocks[0] - 210244248;
|
|
237
|
+
h = (t1 - 1521486534) << 0;
|
|
238
|
+
d = (t1 + 143694565) << 0;
|
|
239
|
+
}
|
|
240
|
+
this.first = false;
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
s0 =
|
|
244
|
+
((a >>> 2) | (a << 30)) ^
|
|
245
|
+
((a >>> 13) | (a << 19)) ^
|
|
246
|
+
((a >>> 22) | (a << 10));
|
|
247
|
+
s1 =
|
|
248
|
+
((e >>> 6) | (e << 26)) ^
|
|
249
|
+
((e >>> 11) | (e << 21)) ^
|
|
250
|
+
((e >>> 25) | (e << 7));
|
|
251
|
+
ab = a & b;
|
|
252
|
+
maj = ab ^ (a & c) ^ bc;
|
|
253
|
+
ch = (e & f) ^ (~e & g);
|
|
254
|
+
t1 = h + s1 + ch + K[j] + blocks[j];
|
|
255
|
+
t2 = s0 + maj;
|
|
256
|
+
h = (d + t1) << 0;
|
|
257
|
+
d = (t1 + t2) << 0;
|
|
258
|
+
}
|
|
259
|
+
s0 =
|
|
260
|
+
((d >>> 2) | (d << 30)) ^
|
|
261
|
+
((d >>> 13) | (d << 19)) ^
|
|
262
|
+
((d >>> 22) | (d << 10));
|
|
263
|
+
s1 =
|
|
264
|
+
((h >>> 6) | (h << 26)) ^
|
|
265
|
+
((h >>> 11) | (h << 21)) ^
|
|
266
|
+
((h >>> 25) | (h << 7));
|
|
267
|
+
da = d & a;
|
|
268
|
+
maj = da ^ (d & b) ^ ab;
|
|
269
|
+
ch = (g & h) ^ (~g & e);
|
|
270
|
+
t1 = f + s1 + ch + K[j + 1] + blocks[j + 1];
|
|
271
|
+
t2 = s0 + maj;
|
|
272
|
+
g = (c + t1) << 0;
|
|
273
|
+
c = (t1 + t2) << 0;
|
|
274
|
+
s0 =
|
|
275
|
+
((c >>> 2) | (c << 30)) ^
|
|
276
|
+
((c >>> 13) | (c << 19)) ^
|
|
277
|
+
((c >>> 22) | (c << 10));
|
|
278
|
+
s1 =
|
|
279
|
+
((g >>> 6) | (g << 26)) ^
|
|
280
|
+
((g >>> 11) | (g << 21)) ^
|
|
281
|
+
((g >>> 25) | (g << 7));
|
|
282
|
+
cd = c & d;
|
|
283
|
+
maj = cd ^ (c & a) ^ da;
|
|
284
|
+
ch = (f & g) ^ (~f & h);
|
|
285
|
+
t1 = e + s1 + ch + K[j + 2] + blocks[j + 2];
|
|
286
|
+
t2 = s0 + maj;
|
|
287
|
+
f = (b + t1) << 0;
|
|
288
|
+
b = (t1 + t2) << 0;
|
|
289
|
+
s0 =
|
|
290
|
+
((b >>> 2) | (b << 30)) ^
|
|
291
|
+
((b >>> 13) | (b << 19)) ^
|
|
292
|
+
((b >>> 22) | (b << 10));
|
|
293
|
+
s1 =
|
|
294
|
+
((f >>> 6) | (f << 26)) ^
|
|
295
|
+
((f >>> 11) | (f << 21)) ^
|
|
296
|
+
((f >>> 25) | (f << 7));
|
|
297
|
+
bc = b & c;
|
|
298
|
+
maj = bc ^ (b & d) ^ cd;
|
|
299
|
+
ch = (f & g) ^ (~f & h);
|
|
300
|
+
t1 = e + s1 + ch + K[j + 3] + blocks[j + 3];
|
|
301
|
+
t2 = s0 + maj;
|
|
302
|
+
e = (a + t1) << 0;
|
|
303
|
+
a = (t1 + t2) << 0;
|
|
304
|
+
this.chromeBugWorkAround = true;
|
|
305
|
+
}
|
|
306
|
+
this.h0 = (this.h0 + a) << 0;
|
|
307
|
+
this.h1 = (this.h1 + b) << 0;
|
|
308
|
+
this.h2 = (this.h2 + c) << 0;
|
|
309
|
+
this.h3 = (this.h3 + d) << 0;
|
|
310
|
+
this.h4 = (this.h4 + e) << 0;
|
|
311
|
+
this.h5 = (this.h5 + f) << 0;
|
|
312
|
+
this.h6 = (this.h6 + g) << 0;
|
|
313
|
+
this.h7 = (this.h7 + h) << 0;
|
|
314
|
+
};
|
|
315
|
+
Sha256.prototype.hex = function () {
|
|
316
|
+
this.finalize();
|
|
317
|
+
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7;
|
|
318
|
+
var hex = HEX_CHARS[(h0 >>> 28) & 0x0f] +
|
|
319
|
+
HEX_CHARS[(h0 >>> 24) & 0x0f] +
|
|
320
|
+
HEX_CHARS[(h0 >>> 20) & 0x0f] +
|
|
321
|
+
HEX_CHARS[(h0 >>> 16) & 0x0f] +
|
|
322
|
+
HEX_CHARS[(h0 >>> 12) & 0x0f] +
|
|
323
|
+
HEX_CHARS[(h0 >>> 8) & 0x0f] +
|
|
324
|
+
HEX_CHARS[(h0 >>> 4) & 0x0f] +
|
|
325
|
+
HEX_CHARS[h0 & 0x0f] +
|
|
326
|
+
HEX_CHARS[(h1 >>> 28) & 0x0f] +
|
|
327
|
+
HEX_CHARS[(h1 >>> 24) & 0x0f] +
|
|
328
|
+
HEX_CHARS[(h1 >>> 20) & 0x0f] +
|
|
329
|
+
HEX_CHARS[(h1 >>> 16) & 0x0f] +
|
|
330
|
+
HEX_CHARS[(h1 >>> 12) & 0x0f] +
|
|
331
|
+
HEX_CHARS[(h1 >>> 8) & 0x0f] +
|
|
332
|
+
HEX_CHARS[(h1 >>> 4) & 0x0f] +
|
|
333
|
+
HEX_CHARS[h1 & 0x0f] +
|
|
334
|
+
HEX_CHARS[(h2 >>> 28) & 0x0f] +
|
|
335
|
+
HEX_CHARS[(h2 >>> 24) & 0x0f] +
|
|
336
|
+
HEX_CHARS[(h2 >>> 20) & 0x0f] +
|
|
337
|
+
HEX_CHARS[(h2 >>> 16) & 0x0f] +
|
|
338
|
+
HEX_CHARS[(h2 >>> 12) & 0x0f] +
|
|
339
|
+
HEX_CHARS[(h2 >>> 8) & 0x0f] +
|
|
340
|
+
HEX_CHARS[(h2 >>> 4) & 0x0f] +
|
|
341
|
+
HEX_CHARS[h2 & 0x0f] +
|
|
342
|
+
HEX_CHARS[(h3 >>> 28) & 0x0f] +
|
|
343
|
+
HEX_CHARS[(h3 >>> 24) & 0x0f] +
|
|
344
|
+
HEX_CHARS[(h3 >>> 20) & 0x0f] +
|
|
345
|
+
HEX_CHARS[(h3 >>> 16) & 0x0f] +
|
|
346
|
+
HEX_CHARS[(h3 >>> 12) & 0x0f] +
|
|
347
|
+
HEX_CHARS[(h3 >>> 8) & 0x0f] +
|
|
348
|
+
HEX_CHARS[(h3 >>> 4) & 0x0f] +
|
|
349
|
+
HEX_CHARS[h3 & 0x0f] +
|
|
350
|
+
HEX_CHARS[(h4 >>> 28) & 0x0f] +
|
|
351
|
+
HEX_CHARS[(h4 >>> 24) & 0x0f] +
|
|
352
|
+
HEX_CHARS[(h4 >>> 20) & 0x0f] +
|
|
353
|
+
HEX_CHARS[(h4 >>> 16) & 0x0f] +
|
|
354
|
+
HEX_CHARS[(h4 >>> 12) & 0x0f] +
|
|
355
|
+
HEX_CHARS[(h4 >>> 8) & 0x0f] +
|
|
356
|
+
HEX_CHARS[(h4 >>> 4) & 0x0f] +
|
|
357
|
+
HEX_CHARS[h4 & 0x0f] +
|
|
358
|
+
HEX_CHARS[(h5 >>> 28) & 0x0f] +
|
|
359
|
+
HEX_CHARS[(h5 >>> 24) & 0x0f] +
|
|
360
|
+
HEX_CHARS[(h5 >>> 20) & 0x0f] +
|
|
361
|
+
HEX_CHARS[(h5 >>> 16) & 0x0f] +
|
|
362
|
+
HEX_CHARS[(h5 >>> 12) & 0x0f] +
|
|
363
|
+
HEX_CHARS[(h5 >>> 8) & 0x0f] +
|
|
364
|
+
HEX_CHARS[(h5 >>> 4) & 0x0f] +
|
|
365
|
+
HEX_CHARS[h5 & 0x0f] +
|
|
366
|
+
HEX_CHARS[(h6 >>> 28) & 0x0f] +
|
|
367
|
+
HEX_CHARS[(h6 >>> 24) & 0x0f] +
|
|
368
|
+
HEX_CHARS[(h6 >>> 20) & 0x0f] +
|
|
369
|
+
HEX_CHARS[(h6 >>> 16) & 0x0f] +
|
|
370
|
+
HEX_CHARS[(h6 >>> 12) & 0x0f] +
|
|
371
|
+
HEX_CHARS[(h6 >>> 8) & 0x0f] +
|
|
372
|
+
HEX_CHARS[(h6 >>> 4) & 0x0f] +
|
|
373
|
+
HEX_CHARS[h6 & 0x0f];
|
|
374
|
+
if (!this.is224) {
|
|
375
|
+
hex +=
|
|
376
|
+
HEX_CHARS[(h7 >>> 28) & 0x0f] +
|
|
377
|
+
HEX_CHARS[(h7 >>> 24) & 0x0f] +
|
|
378
|
+
HEX_CHARS[(h7 >>> 20) & 0x0f] +
|
|
379
|
+
HEX_CHARS[(h7 >>> 16) & 0x0f] +
|
|
380
|
+
HEX_CHARS[(h7 >>> 12) & 0x0f] +
|
|
381
|
+
HEX_CHARS[(h7 >>> 8) & 0x0f] +
|
|
382
|
+
HEX_CHARS[(h7 >>> 4) & 0x0f] +
|
|
383
|
+
HEX_CHARS[h7 & 0x0f];
|
|
384
|
+
}
|
|
385
|
+
return hex;
|
|
386
|
+
};
|
|
387
|
+
Sha256.prototype.toString = Sha256.prototype.hex;
|
|
388
|
+
Sha256.prototype.digest = function () {
|
|
389
|
+
this.finalize();
|
|
390
|
+
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7;
|
|
391
|
+
var arr = [
|
|
392
|
+
(h0 >>> 24) & 0xff,
|
|
393
|
+
(h0 >>> 16) & 0xff,
|
|
394
|
+
(h0 >>> 8) & 0xff,
|
|
395
|
+
h0 & 0xff,
|
|
396
|
+
(h1 >>> 24) & 0xff,
|
|
397
|
+
(h1 >>> 16) & 0xff,
|
|
398
|
+
(h1 >>> 8) & 0xff,
|
|
399
|
+
h1 & 0xff,
|
|
400
|
+
(h2 >>> 24) & 0xff,
|
|
401
|
+
(h2 >>> 16) & 0xff,
|
|
402
|
+
(h2 >>> 8) & 0xff,
|
|
403
|
+
h2 & 0xff,
|
|
404
|
+
(h3 >>> 24) & 0xff,
|
|
405
|
+
(h3 >>> 16) & 0xff,
|
|
406
|
+
(h3 >>> 8) & 0xff,
|
|
407
|
+
h3 & 0xff,
|
|
408
|
+
(h4 >>> 24) & 0xff,
|
|
409
|
+
(h4 >>> 16) & 0xff,
|
|
410
|
+
(h4 >>> 8) & 0xff,
|
|
411
|
+
h4 & 0xff,
|
|
412
|
+
(h5 >>> 24) & 0xff,
|
|
413
|
+
(h5 >>> 16) & 0xff,
|
|
414
|
+
(h5 >>> 8) & 0xff,
|
|
415
|
+
h5 & 0xff,
|
|
416
|
+
(h6 >>> 24) & 0xff,
|
|
417
|
+
(h6 >>> 16) & 0xff,
|
|
418
|
+
(h6 >>> 8) & 0xff,
|
|
419
|
+
h6 & 0xff,
|
|
420
|
+
];
|
|
421
|
+
if (!this.is224) {
|
|
422
|
+
arr.push((h7 >>> 24) & 0xff, (h7 >>> 16) & 0xff, (h7 >>> 8) & 0xff, h7 & 0xff);
|
|
423
|
+
}
|
|
424
|
+
return arr;
|
|
425
|
+
};
|
|
426
|
+
Sha256.prototype.array = Sha256.prototype.digest;
|
|
427
|
+
Sha256.prototype.arrayBuffer = function () {
|
|
428
|
+
this.finalize();
|
|
429
|
+
var buffer = new ArrayBuffer(this.is224 ? 28 : 32);
|
|
430
|
+
var dataView = new DataView(buffer);
|
|
431
|
+
dataView.setUint32(0, this.h0);
|
|
432
|
+
dataView.setUint32(4, this.h1);
|
|
433
|
+
dataView.setUint32(8, this.h2);
|
|
434
|
+
dataView.setUint32(12, this.h3);
|
|
435
|
+
dataView.setUint32(16, this.h4);
|
|
436
|
+
dataView.setUint32(20, this.h5);
|
|
437
|
+
dataView.setUint32(24, this.h6);
|
|
438
|
+
if (!this.is224) {
|
|
439
|
+
dataView.setUint32(28, this.h7);
|
|
440
|
+
}
|
|
441
|
+
return buffer;
|
|
442
|
+
};
|
|
443
|
+
export const sha256 = (...strings) => {
|
|
444
|
+
return new Sha256(false, true).update(strings.join("")).hex();
|
|
445
|
+
};
|
package/dist/utils/json.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.parseJsonMarkdown = parseJsonMarkdown;
|
|
4
|
+
exports.parsePartialJson = parsePartialJson;
|
|
4
5
|
function parseJsonMarkdown(s, parser = parsePartialJson) {
|
|
5
6
|
// eslint-disable-next-line no-param-reassign
|
|
6
7
|
s = s.trim();
|
|
@@ -25,7 +26,6 @@ function parseJsonMarkdown(s, parser = parsePartialJson) {
|
|
|
25
26
|
}
|
|
26
27
|
return parser(finalContent.trim());
|
|
27
28
|
}
|
|
28
|
-
exports.parseJsonMarkdown = parseJsonMarkdown;
|
|
29
29
|
// Adapted from https://github.com/KillianLucas/open-interpreter/blob/main/interpreter/core/llm/utils/parse_partial_json.py
|
|
30
30
|
// MIT License
|
|
31
31
|
function parsePartialJson(s) {
|
|
@@ -103,4 +103,3 @@ function parsePartialJson(s) {
|
|
|
103
103
|
return null;
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
exports.parsePartialJson = parsePartialJson;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Validator = exports.deepCompareStrict = void 0;
|
|
4
|
+
exports.toJsonSchema = toJsonSchema;
|
|
5
|
+
exports.validatesOnlyStrings = validatesOnlyStrings;
|
|
4
6
|
const core_1 = require("zod/v4/core");
|
|
5
7
|
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
6
8
|
const json_schema_1 = require("@cfworker/json-schema");
|
|
@@ -15,14 +17,20 @@ Object.defineProperty(exports, "Validator", { enumerable: true, get: function ()
|
|
|
15
17
|
*/
|
|
16
18
|
function toJsonSchema(schema) {
|
|
17
19
|
if ((0, zod_js_1.isZodSchemaV4)(schema)) {
|
|
18
|
-
|
|
20
|
+
const inputSchema = (0, zod_js_1.interopZodTransformInputSchema)(schema, true);
|
|
21
|
+
if ((0, zod_js_1.isZodObjectV4)(inputSchema)) {
|
|
22
|
+
const strictSchema = (0, zod_js_1.interopZodObjectStrict)(inputSchema, true);
|
|
23
|
+
return (0, core_1.toJSONSchema)(strictSchema);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return (0, core_1.toJSONSchema)(schema);
|
|
27
|
+
}
|
|
19
28
|
}
|
|
20
29
|
if ((0, zod_js_1.isZodSchemaV3)(schema)) {
|
|
21
30
|
return (0, zod_to_json_schema_1.zodToJsonSchema)(schema);
|
|
22
31
|
}
|
|
23
32
|
return schema;
|
|
24
33
|
}
|
|
25
|
-
exports.toJsonSchema = toJsonSchema;
|
|
26
34
|
/**
|
|
27
35
|
* Validates if a JSON schema validates only strings. May return false negatives in some edge cases
|
|
28
36
|
* (like recursive or unresolvable refs).
|
|
@@ -88,4 +96,3 @@ function validatesOnlyStrings(schema) {
|
|
|
88
96
|
// ignore other cases for now where type is omitted
|
|
89
97
|
return false;
|
|
90
98
|
}
|
|
91
|
-
exports.validatesOnlyStrings = validatesOnlyStrings;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { toJSONSchema } from "zod/v4/core";
|
|
2
2
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
3
3
|
import { dereference } from "@cfworker/json-schema";
|
|
4
|
-
import { isZodSchemaV3, isZodSchemaV4 } from "./types/zod.js";
|
|
4
|
+
import { isZodSchemaV3, isZodSchemaV4, interopZodObjectStrict, isZodObjectV4, interopZodTransformInputSchema, } from "./types/zod.js";
|
|
5
5
|
export { deepCompareStrict, Validator } from "@cfworker/json-schema";
|
|
6
6
|
/**
|
|
7
7
|
* Converts a Zod schema or JSON schema to a JSON schema.
|
|
@@ -10,7 +10,14 @@ export { deepCompareStrict, Validator } from "@cfworker/json-schema";
|
|
|
10
10
|
*/
|
|
11
11
|
export function toJsonSchema(schema) {
|
|
12
12
|
if (isZodSchemaV4(schema)) {
|
|
13
|
-
|
|
13
|
+
const inputSchema = interopZodTransformInputSchema(schema, true);
|
|
14
|
+
if (isZodObjectV4(inputSchema)) {
|
|
15
|
+
const strictSchema = interopZodObjectStrict(inputSchema, true);
|
|
16
|
+
return toJSONSchema(strictSchema);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return toJSONSchema(schema);
|
|
20
|
+
}
|
|
14
21
|
}
|
|
15
22
|
if (isZodSchemaV3(schema)) {
|
|
16
23
|
return zodToJsonSchema(schema);
|
package/dist/utils/math.cjs
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.matrixFunc = matrixFunc;
|
|
4
|
+
exports.normalize = normalize;
|
|
5
|
+
exports.cosineSimilarity = cosineSimilarity;
|
|
6
|
+
exports.innerProduct = innerProduct;
|
|
7
|
+
exports.euclideanDistance = euclideanDistance;
|
|
8
|
+
exports.maximalMarginalRelevance = maximalMarginalRelevance;
|
|
4
9
|
const similarities_js_1 = require("./ml-distance/similarities.cjs");
|
|
5
10
|
const distances_js_1 = require("./ml-distance/distances.cjs");
|
|
6
11
|
const euclidean_js_1 = require("./ml-distance-euclidean/euclidean.cjs");
|
|
@@ -30,12 +35,10 @@ function matrixFunc(X, Y, func) {
|
|
|
30
35
|
}
|
|
31
36
|
return X.map((xVector) => Y.map((yVector) => func(xVector, yVector)).map((similarity) => Number.isNaN(similarity) ? 0 : similarity));
|
|
32
37
|
}
|
|
33
|
-
exports.matrixFunc = matrixFunc;
|
|
34
38
|
function normalize(M, similarity = false) {
|
|
35
39
|
const max = matrixMaxVal(M);
|
|
36
40
|
return M.map((row) => row.map((val) => (similarity ? 1 - val / max : val / max)));
|
|
37
41
|
}
|
|
38
|
-
exports.normalize = normalize;
|
|
39
42
|
/**
|
|
40
43
|
* This function calculates the row-wise cosine similarity between two matrices with the same number of columns.
|
|
41
44
|
*
|
|
@@ -49,15 +52,12 @@ exports.normalize = normalize;
|
|
|
49
52
|
function cosineSimilarity(X, Y) {
|
|
50
53
|
return matrixFunc(X, Y, similarities_js_1.cosine);
|
|
51
54
|
}
|
|
52
|
-
exports.cosineSimilarity = cosineSimilarity;
|
|
53
55
|
function innerProduct(X, Y) {
|
|
54
56
|
return matrixFunc(X, Y, distances_js_1.innerProduct);
|
|
55
57
|
}
|
|
56
|
-
exports.innerProduct = innerProduct;
|
|
57
58
|
function euclideanDistance(X, Y) {
|
|
58
59
|
return matrixFunc(X, Y, euclidean_js_1.euclidean);
|
|
59
60
|
}
|
|
60
|
-
exports.euclideanDistance = euclideanDistance;
|
|
61
61
|
/**
|
|
62
62
|
* This function implements the Maximal Marginal Relevance algorithm
|
|
63
63
|
* to select a set of embeddings that maximizes the diversity and relevance to a query embedding.
|
|
@@ -98,7 +98,6 @@ function maximalMarginalRelevance(queryEmbedding, embeddingList, lambda = 0.5, k
|
|
|
98
98
|
}
|
|
99
99
|
return selectedEmbeddingsIndexes;
|
|
100
100
|
}
|
|
101
|
-
exports.maximalMarginalRelevance = maximalMarginalRelevance;
|
|
102
101
|
/**
|
|
103
102
|
* Finds the index of the maximum value in the given array.
|
|
104
103
|
* @param {number[]} array - The input array.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.innerProduct =
|
|
3
|
+
exports.innerProduct = innerProduct;
|
|
4
4
|
/**
|
|
5
5
|
*Returns the Inner Product similarity between vectors a and b
|
|
6
6
|
* @link [Inner Product Similarity algorithm](https://www.naun.org/main/NAUN/ijmmas/mmmas-49.pdf)
|
|
@@ -15,4 +15,3 @@ function innerProduct(a, b) {
|
|
|
15
15
|
}
|
|
16
16
|
return ans;
|
|
17
17
|
}
|
|
18
|
-
exports.innerProduct = innerProduct;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cosine =
|
|
3
|
+
exports.cosine = cosine;
|
|
4
4
|
/**
|
|
5
5
|
* Returns the average of cosine distances between vectors a and b
|
|
6
6
|
* @param a - first vector
|
|
@@ -18,4 +18,3 @@ function cosine(a, b) {
|
|
|
18
18
|
}
|
|
19
19
|
return p / (Math.sqrt(p2) * Math.sqrt(q2));
|
|
20
20
|
}
|
|
21
|
-
exports.cosine = cosine;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.squaredEuclidean = squaredEuclidean;
|
|
4
|
+
exports.euclidean = euclidean;
|
|
4
5
|
function squaredEuclidean(p, q) {
|
|
5
6
|
let d = 0;
|
|
6
7
|
for (let i = 0; i < p.length; i++) {
|
|
@@ -8,8 +9,6 @@ function squaredEuclidean(p, q) {
|
|
|
8
9
|
}
|
|
9
10
|
return d;
|
|
10
11
|
}
|
|
11
|
-
exports.squaredEuclidean = squaredEuclidean;
|
|
12
12
|
function euclidean(p, q) {
|
|
13
13
|
return Math.sqrt(squaredEuclidean(p, q));
|
|
14
14
|
}
|
|
15
|
-
exports.euclidean = euclidean;
|