react-native-nobodywho 0.2.1 → 0.3.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nobodywho",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Run LLMs locally with offline inference — React Native bindings",
5
5
  "main": "src/wrapper.ts",
6
6
  "types": "src/wrapper.ts",
@@ -47,5 +47,10 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "uniffi-bindgen-react-native": "0.30.0-1"
50
+ },
51
+ "devDependencies": {
52
+ "@types/jest": "^30.0.0",
53
+ "jest": "^30.3.0",
54
+ "ts-jest": "^29.4.9"
50
55
  }
51
56
  }
@@ -1,4 +1,4 @@
1
- import { CrossEncoder as RustCrossEncoder } from "../generated/ts/nobodywho";
1
+ import { RustCrossEncoder } from "../generated/ts/nobodywho";
2
2
  import { Model } from "./model";
3
3
 
4
4
  /**
package/src/encoder.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Encoder as RustEncoder } from "../generated/ts/nobodywho";
1
+ import { RustEncoder } from "../generated/ts/nobodywho";
2
2
  import { Model } from "./model";
3
3
 
4
4
  /**
package/src/model.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  loadModel,
3
- type ModelInterface,
3
+ type RustModelInterface,
4
4
  } from "../generated/ts/nobodywho";
5
5
 
6
6
  /**
@@ -26,10 +26,10 @@ import {
26
26
  */
27
27
  export class Model {
28
28
  /** @internal */
29
- readonly _inner: ModelInterface;
29
+ readonly _inner: RustModelInterface;
30
30
 
31
31
  /** @internal */
32
- private constructor(inner: ModelInterface) {
32
+ private constructor(inner: RustModelInterface) {
33
33
  this._inner = inner;
34
34
  }
35
35
 
package/src/tool.ts CHANGED
@@ -5,12 +5,20 @@ import {
5
5
  } from "../generated/ts/nobodywho";
6
6
 
7
7
  /**
8
- * Convert a value from JSON based on the JSON Schema type.
8
+ * Recursively convert a value from JSON based on a JSON Schema type.
9
+ *
10
+ * Supports primitives (`string`, `number`, `integer`, `boolean`),
11
+ * arrays (`{ type: "array", items: ... }`), and nested objects
12
+ * (`{ type: "object", properties: { ... } }`).
9
13
  */
10
14
  function convertValue(
11
15
  value: unknown,
12
16
  schema: Record<string, unknown>,
13
17
  ): unknown {
18
+ if (value === null || value === undefined) {
19
+ return value;
20
+ }
21
+
14
22
  switch (schema.type) {
15
23
  case "integer":
16
24
  case "number":
@@ -19,6 +27,25 @@ function convertValue(
19
27
  return typeof value === "string" ? value === "true" : Boolean(value);
20
28
  case "string":
21
29
  return String(value);
30
+ case "array": {
31
+ if (!Array.isArray(value)) return value;
32
+ const itemSchema = schema.items as Record<string, unknown> | undefined;
33
+ if (!itemSchema) return value;
34
+ return value.map((item) => convertValue(item, itemSchema));
35
+ }
36
+ case "object": {
37
+ if (typeof value !== "object" || Array.isArray(value)) return value;
38
+ const properties = schema.properties as
39
+ | Record<string, Record<string, unknown>>
40
+ | undefined;
41
+ if (!properties) return value;
42
+ const obj = value as Record<string, unknown>;
43
+ const result: Record<string, unknown> = {};
44
+ for (const [key, propSchema] of Object.entries(properties)) {
45
+ result[key] = key in obj ? convertValue(obj[key], propSchema) : undefined;
46
+ }
47
+ return result;
48
+ }
22
49
  default:
23
50
  return value;
24
51
  }
@@ -78,3 +105,6 @@ export class Tool {
78
105
  return this._inner.getSchemaJson();
79
106
  }
80
107
  }
108
+
109
+ /** @internal Exported for testing only. */
110
+ export { convertValue as _convertValue };