@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.
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { FromSchema } from "../json-schema/FromSchema";
7
+ import { JsonSchema } from "../json-schema/JsonSchema";
8
+ /**
9
+ * Supported typed array types
10
+ * - Float16Array: 16-bit floating point (medium precision)
11
+ * - Float32Array: Standard 32-bit floating point (most common)
12
+ * - Float64Array: 64-bit floating point (high precision)
13
+ * - Int8Array: 8-bit signed integer (binary quantization)
14
+ * - Uint8Array: 8-bit unsigned integer (quantization)
15
+ * - Int16Array: 16-bit signed integer (quantization)
16
+ * - Uint16Array: 16-bit unsigned integer (quantization)
17
+ */
18
+ export type TypedArray = Float32Array | Float16Array | Float64Array | Int8Array | Uint8Array | Int16Array | Uint16Array;
19
+ export type TypedArrayString = "TypedArray" | "TypedArray:Float16Array" | "TypedArray:Float32Array" | "TypedArray:Float64Array" | "TypedArray:Int8Array" | "TypedArray:Uint8Array" | "TypedArray:Int16Array" | "TypedArray:Uint16Array";
20
+ export declare function isTypedArray(value: unknown): value is TypedArray;
21
+ declare const TypedArraySchemaOptions: {
22
+ readonly deserialize: [{
23
+ readonly pattern: {
24
+ readonly type: "array";
25
+ readonly format: "TypedArray:Float64Array";
26
+ };
27
+ readonly output: Float64ArrayConstructor;
28
+ }, {
29
+ readonly pattern: {
30
+ readonly type: "array";
31
+ readonly format: "TypedArray:Float32Array";
32
+ };
33
+ readonly output: Float32ArrayConstructor;
34
+ }, {
35
+ readonly pattern: {
36
+ readonly type: "array";
37
+ readonly format: "TypedArray:Float16Array";
38
+ };
39
+ readonly output: Float16ArrayConstructor;
40
+ }, {
41
+ readonly pattern: {
42
+ readonly type: "array";
43
+ readonly format: "TypedArray:Int16Array";
44
+ };
45
+ readonly output: Int16ArrayConstructor;
46
+ }, {
47
+ readonly pattern: {
48
+ readonly type: "array";
49
+ readonly format: "TypedArray:Int8Array";
50
+ };
51
+ readonly output: Int8ArrayConstructor;
52
+ }, {
53
+ readonly pattern: {
54
+ readonly type: "array";
55
+ readonly format: "TypedArray:Uint8Array";
56
+ };
57
+ readonly output: Uint8ArrayConstructor;
58
+ }, {
59
+ readonly pattern: {
60
+ readonly type: "array";
61
+ readonly format: "TypedArray:Uint16Array";
62
+ };
63
+ readonly output: Uint16ArrayConstructor;
64
+ }, {
65
+ readonly pattern: {
66
+ readonly type: "array";
67
+ readonly format: "TypedArray";
68
+ };
69
+ readonly output: TypedArray;
70
+ }];
71
+ readonly parseNotKeyword: true;
72
+ readonly parseIfThenElseKeywords: true;
73
+ readonly keepDefaultedPropertiesOptional: true;
74
+ readonly references: false;
75
+ };
76
+ export type TypedArraySchemaOptions = typeof TypedArraySchemaOptions;
77
+ export type VectorFromSchema<SCHEMA extends JsonSchema> = FromSchema<SCHEMA, TypedArraySchemaOptions>;
78
+ export declare const TypedArraySchema: (annotations?: Record<string, unknown>) => {
79
+ readonly type: "array";
80
+ readonly format: "TypedArray";
81
+ readonly title: "Typed Array";
82
+ readonly description: "A typed array (Float32Array, Int8Array, etc.)";
83
+ };
84
+ export {};
85
+ //# sourceMappingURL=TypedArray.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypedArray.d.ts","sourceRoot":"","sources":["../../src/vector/TypedArray.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAA+C,MAAM,2BAA2B,CAAC;AACpG,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEvD;;;;;;;;;GASG;AACH,MAAM,MAAM,UAAU,GAClB,YAAY,GACZ,YAAY,GACZ,YAAY,GACZ,SAAS,GACT,UAAU,GACV,UAAU,GACV,WAAW,CAAC;AAEhB,MAAM,MAAM,gBAAgB,GACxB,YAAY,GACZ,yBAAyB,GACzB,yBAAyB,GACzB,yBAAyB,GACzB,sBAAsB,GACtB,uBAAuB,GACvB,uBAAuB,GACvB,wBAAwB,CAAC;AAE7B,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAEhE;AAKD,QAAA,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCS,CAAC;AAEvC,MAAM,MAAM,uBAAuB,GAAG,OAAO,uBAAuB,CAAC;AAErE,MAAM,MAAM,gBAAgB,CAAC,MAAM,SAAS,UAAU,IAAI,UAAU,CAClE,MAAM,EACN,uBAAuB,CACxB,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,cAAa,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;;;;;CAQzE,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { TypedArray } from "./TypedArray";
7
+ /**
8
+ * Calculates cosine similarity between two vectors
9
+ * Returns a value between -1 and 1, where 1 means identical direction
10
+ */
11
+ export declare function cosineSimilarity(a: TypedArray, b: TypedArray): number;
12
+ /**
13
+ * Calculates Jaccard similarity between two vectors
14
+ * Uses the formula: sum(min(a[i], b[i])) / sum(max(a[i], b[i]))
15
+ * Returns a value between 0 and 1
16
+ * For negative values, normalizes by finding the global min and shifting to non-negative range
17
+ */
18
+ export declare function jaccardSimilarity(a: TypedArray, b: TypedArray): number;
19
+ /**
20
+ * Calculates Hamming distance between two vectors (normalized)
21
+ * Counts the number of positions where vectors differ
22
+ * Returns a value between 0 and 1 (0 = identical, 1 = completely different)
23
+ */
24
+ export declare function hammingDistance(a: TypedArray, b: TypedArray): number;
25
+ /**
26
+ * Calculates Hamming similarity (inverse of distance)
27
+ * Returns a value between 0 and 1 (1 = identical, 0 = completely different)
28
+ */
29
+ export declare function hammingSimilarity(a: TypedArray, b: TypedArray): number;
30
+ //# sourceMappingURL=VectorSimilarityUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VectorSimilarityUtils.d.ts","sourceRoot":"","sources":["../../src/vector/VectorSimilarityUtils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,MAAM,CAiBrE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,MAAM,CAyBtE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,MAAM,CAcpE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,MAAM,CAEtE"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { TypedArray } from "./TypedArray";
7
+ /**
8
+ * Calculates the magnitude (L2 norm) of a vector
9
+ */
10
+ export declare function magnitude(arr: TypedArray | number[]): number;
11
+ /**
12
+ * Calculates the inner (dot) product of two vectors
13
+ */
14
+ export declare function inner(arr1: TypedArray, arr2: TypedArray): number;
15
+ /**
16
+ * Normalizes a vector to unit length (L2 normalization)
17
+ *
18
+ * @param vector - The vector to normalize
19
+ * @param throwOnZero - If true, throws an error for zero vectors. If false, returns the original vector.
20
+ * @returns Normalized vector with the same type as input
21
+ */
22
+ export declare function normalize(vector: TypedArray, throwOnZero?: boolean, float32?: boolean): TypedArray;
23
+ /**
24
+ * Normalizes an array of numbers to unit length (L2 normalization)
25
+ *
26
+ * @param values - The array of numbers to normalize
27
+ * @param throwOnZero - If true, throws an error for zero vectors. If false, returns the original array.
28
+ * @returns Normalized array of numbers
29
+ */
30
+ export declare function normalizeNumberArray(values: number[], throwOnZero?: boolean): number[];
31
+ //# sourceMappingURL=VectorUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VectorUtils.d.ts","sourceRoot":"","sources":["../../src/vector/VectorUtils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,EAAE,GAAG,MAAM,CAG5D;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,CAMhE;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,UAAO,EAAE,OAAO,UAAQ,GAAG,UAAU,CAwC7F;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,WAAW,UAAQ,GAAG,MAAM,EAAE,CAWpF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@workglow/util",
3
3
  "type": "module",
4
- "version": "0.0.85",
4
+ "version": "0.0.87",
5
5
  "description": "Utility functions and shared types for Workglow, providing common functionality across all packages.",
6
6
  "scripts": {
7
7
  "watch": "concurrently -c 'auto' 'bun:watch-*'",
@@ -36,7 +36,7 @@
36
36
  "access": "public"
37
37
  },
38
38
  "dependencies": {
39
- "json-schema-library": "^10.5.1",
40
- "@sroussey/json-schema-to-ts": "3.1.3"
39
+ "@sroussey/json-schema-library": "^10.5.3",
40
+ "@sroussey/json-schema-to-ts": "3.1.4"
41
41
  }
42
42
  }