forbocai 0.3.18 → 0.4.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/README.md +3 -3
- package/dist/index.d.mts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +37 -27
- package/dist/index.mjs +37 -27
- package/package.json +1 -3
package/README.md
CHANGED
|
@@ -57,14 +57,14 @@ git add . && git commit -m "chore: release vX.X.X" && git push
|
|
|
57
57
|
|
|
58
58
|
The **ForbocAI SDK** is an **Engine-Agnostic** toolkit for creating autonomous AI-powered NPCs in any game or application. It runs anywhere (Node, Browser, Python, Rust).
|
|
59
59
|
|
|
60
|
-
- **Local SLM Cortex** — Run
|
|
60
|
+
- **Local SLM Cortex** — Run quantized Small Language Models (SLMs) natively via **node-llama-cpp**.
|
|
61
61
|
- **Autonomous NPCs** — Create agents with persona, memory, and validated actions.
|
|
62
62
|
- **Persistent Memory** — Local vector storage for semantic recall.
|
|
63
63
|
- **Portable Souls** — Permanent storage (Arweave) + Solana NFTs for tradeable agent identities.
|
|
64
64
|
- **Automated QA** — Ghost Agents for headless testing at scale.
|
|
65
65
|
|
|
66
66
|
**Requirements**:
|
|
67
|
-
-
|
|
67
|
+
- **Native Environment**: Node.js 18+ (Desktop/Server) or C++11 (Game Engine).
|
|
68
68
|
- Node.js 18+ for CLI/Build.
|
|
69
69
|
|
|
70
70
|
---
|
|
@@ -164,7 +164,7 @@ console.log(response.dialogue);
|
|
|
164
164
|
|
|
165
165
|
| Module | Description | Status |
|
|
166
166
|
|--------|-------------|--------|
|
|
167
|
-
| **Cortex** | Local SLM inference engine (Self-Contained) | ✅
|
|
167
|
+
| **Cortex** | Local SLM inference engine (Self-Contained) | ✅ Node (Native) / 🚧 C++ (UE) |
|
|
168
168
|
| **Agent** | Autonomous entities with persona, state, memory | ✅ Complete |
|
|
169
169
|
| **Memory** | Local Vector DB (IndexedDB / FS) | ✅ Complete |
|
|
170
170
|
| **Bridge** | Neuro-symbolic action validation | ✅ Complete |
|
package/dist/index.d.mts
CHANGED
|
@@ -17,14 +17,12 @@ interface CortexStatus {
|
|
|
17
17
|
id: string;
|
|
18
18
|
model: string;
|
|
19
19
|
ready: boolean;
|
|
20
|
-
engine: '
|
|
20
|
+
engine: 'mock' | 'remote' | 'node-llama-cpp';
|
|
21
21
|
}
|
|
22
22
|
interface ICortex {
|
|
23
23
|
init(): Promise<CortexStatus>;
|
|
24
24
|
complete(prompt: string, options?: CompletionOptions): Promise<string>;
|
|
25
25
|
completeStream(prompt: string, options?: CompletionOptions): AsyncGenerator<string>;
|
|
26
|
-
processObservation(observation: Observation): Promise<Directive>;
|
|
27
|
-
generateAction(directive: Directive): Promise<AgentAction>;
|
|
28
26
|
}
|
|
29
27
|
interface CompletionOptions {
|
|
30
28
|
temperature?: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -17,14 +17,12 @@ interface CortexStatus {
|
|
|
17
17
|
id: string;
|
|
18
18
|
model: string;
|
|
19
19
|
ready: boolean;
|
|
20
|
-
engine: '
|
|
20
|
+
engine: 'mock' | 'remote' | 'node-llama-cpp';
|
|
21
21
|
}
|
|
22
22
|
interface ICortex {
|
|
23
23
|
init(): Promise<CortexStatus>;
|
|
24
24
|
complete(prompt: string, options?: CompletionOptions): Promise<string>;
|
|
25
25
|
completeStream(prompt: string, options?: CompletionOptions): AsyncGenerator<string>;
|
|
26
|
-
processObservation(observation: Observation): Promise<Directive>;
|
|
27
|
-
generateAction(directive: Directive): Promise<AgentAction>;
|
|
28
26
|
}
|
|
29
27
|
interface CompletionOptions {
|
|
30
28
|
temperature?: number;
|
package/dist/index.js
CHANGED
|
@@ -202313,6 +202313,13 @@ var createNativeCortex = (config) => {
|
|
|
202313
202313
|
let model;
|
|
202314
202314
|
let context;
|
|
202315
202315
|
let session;
|
|
202316
|
+
let embeddingContext;
|
|
202317
|
+
const createEmbeddingContext = async () => {
|
|
202318
|
+
if (!model.embeddingSupported) {
|
|
202319
|
+
throw new Error("Model does not support embeddings");
|
|
202320
|
+
}
|
|
202321
|
+
embeddingContext = await model.createEmbeddingContext();
|
|
202322
|
+
};
|
|
202316
202323
|
const MODELS_DIR = path.join(process.cwd(), "local_infrastructure", "models");
|
|
202317
202324
|
const init3 = async () => {
|
|
202318
202325
|
if (status.ready) return status;
|
|
@@ -202341,6 +202348,12 @@ var createNativeCortex = (config) => {
|
|
|
202341
202348
|
});
|
|
202342
202349
|
console.log("> Creating context...");
|
|
202343
202350
|
context = await model.createContext();
|
|
202351
|
+
if (model.embeddingSupported) {
|
|
202352
|
+
console.log("> Creating embedding context...");
|
|
202353
|
+
embeddingContext = await model.createEmbeddingContext();
|
|
202354
|
+
} else {
|
|
202355
|
+
console.log("> Model does not support embeddings");
|
|
202356
|
+
}
|
|
202344
202357
|
session = new LlamaChatSession({
|
|
202345
202358
|
contextSequence: context.getSequence()
|
|
202346
202359
|
});
|
|
@@ -202404,37 +202417,20 @@ var createNativeCortex = (config) => {
|
|
|
202404
202417
|
const embed = async (text) => {
|
|
202405
202418
|
if (!status.ready) await init3();
|
|
202406
202419
|
try {
|
|
202407
|
-
|
|
202420
|
+
if (!embeddingContext) {
|
|
202421
|
+
await createEmbeddingContext();
|
|
202422
|
+
}
|
|
202423
|
+
const embeddings = await embeddingContext.getEmbeddingFor(text);
|
|
202424
|
+
return Array.from(embeddings);
|
|
202408
202425
|
} catch (e2) {
|
|
202409
|
-
|
|
202410
|
-
|
|
202411
|
-
};
|
|
202412
|
-
const processObservation = async (obs) => {
|
|
202413
|
-
const prompt = `System: You are an agent.
|
|
202414
|
-
Observation: ${obs.content}
|
|
202415
|
-
Task: Generete a JSON directive { "type": "...", "content": "..." }.`;
|
|
202416
|
-
const res = await complete(prompt);
|
|
202417
|
-
try {
|
|
202418
|
-
return JSON.parse(res);
|
|
202419
|
-
} catch {
|
|
202420
|
-
return { type: "thought", content: res };
|
|
202421
|
-
}
|
|
202422
|
-
};
|
|
202423
|
-
const generateAction = async (dir) => {
|
|
202424
|
-
const prompt = `Directive: ${dir.content}. Generate JSON action.`;
|
|
202425
|
-
const res = await complete(prompt);
|
|
202426
|
-
try {
|
|
202427
|
-
return JSON.parse(res);
|
|
202428
|
-
} catch {
|
|
202429
|
-
return { type: "idle", reason: res };
|
|
202426
|
+
console.warn("Embedding generation failed, falling back to random vector:", e2);
|
|
202427
|
+
return new Array(384).fill(0).map(() => Math.random());
|
|
202430
202428
|
}
|
|
202431
202429
|
};
|
|
202432
202430
|
return {
|
|
202433
202431
|
init: init3,
|
|
202434
202432
|
complete,
|
|
202435
202433
|
completeStream,
|
|
202436
|
-
processObservation,
|
|
202437
|
-
generateAction,
|
|
202438
202434
|
embed
|
|
202439
202435
|
// Extended interface for private use by Memory
|
|
202440
202436
|
};
|
|
@@ -202831,9 +202827,23 @@ var initVectorEngine = async () => {
|
|
|
202831
202827
|
}
|
|
202832
202828
|
};
|
|
202833
202829
|
var generateEmbedding = async (text) => {
|
|
202834
|
-
|
|
202835
|
-
|
|
202836
|
-
|
|
202830
|
+
const cortexConfig = {
|
|
202831
|
+
model: "smollm2-135m",
|
|
202832
|
+
temperature: 0.7,
|
|
202833
|
+
maxTokens: 128,
|
|
202834
|
+
gpu: true
|
|
202835
|
+
};
|
|
202836
|
+
const cortex = createCortex(cortexConfig);
|
|
202837
|
+
try {
|
|
202838
|
+
await cortex.init();
|
|
202839
|
+
const embedding = await cortex.embed(text);
|
|
202840
|
+
return embedding;
|
|
202841
|
+
} catch (e2) {
|
|
202842
|
+
console.warn("Embedding generation failed, falling back to transformers:", e2);
|
|
202843
|
+
if (!pipeline) await initVectorEngine();
|
|
202844
|
+
const output = await pipeline(text, { pooling: "mean", normalize: true });
|
|
202845
|
+
return Array.from(output.data);
|
|
202846
|
+
}
|
|
202837
202847
|
};
|
|
202838
202848
|
var getVectorTable = async (dbPath, tableName = "memories") => {
|
|
202839
202849
|
if (!lancedb) await initVectorEngine();
|
package/dist/index.mjs
CHANGED
|
@@ -51,6 +51,13 @@ var createNativeCortex = (config) => {
|
|
|
51
51
|
let model;
|
|
52
52
|
let context;
|
|
53
53
|
let session;
|
|
54
|
+
let embeddingContext;
|
|
55
|
+
const createEmbeddingContext = async () => {
|
|
56
|
+
if (!model.embeddingSupported) {
|
|
57
|
+
throw new Error("Model does not support embeddings");
|
|
58
|
+
}
|
|
59
|
+
embeddingContext = await model.createEmbeddingContext();
|
|
60
|
+
};
|
|
54
61
|
const MODELS_DIR = path.join(process.cwd(), "local_infrastructure", "models");
|
|
55
62
|
const init2 = async () => {
|
|
56
63
|
if (status.ready) return status;
|
|
@@ -79,6 +86,12 @@ var createNativeCortex = (config) => {
|
|
|
79
86
|
});
|
|
80
87
|
console.log("> Creating context...");
|
|
81
88
|
context = await model.createContext();
|
|
89
|
+
if (model.embeddingSupported) {
|
|
90
|
+
console.log("> Creating embedding context...");
|
|
91
|
+
embeddingContext = await model.createEmbeddingContext();
|
|
92
|
+
} else {
|
|
93
|
+
console.log("> Model does not support embeddings");
|
|
94
|
+
}
|
|
82
95
|
session = new LlamaChatSession({
|
|
83
96
|
contextSequence: context.getSequence()
|
|
84
97
|
});
|
|
@@ -142,37 +155,20 @@ var createNativeCortex = (config) => {
|
|
|
142
155
|
const embed = async (text) => {
|
|
143
156
|
if (!status.ready) await init2();
|
|
144
157
|
try {
|
|
145
|
-
|
|
158
|
+
if (!embeddingContext) {
|
|
159
|
+
await createEmbeddingContext();
|
|
160
|
+
}
|
|
161
|
+
const embeddings = await embeddingContext.getEmbeddingFor(text);
|
|
162
|
+
return Array.from(embeddings);
|
|
146
163
|
} catch (e) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
};
|
|
150
|
-
const processObservation = async (obs) => {
|
|
151
|
-
const prompt = `System: You are an agent.
|
|
152
|
-
Observation: ${obs.content}
|
|
153
|
-
Task: Generete a JSON directive { "type": "...", "content": "..." }.`;
|
|
154
|
-
const res = await complete(prompt);
|
|
155
|
-
try {
|
|
156
|
-
return JSON.parse(res);
|
|
157
|
-
} catch {
|
|
158
|
-
return { type: "thought", content: res };
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
const generateAction = async (dir) => {
|
|
162
|
-
const prompt = `Directive: ${dir.content}. Generate JSON action.`;
|
|
163
|
-
const res = await complete(prompt);
|
|
164
|
-
try {
|
|
165
|
-
return JSON.parse(res);
|
|
166
|
-
} catch {
|
|
167
|
-
return { type: "idle", reason: res };
|
|
164
|
+
console.warn("Embedding generation failed, falling back to random vector:", e);
|
|
165
|
+
return new Array(384).fill(0).map(() => Math.random());
|
|
168
166
|
}
|
|
169
167
|
};
|
|
170
168
|
return {
|
|
171
169
|
init: init2,
|
|
172
170
|
complete,
|
|
173
171
|
completeStream,
|
|
174
|
-
processObservation,
|
|
175
|
-
generateAction,
|
|
176
172
|
embed
|
|
177
173
|
// Extended interface for private use by Memory
|
|
178
174
|
};
|
|
@@ -569,9 +565,23 @@ var initVectorEngine = async () => {
|
|
|
569
565
|
}
|
|
570
566
|
};
|
|
571
567
|
var generateEmbedding = async (text) => {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
568
|
+
const cortexConfig = {
|
|
569
|
+
model: "smollm2-135m",
|
|
570
|
+
temperature: 0.7,
|
|
571
|
+
maxTokens: 128,
|
|
572
|
+
gpu: true
|
|
573
|
+
};
|
|
574
|
+
const cortex = createCortex(cortexConfig);
|
|
575
|
+
try {
|
|
576
|
+
await cortex.init();
|
|
577
|
+
const embedding = await cortex.embed(text);
|
|
578
|
+
return embedding;
|
|
579
|
+
} catch (e) {
|
|
580
|
+
console.warn("Embedding generation failed, falling back to transformers:", e);
|
|
581
|
+
if (!pipeline) await initVectorEngine();
|
|
582
|
+
const output = await pipeline(text, { pooling: "mean", normalize: true });
|
|
583
|
+
return Array.from(output.data);
|
|
584
|
+
}
|
|
575
585
|
};
|
|
576
586
|
var getVectorTable = async (dbPath, tableName = "memories") => {
|
|
577
587
|
if (!lancedb) await initVectorEngine();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "forbocai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"description": "The Infrastructure Layer for Autonomous AI Characters",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,11 +21,9 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@irys/sdk": "^0.1.1",
|
|
23
23
|
"@lancedb/lancedb": "^0.23.0",
|
|
24
|
-
"@mlc-ai/web-llm": "^0.2.80",
|
|
25
24
|
"@xenova/transformers": "^2.17.2",
|
|
26
25
|
"apache-arrow": "^18.1.0",
|
|
27
26
|
"axios": "^1.6.2",
|
|
28
|
-
"idb": "^8.0.3",
|
|
29
27
|
"node-llama-cpp": "^3.15.1",
|
|
30
28
|
"onnxruntime-node": "^1.23.2",
|
|
31
29
|
"zod": "^3.22.4"
|