@workglow/util 0.0.85 → 0.0.87
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/README.md +32 -0
- package/dist/browser.js +232 -2
- package/dist/browser.js.map +10 -5
- package/dist/bun.js +232 -2
- package/dist/bun.js.map +10 -5
- package/dist/common.d.ts +4 -0
- package/dist/common.d.ts.map +1 -1
- package/dist/di/InputResolverRegistry.d.ts +58 -0
- package/dist/di/InputResolverRegistry.d.ts.map +1 -0
- package/dist/di/ServiceRegistry.d.ts +1 -1
- package/dist/di/ServiceRegistry.d.ts.map +1 -1
- package/dist/di/index.d.ts +1 -0
- package/dist/di/index.d.ts.map +1 -1
- package/dist/json-schema/JsonSchema.d.ts +1 -0
- package/dist/json-schema/JsonSchema.d.ts.map +1 -1
- package/dist/json-schema/SchemaValidation.d.ts +2 -2
- package/dist/json-schema/SchemaValidation.d.ts.map +1 -1
- package/dist/node.js +232 -2
- package/dist/node.js.map +10 -5
- package/dist/vector/Tensor.d.ts +59 -0
- package/dist/vector/Tensor.d.ts.map +1 -0
- package/dist/vector/TypedArray.d.ts +85 -0
- package/dist/vector/TypedArray.d.ts.map +1 -0
- package/dist/vector/VectorSimilarityUtils.d.ts +30 -0
- package/dist/vector/VectorSimilarityUtils.d.ts.map +1 -0
- package/dist/vector/VectorUtils.d.ts +31 -0
- package/dist/vector/VectorUtils.d.ts.map +1 -0
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonSchema.d.ts","sourceRoot":"","sources":["../../src/json-schema/JsonSchema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAE3F,MAAM,MAAM,qBAAqB,GAAG;IAClC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,eAAe,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACnC,aAAa,CAAC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 Steven Roussey <sroussey@gmail.com>
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
export { compileSchema } from "json-schema-library";
|
|
7
|
-
export type { SchemaNode } from "json-schema-library";
|
|
6
|
+
export { compileSchema } from "@sroussey/json-schema-library";
|
|
7
|
+
export type { SchemaNode } from "@sroussey/json-schema-library";
|
|
8
8
|
//# sourceMappingURL=SchemaValidation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaValidation.d.ts","sourceRoot":"","sources":["../../src/json-schema/SchemaValidation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"SchemaValidation.d.ts","sourceRoot":"","sources":["../../src/json-schema/SchemaValidation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,YAAY,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC"}
|
package/dist/node.js
CHANGED
|
@@ -77,6 +77,19 @@ class ServiceRegistry {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
var globalServiceRegistry = new ServiceRegistry(globalContainer);
|
|
80
|
+
|
|
81
|
+
// src/di/InputResolverRegistry.ts
|
|
82
|
+
var INPUT_RESOLVERS = createServiceToken("task.input.resolvers");
|
|
83
|
+
if (!globalServiceRegistry.has(INPUT_RESOLVERS)) {
|
|
84
|
+
globalServiceRegistry.register(INPUT_RESOLVERS, () => new Map, true);
|
|
85
|
+
}
|
|
86
|
+
function getInputResolvers() {
|
|
87
|
+
return globalServiceRegistry.get(INPUT_RESOLVERS);
|
|
88
|
+
}
|
|
89
|
+
function registerInputResolver(formatPrefix, resolver) {
|
|
90
|
+
const resolvers = getInputResolvers();
|
|
91
|
+
resolvers.set(formatPrefix, resolver);
|
|
92
|
+
}
|
|
80
93
|
// src/events/EventEmitter.ts
|
|
81
94
|
class EventEmitter {
|
|
82
95
|
listeners = {};
|
|
@@ -963,7 +976,7 @@ function areObjectSchemasSemanticallyCompatible(sourceSchema, targetSchema) {
|
|
|
963
976
|
return areSemanticallyCompatible(sourceSchema, targetSchema);
|
|
964
977
|
}
|
|
965
978
|
// src/json-schema/SchemaValidation.ts
|
|
966
|
-
import { compileSchema } from "json-schema-library";
|
|
979
|
+
import { compileSchema } from "@sroussey/json-schema-library";
|
|
967
980
|
// src/utilities/Misc.ts
|
|
968
981
|
function forceArray(input) {
|
|
969
982
|
if (Array.isArray(input))
|
|
@@ -1337,6 +1350,208 @@ function objectOfArraysAsArrayOfObjects(data) {
|
|
|
1337
1350
|
}
|
|
1338
1351
|
});
|
|
1339
1352
|
}
|
|
1353
|
+
// src/vector/TypedArray.ts
|
|
1354
|
+
function isTypedArray(value) {
|
|
1355
|
+
return ArrayBuffer.isView(value) && !(value instanceof DataView);
|
|
1356
|
+
}
|
|
1357
|
+
var TypedArrayType = null;
|
|
1358
|
+
var TypedArraySchemaOptions = {
|
|
1359
|
+
...FromSchemaDefaultOptions,
|
|
1360
|
+
deserialize: [
|
|
1361
|
+
{
|
|
1362
|
+
pattern: { type: "array", format: "TypedArray:Float64Array" },
|
|
1363
|
+
output: Float64Array
|
|
1364
|
+
},
|
|
1365
|
+
{
|
|
1366
|
+
pattern: { type: "array", format: "TypedArray:Float32Array" },
|
|
1367
|
+
output: Float32Array
|
|
1368
|
+
},
|
|
1369
|
+
{
|
|
1370
|
+
pattern: { type: "array", format: "TypedArray:Float16Array" },
|
|
1371
|
+
output: Float16Array
|
|
1372
|
+
},
|
|
1373
|
+
{
|
|
1374
|
+
pattern: { type: "array", format: "TypedArray:Int16Array" },
|
|
1375
|
+
output: Int16Array
|
|
1376
|
+
},
|
|
1377
|
+
{
|
|
1378
|
+
pattern: { type: "array", format: "TypedArray:Int8Array" },
|
|
1379
|
+
output: Int8Array
|
|
1380
|
+
},
|
|
1381
|
+
{
|
|
1382
|
+
pattern: { type: "array", format: "TypedArray:Uint8Array" },
|
|
1383
|
+
output: Uint8Array
|
|
1384
|
+
},
|
|
1385
|
+
{
|
|
1386
|
+
pattern: { type: "array", format: "TypedArray:Uint16Array" },
|
|
1387
|
+
output: Uint16Array
|
|
1388
|
+
},
|
|
1389
|
+
{
|
|
1390
|
+
pattern: { type: "array", format: "TypedArray" },
|
|
1391
|
+
output: TypedArrayType
|
|
1392
|
+
}
|
|
1393
|
+
]
|
|
1394
|
+
};
|
|
1395
|
+
var TypedArraySchema = (annotations = {}) => {
|
|
1396
|
+
return {
|
|
1397
|
+
type: "array",
|
|
1398
|
+
format: "TypedArray",
|
|
1399
|
+
title: "Typed Array",
|
|
1400
|
+
description: "A typed array (Float32Array, Int8Array, etc.)",
|
|
1401
|
+
...annotations
|
|
1402
|
+
};
|
|
1403
|
+
};
|
|
1404
|
+
|
|
1405
|
+
// src/vector/Tensor.ts
|
|
1406
|
+
var TensorType = {
|
|
1407
|
+
FLOAT16: "float16",
|
|
1408
|
+
FLOAT32: "float32",
|
|
1409
|
+
FLOAT64: "float64",
|
|
1410
|
+
INT8: "int8",
|
|
1411
|
+
UINT8: "uint8",
|
|
1412
|
+
INT16: "int16",
|
|
1413
|
+
UINT16: "uint16"
|
|
1414
|
+
};
|
|
1415
|
+
var TensorSchema = (annotations = {}) => ({
|
|
1416
|
+
type: "object",
|
|
1417
|
+
properties: {
|
|
1418
|
+
type: {
|
|
1419
|
+
type: "string",
|
|
1420
|
+
enum: Object.values(TensorType),
|
|
1421
|
+
title: "Type",
|
|
1422
|
+
description: "The type of the tensor"
|
|
1423
|
+
},
|
|
1424
|
+
data: TypedArraySchema({
|
|
1425
|
+
title: "Data",
|
|
1426
|
+
description: "The data of the tensor"
|
|
1427
|
+
}),
|
|
1428
|
+
shape: {
|
|
1429
|
+
type: "array",
|
|
1430
|
+
items: { type: "number" },
|
|
1431
|
+
title: "Shape",
|
|
1432
|
+
description: "The shape of the tensor (dimensions)",
|
|
1433
|
+
minItems: 1,
|
|
1434
|
+
default: [1]
|
|
1435
|
+
},
|
|
1436
|
+
normalized: {
|
|
1437
|
+
type: "boolean",
|
|
1438
|
+
title: "Normalized",
|
|
1439
|
+
description: "Whether the tensor data is normalized",
|
|
1440
|
+
default: false
|
|
1441
|
+
}
|
|
1442
|
+
},
|
|
1443
|
+
required: ["data"],
|
|
1444
|
+
additionalProperties: false,
|
|
1445
|
+
...annotations
|
|
1446
|
+
});
|
|
1447
|
+
// src/vector/VectorSimilarityUtils.ts
|
|
1448
|
+
function cosineSimilarity(a, b) {
|
|
1449
|
+
if (a.length !== b.length) {
|
|
1450
|
+
throw new Error("Vectors must have the same length");
|
|
1451
|
+
}
|
|
1452
|
+
let dotProduct = 0;
|
|
1453
|
+
let normA = 0;
|
|
1454
|
+
let normB = 0;
|
|
1455
|
+
for (let i = 0;i < a.length; i++) {
|
|
1456
|
+
dotProduct += a[i] * b[i];
|
|
1457
|
+
normA += a[i] * a[i];
|
|
1458
|
+
normB += b[i] * b[i];
|
|
1459
|
+
}
|
|
1460
|
+
const denominator = Math.sqrt(normA) * Math.sqrt(normB);
|
|
1461
|
+
if (denominator === 0) {
|
|
1462
|
+
return 0;
|
|
1463
|
+
}
|
|
1464
|
+
return dotProduct / denominator;
|
|
1465
|
+
}
|
|
1466
|
+
function jaccardSimilarity(a, b) {
|
|
1467
|
+
if (a.length !== b.length) {
|
|
1468
|
+
throw new Error("Vectors must have the same length");
|
|
1469
|
+
}
|
|
1470
|
+
let globalMin = a[0];
|
|
1471
|
+
for (let i = 0;i < a.length; i++) {
|
|
1472
|
+
globalMin = Math.min(globalMin, a[i], b[i]);
|
|
1473
|
+
}
|
|
1474
|
+
const shift = globalMin < 0 ? -globalMin : 0;
|
|
1475
|
+
let minSum = 0;
|
|
1476
|
+
let maxSum = 0;
|
|
1477
|
+
for (let i = 0;i < a.length; i++) {
|
|
1478
|
+
const shiftedA = a[i] + shift;
|
|
1479
|
+
const shiftedB = b[i] + shift;
|
|
1480
|
+
minSum += Math.min(shiftedA, shiftedB);
|
|
1481
|
+
maxSum += Math.max(shiftedA, shiftedB);
|
|
1482
|
+
}
|
|
1483
|
+
return maxSum === 0 ? 0 : minSum / maxSum;
|
|
1484
|
+
}
|
|
1485
|
+
function hammingDistance(a, b) {
|
|
1486
|
+
if (a.length !== b.length) {
|
|
1487
|
+
throw new Error("Vectors must have the same length");
|
|
1488
|
+
}
|
|
1489
|
+
let differences = 0;
|
|
1490
|
+
for (let i = 0;i < a.length; i++) {
|
|
1491
|
+
if (a[i] !== b[i]) {
|
|
1492
|
+
differences++;
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
return differences / a.length;
|
|
1496
|
+
}
|
|
1497
|
+
function hammingSimilarity(a, b) {
|
|
1498
|
+
return 1 - hammingDistance(a, b);
|
|
1499
|
+
}
|
|
1500
|
+
// src/vector/VectorUtils.ts
|
|
1501
|
+
function magnitude(arr) {
|
|
1502
|
+
return Math.sqrt(arr.reduce((acc, val) => acc + val * val, 0));
|
|
1503
|
+
}
|
|
1504
|
+
function inner(arr1, arr2) {
|
|
1505
|
+
if (arr1.length !== arr2.length) {
|
|
1506
|
+
throw new Error("Vectors must have the same length to compute inner product.");
|
|
1507
|
+
}
|
|
1508
|
+
return arr1.reduce((acc, val, i) => acc + val * arr2[i], 0);
|
|
1509
|
+
}
|
|
1510
|
+
function normalize(vector, throwOnZero = true, float32 = false) {
|
|
1511
|
+
const mag = magnitude(vector);
|
|
1512
|
+
if (mag === 0) {
|
|
1513
|
+
if (throwOnZero) {
|
|
1514
|
+
throw new Error("Cannot normalize a zero vector.");
|
|
1515
|
+
}
|
|
1516
|
+
return vector;
|
|
1517
|
+
}
|
|
1518
|
+
const normalized = Array.from(vector).map((val) => Number(val) / mag);
|
|
1519
|
+
if (float32) {
|
|
1520
|
+
return new Float32Array(normalized);
|
|
1521
|
+
}
|
|
1522
|
+
if (vector instanceof Float64Array) {
|
|
1523
|
+
return new Float64Array(normalized);
|
|
1524
|
+
}
|
|
1525
|
+
if (vector instanceof Float16Array) {
|
|
1526
|
+
return new Float16Array(normalized);
|
|
1527
|
+
}
|
|
1528
|
+
if (vector instanceof Float32Array) {
|
|
1529
|
+
return new Float32Array(normalized);
|
|
1530
|
+
}
|
|
1531
|
+
if (vector instanceof Int8Array) {
|
|
1532
|
+
return new Int8Array(normalized);
|
|
1533
|
+
}
|
|
1534
|
+
if (vector instanceof Uint8Array) {
|
|
1535
|
+
return new Uint8Array(normalized);
|
|
1536
|
+
}
|
|
1537
|
+
if (vector instanceof Int16Array) {
|
|
1538
|
+
return new Int16Array(normalized);
|
|
1539
|
+
}
|
|
1540
|
+
if (vector instanceof Uint16Array) {
|
|
1541
|
+
return new Uint16Array(normalized);
|
|
1542
|
+
}
|
|
1543
|
+
return new Float32Array(normalized);
|
|
1544
|
+
}
|
|
1545
|
+
function normalizeNumberArray(values, throwOnZero = false) {
|
|
1546
|
+
const norm = magnitude(values);
|
|
1547
|
+
if (norm === 0) {
|
|
1548
|
+
if (throwOnZero) {
|
|
1549
|
+
throw new Error("Cannot normalize a zero vector.");
|
|
1550
|
+
}
|
|
1551
|
+
return values;
|
|
1552
|
+
}
|
|
1553
|
+
return values.map((v) => v / norm);
|
|
1554
|
+
}
|
|
1340
1555
|
// src/worker/WorkerManager.ts
|
|
1341
1556
|
function extractTransferables(obj) {
|
|
1342
1557
|
const transferables = [];
|
|
@@ -1663,16 +1878,27 @@ export {
|
|
|
1663
1878
|
sleep,
|
|
1664
1879
|
sha256,
|
|
1665
1880
|
serialize,
|
|
1881
|
+
registerInputResolver,
|
|
1666
1882
|
parseDataUri,
|
|
1667
1883
|
parentPort2 as parentPort,
|
|
1668
1884
|
objectOfArraysAsArrayOfObjects,
|
|
1885
|
+
normalizeNumberArray,
|
|
1886
|
+
normalize,
|
|
1669
1887
|
makeFingerprint,
|
|
1888
|
+
magnitude,
|
|
1889
|
+
jaccardSimilarity,
|
|
1890
|
+
isTypedArray,
|
|
1891
|
+
inner,
|
|
1892
|
+
hammingSimilarity,
|
|
1893
|
+
hammingDistance,
|
|
1670
1894
|
globalServiceRegistry,
|
|
1671
1895
|
globalContainer,
|
|
1896
|
+
getInputResolvers,
|
|
1672
1897
|
forceArray,
|
|
1673
1898
|
deepEqual,
|
|
1674
1899
|
decompress,
|
|
1675
1900
|
createServiceToken,
|
|
1901
|
+
cosineSimilarity,
|
|
1676
1902
|
convertImageDataToUseableForm,
|
|
1677
1903
|
compress,
|
|
1678
1904
|
compileSchema,
|
|
@@ -1684,9 +1910,13 @@ export {
|
|
|
1684
1910
|
Worker,
|
|
1685
1911
|
WORKER_SERVER,
|
|
1686
1912
|
WORKER_MANAGER,
|
|
1913
|
+
TypedArraySchema,
|
|
1914
|
+
TensorType,
|
|
1915
|
+
TensorSchema,
|
|
1687
1916
|
ServiceRegistry,
|
|
1688
1917
|
NodeDoesntExistError,
|
|
1689
1918
|
NodeAlreadyExistsError,
|
|
1919
|
+
INPUT_RESOLVERS,
|
|
1690
1920
|
Graph,
|
|
1691
1921
|
FromSchemaDefaultOptions,
|
|
1692
1922
|
EventEmitter,
|
|
@@ -1697,4 +1927,4 @@ export {
|
|
|
1697
1927
|
BaseError
|
|
1698
1928
|
};
|
|
1699
1929
|
|
|
1700
|
-
//# debugId=
|
|
1930
|
+
//# debugId=7EBB738750BDF34E64756E2164756E21
|