rice-node-sdk 1.0.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.
@@ -0,0 +1,10 @@
1
+ import Long from "long";
2
+ export declare class BitVector {
3
+ private chunks;
4
+ static readonly ADDRESS_SIZE_U64 = 16;
5
+ constructor(chunks?: Long[] | number[]);
6
+ static random(): BitVector;
7
+ toList(): Long[];
8
+ hammingDistance(other: BitVector): number;
9
+ private popCount32;
10
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.BitVector = void 0;
7
+ const long_1 = __importDefault(require("long"));
8
+ class BitVector {
9
+ constructor(chunks) {
10
+ if (chunks) {
11
+ if (chunks.length !== BitVector.ADDRESS_SIZE_U64) {
12
+ throw new Error(`BitVector must have ${BitVector.ADDRESS_SIZE_U64} chunks`);
13
+ }
14
+ this.chunks = chunks.map((c) => long_1.default.fromValue(c));
15
+ }
16
+ else {
17
+ this.chunks = new Array(BitVector.ADDRESS_SIZE_U64).fill(long_1.default.UZERO);
18
+ }
19
+ }
20
+ static random() {
21
+ const chunks = [];
22
+ for (let i = 0; i < BitVector.ADDRESS_SIZE_U64; i++) {
23
+ // Generate random 64-bit int.
24
+ // random() returns [0, 1).
25
+ const low = Math.floor(Math.random() * 0x100000000);
26
+ const high = Math.floor(Math.random() * 0x100000000);
27
+ chunks.push(new long_1.default(low, high, true)); // unsigned
28
+ }
29
+ return new BitVector(chunks);
30
+ }
31
+ toList() {
32
+ return this.chunks;
33
+ }
34
+ hammingDistance(other) {
35
+ let distance = 0;
36
+ for (let i = 0; i < BitVector.ADDRESS_SIZE_U64; i++) {
37
+ const xor = this.chunks[i].xor(other.chunks[i]);
38
+ // Long stores values as signed 32-bit integers, but bitwise operations work on bits.
39
+ // getLowBits() and getHighBits() return signed 32-bit integers.
40
+ // We cast them to unsigned for bit counting logic if needed, but standard popcount works on bit pattern.
41
+ distance +=
42
+ this.popCount32(xor.getLowBits()) + this.popCount32(xor.getHighBits());
43
+ }
44
+ return distance;
45
+ }
46
+ // Hamming weight (population count) for 32-bit integer
47
+ popCount32(n) {
48
+ n = n - ((n >>> 1) & 0x55555555);
49
+ n = (n & 0x33333333) + ((n >>> 2) & 0x33333333);
50
+ return (((n + (n >>> 4)) & 0xf0f0f0f) * 0x1010101) >>> 24;
51
+ }
52
+ }
53
+ exports.BitVector = BitVector;
54
+ BitVector.ADDRESS_SIZE_U64 = 16;
@@ -0,0 +1,29 @@
1
+ export declare const state: ({
2
+ name: string;
3
+ description: string;
4
+ input_schema: {
5
+ type: string;
6
+ properties: {
7
+ content: {
8
+ type: string;
9
+ description: string;
10
+ };
11
+ query?: undefined;
12
+ };
13
+ required: string[];
14
+ };
15
+ } | {
16
+ name: string;
17
+ description: string;
18
+ input_schema: {
19
+ type: string;
20
+ properties: {
21
+ query: {
22
+ type: string;
23
+ description: string;
24
+ };
25
+ content?: undefined;
26
+ };
27
+ required: string[];
28
+ };
29
+ })[];
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.state = void 0;
4
+ exports.state = [
5
+ {
6
+ name: "focus",
7
+ description: "Stores a piece of information in working memory (State/Flux).",
8
+ input_schema: {
9
+ type: "object",
10
+ properties: {
11
+ content: {
12
+ type: "string",
13
+ description: "The information to focus on.",
14
+ },
15
+ },
16
+ required: ["content"],
17
+ },
18
+ },
19
+ {
20
+ name: "recall",
21
+ description: "Recalls relevant memories from State based on a query.",
22
+ input_schema: {
23
+ type: "object",
24
+ properties: {
25
+ query: { type: "string", description: "The query to search for." },
26
+ },
27
+ required: ["query"],
28
+ },
29
+ },
30
+ {
31
+ name: "remember",
32
+ description: "Stores information in long-term memory for future recall.",
33
+ input_schema: {
34
+ type: "object",
35
+ properties: {
36
+ content: {
37
+ type: "string",
38
+ description: "The information to remember.",
39
+ },
40
+ },
41
+ required: ["content"],
42
+ },
43
+ },
44
+ ];
@@ -0,0 +1,2 @@
1
+ import { StateClient } from "../state";
2
+ export declare function execute(name: string, args: any, client: StateClient): Promise<string | boolean | any[]>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.execute = execute;
4
+ async function execute(name, args, client) {
5
+ switch (name) {
6
+ case "focus":
7
+ return await client.focus(args.content);
8
+ case "recall":
9
+ return await client.reminisce(args.query);
10
+ case "remember":
11
+ if (args.content) {
12
+ return await client.commit(args.content, "Stored in long-term memory", {
13
+ action: "remember",
14
+ });
15
+ }
16
+ return await client.commit(args.input, args.outcome, {
17
+ action: args.action,
18
+ });
19
+ default:
20
+ throw new Error(`Unknown tool: ${name}`);
21
+ }
22
+ }
@@ -0,0 +1,29 @@
1
+ export declare const state: ({
2
+ name: string;
3
+ description: string;
4
+ parameters: {
5
+ type: string;
6
+ properties: {
7
+ content: {
8
+ type: string;
9
+ description: string;
10
+ };
11
+ query?: undefined;
12
+ };
13
+ required: string[];
14
+ };
15
+ } | {
16
+ name: string;
17
+ description: string;
18
+ parameters: {
19
+ type: string;
20
+ properties: {
21
+ query: {
22
+ type: string;
23
+ description: string;
24
+ };
25
+ content?: undefined;
26
+ };
27
+ required: string[];
28
+ };
29
+ })[];
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.state = void 0;
4
+ exports.state = [
5
+ {
6
+ name: "focus",
7
+ description: "Stores a piece of information in working memory (State/Flux).",
8
+ parameters: {
9
+ type: "OBJECT",
10
+ properties: {
11
+ content: {
12
+ type: "STRING",
13
+ description: "The information to focus on.",
14
+ },
15
+ },
16
+ required: ["content"],
17
+ },
18
+ },
19
+ {
20
+ name: "recall",
21
+ description: "Recalls relevant memories from State based on a query.",
22
+ parameters: {
23
+ type: "OBJECT",
24
+ properties: {
25
+ query: { type: "STRING", description: "The query to search for." },
26
+ },
27
+ required: ["query"],
28
+ },
29
+ },
30
+ {
31
+ name: "remember",
32
+ description: "Stores information in long-term memory for future recall.",
33
+ parameters: {
34
+ type: "OBJECT",
35
+ properties: {
36
+ content: {
37
+ type: "STRING",
38
+ description: "The information to remember.",
39
+ },
40
+ },
41
+ required: ["content"],
42
+ },
43
+ },
44
+ ];
@@ -0,0 +1,35 @@
1
+ export declare const state: ({
2
+ type: string;
3
+ function: {
4
+ name: string;
5
+ description: string;
6
+ parameters: {
7
+ type: string;
8
+ properties: {
9
+ content: {
10
+ type: string;
11
+ description: string;
12
+ };
13
+ query?: undefined;
14
+ };
15
+ required: string[];
16
+ };
17
+ };
18
+ } | {
19
+ type: string;
20
+ function: {
21
+ name: string;
22
+ description: string;
23
+ parameters: {
24
+ type: string;
25
+ properties: {
26
+ query: {
27
+ type: string;
28
+ description: string;
29
+ };
30
+ content?: undefined;
31
+ };
32
+ required: string[];
33
+ };
34
+ };
35
+ })[];
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.state = void 0;
4
+ exports.state = [
5
+ {
6
+ type: "function",
7
+ function: {
8
+ name: "focus",
9
+ description: "Stores a piece of information in working memory (State/Flux).",
10
+ parameters: {
11
+ type: "object",
12
+ properties: {
13
+ content: {
14
+ type: "string",
15
+ description: "The information to focus on.",
16
+ },
17
+ },
18
+ required: ["content"],
19
+ },
20
+ },
21
+ },
22
+ {
23
+ type: "function",
24
+ function: {
25
+ name: "recall",
26
+ description: "Recalls relevant memories from State based on a query.",
27
+ parameters: {
28
+ type: "object",
29
+ properties: {
30
+ query: { type: "string", description: "The query to search for." },
31
+ },
32
+ required: ["query"],
33
+ },
34
+ },
35
+ },
36
+ {
37
+ type: "function",
38
+ function: {
39
+ name: "remember",
40
+ description: "Stores information in long-term memory for future recall.",
41
+ parameters: {
42
+ type: "object",
43
+ properties: {
44
+ content: {
45
+ type: "string",
46
+ description: "The information to remember.",
47
+ },
48
+ },
49
+ required: ["content"],
50
+ },
51
+ },
52
+ },
53
+ ];
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "rice-node-sdk",
3
+ "version": "1.0.0",
4
+ "description": "SDK for Rice",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./tools/anthropic": {
13
+ "types": "./dist/tools/anthropic.d.ts",
14
+ "default": "./dist/tools/anthropic.js"
15
+ },
16
+ "./tools/google": {
17
+ "types": "./dist/tools/google.d.ts",
18
+ "default": "./dist/tools/google.js"
19
+ },
20
+ "./tools/openai": {
21
+ "types": "./dist/tools/openai.d.ts",
22
+ "default": "./dist/tools/openai.js"
23
+ },
24
+ "./tools/execute": {
25
+ "types": "./dist/tools/execute.d.ts",
26
+ "default": "./dist/tools/execute.js"
27
+ }
28
+ },
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "scripts": {
33
+ "build": "tsc && npm run copy-proto",
34
+ "copy-proto": "mkdir -p dist/state/proto && cp src/state/proto/state.proto dist/state/proto/state.proto",
35
+ "prepack": "npm run build",
36
+ "test": "jest"
37
+ },
38
+ "keywords": [
39
+ "rice",
40
+ "ai"
41
+ ],
42
+ "author": "",
43
+ "license": "ISC",
44
+ "dependencies": {
45
+ "@grpc/grpc-js": "^1.10.0",
46
+ "@grpc/proto-loader": "^0.7.10",
47
+ "axios": "^1.6.0",
48
+ "long": "^5.2.3"
49
+ },
50
+ "devDependencies": {
51
+ "@types/jest": "^30.0.0",
52
+ "@types/node": "^20.0.0",
53
+ "dotenv": "^17.2.3",
54
+ "jest": "^30.2.0",
55
+ "ts-jest": "^29.4.6",
56
+ "typescript": "^5.3.0"
57
+ }
58
+ }