@forbocai/browser 0.5.4 → 0.5.6
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/index.d.mts +12 -6
- package/dist/index.d.ts +12 -6
- package/dist/index.js +16 -7
- package/dist/index.mjs +16 -7
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
|
-
import { CortexConfig, ICortex,
|
|
1
|
+
import { CortexConfig, ICortex, MemoryItem } from '@forbocai/core';
|
|
2
2
|
|
|
3
3
|
declare const createBrowserCortex: (config?: CortexConfig) => ICortex;
|
|
4
4
|
declare const createCortex: (config?: CortexConfig) => ICortex;
|
|
5
5
|
|
|
6
6
|
interface IBrowserMemory {
|
|
7
|
-
store(text: string, type?:
|
|
7
|
+
store(text: string, type?: string, importance?: number): Promise<MemoryItem>;
|
|
8
8
|
recall(query: string, limit?: number): Promise<MemoryItem[]>;
|
|
9
9
|
clear(): Promise<void>;
|
|
10
10
|
}
|
|
11
|
-
declare const createBrowserMemory: (config?:
|
|
12
|
-
|
|
11
|
+
declare const createBrowserMemory: (config?: {
|
|
12
|
+
decay?: "none" | "temporal";
|
|
13
|
+
maxContextWindow?: number;
|
|
14
|
+
}) => {
|
|
15
|
+
store: (text: string, type?: string, importance?: number) => Promise<MemoryItem>;
|
|
13
16
|
recall: (query: string, limit?: number) => Promise<MemoryItem[]>;
|
|
14
17
|
clear: () => Promise<void>;
|
|
15
18
|
};
|
|
16
|
-
declare const createMemory: (config?:
|
|
17
|
-
|
|
19
|
+
declare const createMemory: (config?: {
|
|
20
|
+
decay?: "none" | "temporal";
|
|
21
|
+
maxContextWindow?: number;
|
|
22
|
+
}) => {
|
|
23
|
+
store: (text: string, type?: string, importance?: number) => Promise<MemoryItem>;
|
|
18
24
|
recall: (query: string, limit?: number) => Promise<MemoryItem[]>;
|
|
19
25
|
clear: () => Promise<void>;
|
|
20
26
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
|
-
import { CortexConfig, ICortex,
|
|
1
|
+
import { CortexConfig, ICortex, MemoryItem } from '@forbocai/core';
|
|
2
2
|
|
|
3
3
|
declare const createBrowserCortex: (config?: CortexConfig) => ICortex;
|
|
4
4
|
declare const createCortex: (config?: CortexConfig) => ICortex;
|
|
5
5
|
|
|
6
6
|
interface IBrowserMemory {
|
|
7
|
-
store(text: string, type?:
|
|
7
|
+
store(text: string, type?: string, importance?: number): Promise<MemoryItem>;
|
|
8
8
|
recall(query: string, limit?: number): Promise<MemoryItem[]>;
|
|
9
9
|
clear(): Promise<void>;
|
|
10
10
|
}
|
|
11
|
-
declare const createBrowserMemory: (config?:
|
|
12
|
-
|
|
11
|
+
declare const createBrowserMemory: (config?: {
|
|
12
|
+
decay?: "none" | "temporal";
|
|
13
|
+
maxContextWindow?: number;
|
|
14
|
+
}) => {
|
|
15
|
+
store: (text: string, type?: string, importance?: number) => Promise<MemoryItem>;
|
|
13
16
|
recall: (query: string, limit?: number) => Promise<MemoryItem[]>;
|
|
14
17
|
clear: () => Promise<void>;
|
|
15
18
|
};
|
|
16
|
-
declare const createMemory: (config?:
|
|
17
|
-
|
|
19
|
+
declare const createMemory: (config?: {
|
|
20
|
+
decay?: "none" | "temporal";
|
|
21
|
+
maxContextWindow?: number;
|
|
22
|
+
}) => {
|
|
23
|
+
store: (text: string, type?: string, importance?: number) => Promise<MemoryItem>;
|
|
18
24
|
recall: (query: string, limit?: number) => Promise<MemoryItem[]>;
|
|
19
25
|
clear: () => Promise<void>;
|
|
20
26
|
};
|
package/dist/index.js
CHANGED
|
@@ -62,8 +62,9 @@ var createBrowserCortex = (config = {}) => {
|
|
|
62
62
|
const init = async (onProgress) => {
|
|
63
63
|
if (status.ready) return status;
|
|
64
64
|
const initProgressCallback = (report) => {
|
|
65
|
-
|
|
66
|
-
if (onProgress) {
|
|
65
|
+
const match = report.text?.match(/(\d+)%/);
|
|
66
|
+
if (onProgress && match) {
|
|
67
|
+
onProgress(parseInt(match[1], 10));
|
|
67
68
|
}
|
|
68
69
|
};
|
|
69
70
|
const modelId = resolveModelId(friendlyModel);
|
|
@@ -117,14 +118,22 @@ var import_orama = require("@orama/orama");
|
|
|
117
118
|
var embedder = null;
|
|
118
119
|
var initVectorEngine = async () => {
|
|
119
120
|
if (embedder) return;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
try {
|
|
122
|
+
const { pipeline } = await import("@huggingface/transformers");
|
|
123
|
+
embedder = await pipeline("feature-extraction", "Xenova/all-MiniLM-L6-v2");
|
|
124
|
+
} catch (e) {
|
|
125
|
+
console.error("Failed to init Browser Vector Engine:", e);
|
|
126
|
+
}
|
|
123
127
|
};
|
|
124
128
|
var generateEmbedding = async (text) => {
|
|
125
129
|
if (!embedder) await initVectorEngine();
|
|
126
|
-
|
|
127
|
-
|
|
130
|
+
try {
|
|
131
|
+
const result = await embedder(text, { pooling: "mean", normalize: true });
|
|
132
|
+
return Array.from(result.data);
|
|
133
|
+
} catch (e) {
|
|
134
|
+
console.error("Browser embedding failed:", e);
|
|
135
|
+
return new Array(384).fill(0);
|
|
136
|
+
}
|
|
128
137
|
};
|
|
129
138
|
|
|
130
139
|
// src/memory.ts
|
package/dist/index.mjs
CHANGED
|
@@ -20,8 +20,9 @@ var createBrowserCortex = (config = {}) => {
|
|
|
20
20
|
const init = async (onProgress) => {
|
|
21
21
|
if (status.ready) return status;
|
|
22
22
|
const initProgressCallback = (report) => {
|
|
23
|
-
|
|
24
|
-
if (onProgress) {
|
|
23
|
+
const match = report.text?.match(/(\d+)%/);
|
|
24
|
+
if (onProgress && match) {
|
|
25
|
+
onProgress(parseInt(match[1], 10));
|
|
25
26
|
}
|
|
26
27
|
};
|
|
27
28
|
const modelId = resolveModelId(friendlyModel);
|
|
@@ -75,14 +76,22 @@ import { create, insert, search } from "@orama/orama";
|
|
|
75
76
|
var embedder = null;
|
|
76
77
|
var initVectorEngine = async () => {
|
|
77
78
|
if (embedder) return;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
try {
|
|
80
|
+
const { pipeline } = await import("@huggingface/transformers");
|
|
81
|
+
embedder = await pipeline("feature-extraction", "Xenova/all-MiniLM-L6-v2");
|
|
82
|
+
} catch (e) {
|
|
83
|
+
console.error("Failed to init Browser Vector Engine:", e);
|
|
84
|
+
}
|
|
81
85
|
};
|
|
82
86
|
var generateEmbedding = async (text) => {
|
|
83
87
|
if (!embedder) await initVectorEngine();
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
try {
|
|
89
|
+
const result = await embedder(text, { pooling: "mean", normalize: true });
|
|
90
|
+
return Array.from(result.data);
|
|
91
|
+
} catch (e) {
|
|
92
|
+
console.error("Browser embedding failed:", e);
|
|
93
|
+
return new Array(384).fill(0);
|
|
94
|
+
}
|
|
86
95
|
};
|
|
87
96
|
|
|
88
97
|
// src/memory.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forbocai/browser",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"description": "Web Browser implementation for ForbocAI SDK",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"test": "vitest"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@forbocai/core": "^0.5.
|
|
15
|
+
"@forbocai/core": "^0.5.6",
|
|
16
16
|
"@mlc-ai/web-llm": "^0.2.46",
|
|
17
17
|
"@orama/orama": "^2.0.26",
|
|
18
18
|
"@huggingface/transformers": "^3.0.0"
|