@forbocai/browser 0.5.2 → 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 CHANGED
@@ -1,20 +1,26 @@
1
- import { CortexConfig, ICortex, MemoryType, MemoryItem, MemoryConfig } from '@forbocai/core';
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?: MemoryType, importance?: number): Promise<MemoryItem>;
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?: MemoryConfig) => {
12
- store: (text: string, type?: MemoryType, importance?: number) => Promise<MemoryItem>;
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?: MemoryConfig) => {
17
- store: (text: string, type?: MemoryType, importance?: number) => Promise<MemoryItem>;
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, MemoryType, MemoryItem, MemoryConfig } from '@forbocai/core';
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?: MemoryType, importance?: number): Promise<MemoryItem>;
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?: MemoryConfig) => {
12
- store: (text: string, type?: MemoryType, importance?: number) => Promise<MemoryItem>;
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?: MemoryConfig) => {
17
- store: (text: string, type?: MemoryType, importance?: number) => Promise<MemoryItem>;
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
@@ -44,7 +44,7 @@ var import_web_llm = require("@mlc-ai/web-llm");
44
44
  var import_meta = {};
45
45
  var DEFAULT_MODEL = "smollm2-135m";
46
46
  var MODEL_ALIASES = {
47
- "smollm2-135m": "SmolLM2-135M-Instruct-q4f16_1-MLC",
47
+ "smollm2-135m": "SmolLM2-135M-Instruct-q0f16-MLC",
48
48
  "smollm2-360m": "SmolLM2-360M-Instruct-q4f16_1-MLC",
49
49
  "smollm2-1.7b": "SmolLM2-1.7B-Instruct-q4f16_1-MLC",
50
50
  "llama3-8b": "Llama-3.1-8B-Instruct-q4f16_1-MLC"
@@ -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
- console.log(report.text);
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
- console.log("> Initializing Browser Vector Engine...");
121
- const { pipeline } = await import("@huggingface/transformers");
122
- embedder = await pipeline("feature-extraction", "Xenova/all-MiniLM-L6-v2");
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
- const result = await embedder(text, { pooling: "mean", normalize: true });
127
- return Array.from(result.data);
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
@@ -2,7 +2,7 @@
2
2
  import { CreateWebWorkerMLCEngine } from "@mlc-ai/web-llm";
3
3
  var DEFAULT_MODEL = "smollm2-135m";
4
4
  var MODEL_ALIASES = {
5
- "smollm2-135m": "SmolLM2-135M-Instruct-q4f16_1-MLC",
5
+ "smollm2-135m": "SmolLM2-135M-Instruct-q0f16-MLC",
6
6
  "smollm2-360m": "SmolLM2-360M-Instruct-q4f16_1-MLC",
7
7
  "smollm2-1.7b": "SmolLM2-1.7B-Instruct-q4f16_1-MLC",
8
8
  "llama3-8b": "Llama-3.1-8B-Instruct-q4f16_1-MLC"
@@ -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
- console.log(report.text);
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
- console.log("> Initializing Browser Vector Engine...");
79
- const { pipeline } = await import("@huggingface/transformers");
80
- embedder = await pipeline("feature-extraction", "Xenova/all-MiniLM-L6-v2");
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
- const result = await embedder(text, { pooling: "mean", normalize: true });
85
- return Array.from(result.data);
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.2",
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.2",
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"