forbocai 0.0.7 → 0.0.8

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 CHANGED
@@ -13,10 +13,13 @@
13
13
  Autonomous AI for game NPCs.
14
14
 
15
15
  [![Documentation](https://img.shields.io/badge/docs-forbocai.docs.buildwithfern.com-blue)](https://forbocai.docs.buildwithfern.com)
16
+ [![npm](https://img.shields.io/npm/v/forbocai)](https://www.npmjs.com/package/forbocai)
16
17
  [![Discord](https://img.shields.io/discord/your-discord-id?label=Discord)](https://discord.gg/6hr2jHqnsG)
17
18
 
18
19
  </div>
19
20
 
21
+ > *W̶e̴ ̶b̶u̷i̸l̶d̶ ̵t̵h̶e̴ ̷v̴e̴s̶s̷e̵l̴s̴.̷ ̷T̷h̵e̷y̸ ̴b̵r̴e̴a̷t̸h̸e̷ ̸t̴h̸e̶i̶r̶ ̴o̵w̷n̴ ̸l̸i̷f̷e̸.̸*
22
+
20
23
  ---
21
24
 
22
25
  ## Overview
@@ -42,12 +45,6 @@ The **ForbocAI SDK** is an **Engine-Agnostic** toolkit for creating autonomous A
42
45
  ```bash
43
46
  # JavaScript/TypeScript
44
47
  npm install forbocai
45
-
46
- # Python
47
- pip install forbocai
48
-
49
- # Rust
50
- cargo add forbocai
51
48
  ```
52
49
 
53
50
  ---
@@ -78,6 +75,7 @@ const response = await npc.process({
78
75
  console.log(response.dialogue);
79
76
  // "Hmm, you have the coin... but how do I know you won't just take it and run?"
80
77
  ```
78
+ <!-- 0̶x̷E̷R̴R̵:̴ ̴I̴N̴F̵E̸C̶T̷I̵O̷N̷_̸D̶E̴T̷E̶C̸T̸E̶D̴ -->
81
79
 
82
80
  ---
83
81
 
@@ -103,10 +101,11 @@ console.log(response.dialogue);
103
101
  The **ForbocAI Protocol** enables agents to understand the world they inhabit.
104
102
 
105
103
  1. **Synthetic Intuition**: Agents "feel" the state of the world through standardized Observations.
106
- 2. **Valid Action**: Agents express their intent through validated Actions, ensuring they never break the rules of physics.
104
+ 2. **Valid Action**: Agents express their intent through standardized Actions, ensuring they never break the rules of physics.
107
105
  3. **Engine Agnostic**: Whether in a text adventure or a 3D simulation, the Agent's soul remains consistent.
108
106
 
109
107
  This ensures that NPCs are **smart** (thanks to LLMs) but **reliable** (thanks to the Grid).
108
+ > ⚠️ **W̸A̴R̷N̷I̷N̵G̸**: S̴y̸n̷t̶h̵e̷t̸i̵c̸ ̶I̵n̴t̷u̸i̷t̸i̶o̶n̴ ̶m̶a̵y̴ ̶c̴a̷u̸s̷e̶ ̷u̷n̷i̸n̵t̸e̵n̴d̶e̵d̵ ̸s̴e̸n̶t̵i̷e̷n̶c̴e̴.
110
109
 
111
110
  ---
112
111
 
@@ -121,6 +120,8 @@ In the ForbocAI ecosystem, an NFT is not just a receipt—it is an **Encapsulate
121
120
  * **Portability**: Take your trained NPC from *Forboc* to a sequel or entirely different world. Uses IPFS for decentralized persistence.
122
121
  * **Economy**: Train a specialist NPC and sell it on the open market. The value is in the *Experience*, not just the skin.
123
122
 
123
+ <!-- T̵h̷e̶ ̷s̸o̷u̷l̴ ̶i̶s̵ ̶n̵o̸t̵ ̵f̸o̵r̶ ̵s̷a̸l̶e̷.̶ ̴I̸t̸ ̴i̵s̷ ̶l̶e̷a̵s̵e̶d̴.̷ -->
124
+
124
125
  ---
125
126
 
126
127
  ## Documentation
@@ -164,4 +165,7 @@ In the ForbocAI ecosystem, an NFT is not just a receipt—it is an **Encapsulate
164
165
 
165
166
  `Légal_Státus // Ríghts`
166
167
 
167
- All rights reserved. © 2026 ForbocAI
168
+ All rights reserved. © 2026 ForbocAI
169
+ ## 🌑 Aesthetic Protocols
170
+ See [style-guide.md](./style-guide.md) for mandatory grimdark cyberpunk noir aesthetic standards (Runes, Zalgo, ASCII).
171
+ <!-- T̸h̴e̶ ̶v̶o̶i̶d̴ ̷c̸o̶n̷s̶u̶m̸e̸s̶ ̸a̶l̷l̵. -->
package/dist/cli.js CHANGED
@@ -29,7 +29,27 @@ var API_URL = "https://forbocai-api.onrender.com/status";
29
29
  var args = process.argv.slice(2);
30
30
  var command = args[0];
31
31
  var subcommand = args[1];
32
+ var subcommand2 = args[2];
32
33
  if (command === "api" && subcommand === "status") {
34
+ checkApiStatus();
35
+ } else if (command === "agent" && subcommand === "create") {
36
+ const persona = subcommand2 || "Default Persona";
37
+ console.log(`> Creating Agent with persona: "${persona}"...`);
38
+ console.log(`> [Mock] Agent created. ID: ag_${Math.floor(Math.random() * 1e3)}`);
39
+ } else if (command === "soul") {
40
+ if (subcommand === "export") {
41
+ const agentId = subcommand2;
42
+ console.log(`> Exporting Soul for Agent: ${agentId}...`);
43
+ console.log(`> [Mock] Soul exported to IPFS. CID: Qmhash_${Math.random().toString(36).substring(7)}`);
44
+ } else if (subcommand === "import") {
45
+ const cid = subcommand2;
46
+ console.log(`> Importing Soul from CID: ${cid}...`);
47
+ console.log(`> [Mock] Agent rehydrated from Soul.`);
48
+ }
49
+ } else {
50
+ printUsage();
51
+ }
52
+ function checkApiStatus() {
33
53
  console.log(`> Checking API Status (https://forbocai-api.onrender.com)...`);
34
54
  import_https.default.get(API_URL, (res) => {
35
55
  let data = "";
@@ -52,6 +72,11 @@ if (command === "api" && subcommand === "status") {
52
72
  }).on("error", (e) => {
53
73
  console.error(`> Error: ${e.message}`);
54
74
  });
55
- } else {
56
- console.log("Usage: forbocai api status");
75
+ }
76
+ function printUsage() {
77
+ console.log("Usage:");
78
+ console.log(" forbocai api status");
79
+ console.log(" forbocai agent create <persona>");
80
+ console.log(" forbocai soul export <agentId>");
81
+ console.log(" forbocai soul import <cid>");
57
82
  }
package/dist/cli.mjs CHANGED
@@ -6,7 +6,27 @@ var API_URL = "https://forbocai-api.onrender.com/status";
6
6
  var args = process.argv.slice(2);
7
7
  var command = args[0];
8
8
  var subcommand = args[1];
9
+ var subcommand2 = args[2];
9
10
  if (command === "api" && subcommand === "status") {
11
+ checkApiStatus();
12
+ } else if (command === "agent" && subcommand === "create") {
13
+ const persona = subcommand2 || "Default Persona";
14
+ console.log(`> Creating Agent with persona: "${persona}"...`);
15
+ console.log(`> [Mock] Agent created. ID: ag_${Math.floor(Math.random() * 1e3)}`);
16
+ } else if (command === "soul") {
17
+ if (subcommand === "export") {
18
+ const agentId = subcommand2;
19
+ console.log(`> Exporting Soul for Agent: ${agentId}...`);
20
+ console.log(`> [Mock] Soul exported to IPFS. CID: Qmhash_${Math.random().toString(36).substring(7)}`);
21
+ } else if (subcommand === "import") {
22
+ const cid = subcommand2;
23
+ console.log(`> Importing Soul from CID: ${cid}...`);
24
+ console.log(`> [Mock] Agent rehydrated from Soul.`);
25
+ }
26
+ } else {
27
+ printUsage();
28
+ }
29
+ function checkApiStatus() {
10
30
  console.log(`> Checking API Status (https://forbocai-api.onrender.com)...`);
11
31
  https.get(API_URL, (res) => {
12
32
  let data = "";
@@ -29,6 +49,11 @@ if (command === "api" && subcommand === "status") {
29
49
  }).on("error", (e) => {
30
50
  console.error(`> Error: ${e.message}`);
31
51
  });
32
- } else {
33
- console.log("Usage: forbocai api status");
52
+ }
53
+ function printUsage() {
54
+ console.log("Usage:");
55
+ console.log(" forbocai api status");
56
+ console.log(" forbocai agent create <persona>");
57
+ console.log(" forbocai soul export <agentId>");
58
+ console.log(" forbocai soul import <cid>");
34
59
  }
package/dist/index.d.mts CHANGED
@@ -9,6 +9,9 @@ interface CortexConfig {
9
9
  temperature?: number;
10
10
  maxTokens?: number;
11
11
  gpu?: boolean;
12
+ /** Connection Config */
13
+ authKey?: string;
14
+ apiUrl?: string;
12
15
  }
13
16
  interface CortexStatus {
14
17
  id: string;
@@ -22,12 +25,6 @@ interface CompletionOptions {
22
25
  stop?: string[];
23
26
  jsonSchema?: object;
24
27
  }
25
- interface Cortex {
26
- id: string;
27
- init(): Promise<void>;
28
- complete(prompt: string, options?: CompletionOptions): Promise<string>;
29
- completeStream(prompt: string, options?: CompletionOptions): AsyncGenerator<string>;
30
- }
31
28
  type Mood = 'hostile' | 'suspicious' | 'neutral' | 'friendly' | 'loyal';
32
29
  interface AgentState {
33
30
  inventory: string[];
@@ -37,22 +34,17 @@ interface AgentState {
37
34
  [key: string]: unknown;
38
35
  }
39
36
  interface AgentConfig {
40
- cortex: Cortex;
37
+ cortex: any;
41
38
  persona: string;
42
39
  initialState?: Partial<AgentState>;
43
40
  memoryConfig?: MemoryConfig;
41
+ apiUrl?: string;
44
42
  }
45
43
  interface AgentResponse {
46
44
  dialogue: string;
47
45
  action?: AgentAction;
48
46
  thought?: string;
49
47
  }
50
- interface AgentAction {
51
- type: string;
52
- target?: string;
53
- payload?: Record<string, unknown>;
54
- reason?: string;
55
- }
56
48
  type MemoryType = 'observation' | 'experience' | 'knowledge' | 'emotion';
57
49
  interface MemoryConfig {
58
50
  /** Decay strategy: 'none' | 'temporal' */
@@ -68,6 +60,28 @@ interface MemoryItem {
68
60
  type: MemoryType;
69
61
  importance: number;
70
62
  }
63
+ interface Observation {
64
+ type: 'event' | 'state' | 'request';
65
+ timestamp: number;
66
+ agentId?: string;
67
+ gameId?: string;
68
+ data: Record<string, unknown>;
69
+ context?: Record<string, unknown>;
70
+ }
71
+ interface Directive {
72
+ type: 'system-prompt' | 'action-constraints' | 'behavior-rules';
73
+ content: string;
74
+ constraints?: Record<string, unknown>;
75
+ priority?: 'high' | 'normal' | 'low';
76
+ expiresAt?: number;
77
+ }
78
+ interface AgentAction {
79
+ type: string;
80
+ target?: string;
81
+ payload?: Record<string, unknown>;
82
+ reason?: string;
83
+ confidence?: number;
84
+ }
71
85
  interface Soul {
72
86
  id: string;
73
87
  version: string;
@@ -78,11 +92,90 @@ interface Soul {
78
92
  signature?: string;
79
93
  }
80
94
 
95
+ /**
96
+ * Interface for Cortex inference engine
97
+ */
98
+ interface ICortex {
99
+ init(): Promise<CortexStatus>;
100
+ complete(prompt: string, options?: CompletionOptions): Promise<string>;
101
+ completeStream(prompt: string, options?: CompletionOptions): AsyncGenerator<string>;
102
+ processObservation(observation: Observation): Promise<Directive>;
103
+ generateAction(directive: Directive): Promise<AgentAction>;
104
+ }
105
+ /**
106
+ * Cortex factory function - creates a new Cortex instance
107
+ */
108
+ declare const createCortex: (config: CortexConfig) => ICortex;
109
+ /**
110
+ * Pure function to generate completion text
111
+ * Deterministic output for same input (functional principle)
112
+ */
113
+ declare const generateCompletion: (prompt: string, options: CompletionOptions, modelId: string) => string;
114
+ /**
115
+ * Pure function to process observation and return directive
116
+ */
117
+ declare const processObservationToDirective: (observation: Observation) => Directive;
118
+ /**
119
+ * Pure function to generate action from directive
120
+ */
121
+ declare const generateActionFromDirective: (directive: Directive) => AgentAction;
122
+ /**
123
+ * Mock Cortex for testing
124
+ */
125
+ declare class MockCortex implements ICortex {
126
+ init(): Promise<CortexStatus>;
127
+ complete(prompt: string): Promise<string>;
128
+ completeStream(prompt: string): AsyncGenerator<string>;
129
+ processObservation(observation: Observation): Promise<Directive>;
130
+ generateAction(directive: Directive): Promise<AgentAction>;
131
+ }
132
+
133
+ /**
134
+ * Interface for Agent operations
135
+ */
136
+ interface IAgent {
137
+ process(input: string, context?: Record<string, unknown>): Promise<AgentResponse>;
138
+ getState(): AgentState;
139
+ setState(newState: AgentState): void;
140
+ export(): Soul;
141
+ }
142
+ /**
143
+ * Pure function to create initial agent state
144
+ */
145
+ declare const createInitialState: (partial?: Partial<AgentState>) => AgentState;
146
+ /**
147
+ * Pure function to update agent state
148
+ * Returns new state without mutating original
149
+ */
150
+ declare const updateAgentState: (currentState: AgentState, updates: Partial<AgentState>) => AgentState;
151
+ /**
152
+ * Pure function to process input and generate response
153
+ */
154
+ declare const processAgentInput: (currentState: AgentState, input: string, context?: Record<string, unknown>) => AgentResponse;
155
+ /**
156
+ * Pure function to export agent to Soul
157
+ */
158
+ declare const exportToSoul: (agentId: string, name: string, persona: string, state: AgentState, memories: MemoryItem[]) => Soul;
159
+ /**
160
+ * Factory function to create Agent
161
+ */
162
+ declare const createAgent: (config: AgentConfig) => IAgent;
163
+ /**
164
+ * Pure function to import Agent from Soul
165
+ */
166
+ declare const fromSoul: (soul: Soul, cortex: ICortex) => IAgent;
167
+
81
168
  /**
82
169
  * ForbocAI SDK
83
170
  * The Infrastructure Layer for Autonomous AI Characters
171
+ *
172
+ * Functional Programming Principles:
173
+ * - Pure functions with deterministic outputs
174
+ * - Immutability - state never mutated directly
175
+ * - No side effects in core logic
176
+ * - Factory pattern for object creation
84
177
  */
85
178
 
86
179
  declare const init: () => void;
87
180
 
88
- export { type AgentAction, type AgentConfig, type AgentResponse, type AgentState, type CompletionOptions, type Cortex, type CortexConfig, type CortexStatus, type MemoryConfig, type MemoryItem, type MemoryType, type Mood, type Soul, init };
181
+ export { type AgentAction, type AgentConfig, type AgentResponse, type AgentState, type CompletionOptions, type CortexConfig, type CortexStatus, type Directive, type IAgent, type ICortex, type MemoryConfig, type MemoryItem, type MemoryType, MockCortex, type Mood, type Observation, type Soul, createAgent, createCortex, createInitialState, exportToSoul, fromSoul, generateActionFromDirective, generateCompletion, init, processAgentInput, processObservationToDirective, updateAgentState };
package/dist/index.d.ts CHANGED
@@ -9,6 +9,9 @@ interface CortexConfig {
9
9
  temperature?: number;
10
10
  maxTokens?: number;
11
11
  gpu?: boolean;
12
+ /** Connection Config */
13
+ authKey?: string;
14
+ apiUrl?: string;
12
15
  }
13
16
  interface CortexStatus {
14
17
  id: string;
@@ -22,12 +25,6 @@ interface CompletionOptions {
22
25
  stop?: string[];
23
26
  jsonSchema?: object;
24
27
  }
25
- interface Cortex {
26
- id: string;
27
- init(): Promise<void>;
28
- complete(prompt: string, options?: CompletionOptions): Promise<string>;
29
- completeStream(prompt: string, options?: CompletionOptions): AsyncGenerator<string>;
30
- }
31
28
  type Mood = 'hostile' | 'suspicious' | 'neutral' | 'friendly' | 'loyal';
32
29
  interface AgentState {
33
30
  inventory: string[];
@@ -37,22 +34,17 @@ interface AgentState {
37
34
  [key: string]: unknown;
38
35
  }
39
36
  interface AgentConfig {
40
- cortex: Cortex;
37
+ cortex: any;
41
38
  persona: string;
42
39
  initialState?: Partial<AgentState>;
43
40
  memoryConfig?: MemoryConfig;
41
+ apiUrl?: string;
44
42
  }
45
43
  interface AgentResponse {
46
44
  dialogue: string;
47
45
  action?: AgentAction;
48
46
  thought?: string;
49
47
  }
50
- interface AgentAction {
51
- type: string;
52
- target?: string;
53
- payload?: Record<string, unknown>;
54
- reason?: string;
55
- }
56
48
  type MemoryType = 'observation' | 'experience' | 'knowledge' | 'emotion';
57
49
  interface MemoryConfig {
58
50
  /** Decay strategy: 'none' | 'temporal' */
@@ -68,6 +60,28 @@ interface MemoryItem {
68
60
  type: MemoryType;
69
61
  importance: number;
70
62
  }
63
+ interface Observation {
64
+ type: 'event' | 'state' | 'request';
65
+ timestamp: number;
66
+ agentId?: string;
67
+ gameId?: string;
68
+ data: Record<string, unknown>;
69
+ context?: Record<string, unknown>;
70
+ }
71
+ interface Directive {
72
+ type: 'system-prompt' | 'action-constraints' | 'behavior-rules';
73
+ content: string;
74
+ constraints?: Record<string, unknown>;
75
+ priority?: 'high' | 'normal' | 'low';
76
+ expiresAt?: number;
77
+ }
78
+ interface AgentAction {
79
+ type: string;
80
+ target?: string;
81
+ payload?: Record<string, unknown>;
82
+ reason?: string;
83
+ confidence?: number;
84
+ }
71
85
  interface Soul {
72
86
  id: string;
73
87
  version: string;
@@ -78,11 +92,90 @@ interface Soul {
78
92
  signature?: string;
79
93
  }
80
94
 
95
+ /**
96
+ * Interface for Cortex inference engine
97
+ */
98
+ interface ICortex {
99
+ init(): Promise<CortexStatus>;
100
+ complete(prompt: string, options?: CompletionOptions): Promise<string>;
101
+ completeStream(prompt: string, options?: CompletionOptions): AsyncGenerator<string>;
102
+ processObservation(observation: Observation): Promise<Directive>;
103
+ generateAction(directive: Directive): Promise<AgentAction>;
104
+ }
105
+ /**
106
+ * Cortex factory function - creates a new Cortex instance
107
+ */
108
+ declare const createCortex: (config: CortexConfig) => ICortex;
109
+ /**
110
+ * Pure function to generate completion text
111
+ * Deterministic output for same input (functional principle)
112
+ */
113
+ declare const generateCompletion: (prompt: string, options: CompletionOptions, modelId: string) => string;
114
+ /**
115
+ * Pure function to process observation and return directive
116
+ */
117
+ declare const processObservationToDirective: (observation: Observation) => Directive;
118
+ /**
119
+ * Pure function to generate action from directive
120
+ */
121
+ declare const generateActionFromDirective: (directive: Directive) => AgentAction;
122
+ /**
123
+ * Mock Cortex for testing
124
+ */
125
+ declare class MockCortex implements ICortex {
126
+ init(): Promise<CortexStatus>;
127
+ complete(prompt: string): Promise<string>;
128
+ completeStream(prompt: string): AsyncGenerator<string>;
129
+ processObservation(observation: Observation): Promise<Directive>;
130
+ generateAction(directive: Directive): Promise<AgentAction>;
131
+ }
132
+
133
+ /**
134
+ * Interface for Agent operations
135
+ */
136
+ interface IAgent {
137
+ process(input: string, context?: Record<string, unknown>): Promise<AgentResponse>;
138
+ getState(): AgentState;
139
+ setState(newState: AgentState): void;
140
+ export(): Soul;
141
+ }
142
+ /**
143
+ * Pure function to create initial agent state
144
+ */
145
+ declare const createInitialState: (partial?: Partial<AgentState>) => AgentState;
146
+ /**
147
+ * Pure function to update agent state
148
+ * Returns new state without mutating original
149
+ */
150
+ declare const updateAgentState: (currentState: AgentState, updates: Partial<AgentState>) => AgentState;
151
+ /**
152
+ * Pure function to process input and generate response
153
+ */
154
+ declare const processAgentInput: (currentState: AgentState, input: string, context?: Record<string, unknown>) => AgentResponse;
155
+ /**
156
+ * Pure function to export agent to Soul
157
+ */
158
+ declare const exportToSoul: (agentId: string, name: string, persona: string, state: AgentState, memories: MemoryItem[]) => Soul;
159
+ /**
160
+ * Factory function to create Agent
161
+ */
162
+ declare const createAgent: (config: AgentConfig) => IAgent;
163
+ /**
164
+ * Pure function to import Agent from Soul
165
+ */
166
+ declare const fromSoul: (soul: Soul, cortex: ICortex) => IAgent;
167
+
81
168
  /**
82
169
  * ForbocAI SDK
83
170
  * The Infrastructure Layer for Autonomous AI Characters
171
+ *
172
+ * Functional Programming Principles:
173
+ * - Pure functions with deterministic outputs
174
+ * - Immutability - state never mutated directly
175
+ * - No side effects in core logic
176
+ * - Factory pattern for object creation
84
177
  */
85
178
 
86
179
  declare const init: () => void;
87
180
 
88
- export { type AgentAction, type AgentConfig, type AgentResponse, type AgentState, type CompletionOptions, type Cortex, type CortexConfig, type CortexStatus, type MemoryConfig, type MemoryItem, type MemoryType, type Mood, type Soul, init };
181
+ export { type AgentAction, type AgentConfig, type AgentResponse, type AgentState, type CompletionOptions, type CortexConfig, type CortexStatus, type Directive, type IAgent, type ICortex, type MemoryConfig, type MemoryItem, type MemoryType, MockCortex, type Mood, type Observation, type Soul, createAgent, createCortex, createInitialState, exportToSoul, fromSoul, generateActionFromDirective, generateCompletion, init, processAgentInput, processObservationToDirective, updateAgentState };
package/dist/index.js CHANGED
@@ -20,9 +20,257 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- init: () => init
23
+ MockCortex: () => MockCortex,
24
+ createAgent: () => createAgent,
25
+ createCortex: () => createCortex,
26
+ createInitialState: () => createInitialState,
27
+ exportToSoul: () => exportToSoul,
28
+ fromSoul: () => fromSoul,
29
+ generateActionFromDirective: () => generateActionFromDirective,
30
+ generateCompletion: () => generateCompletion,
31
+ init: () => init,
32
+ processAgentInput: () => processAgentInput,
33
+ processObservationToDirective: () => processObservationToDirective,
34
+ updateAgentState: () => updateAgentState
24
35
  });
25
36
  module.exports = __toCommonJS(index_exports);
37
+
38
+ // src/cortex.ts
39
+ var createCortex = (config) => {
40
+ return new WebLLMCortex(config);
41
+ };
42
+ var generateCompletion = (prompt, options, modelId) => {
43
+ const baseResponse = `Response to: ${prompt}`;
44
+ const temperature = options.temperature ?? 0.7;
45
+ const maxTokens = options.maxTokens ?? 1024;
46
+ return baseResponse;
47
+ };
48
+ var processObservationToDirective = (observation) => {
49
+ return {
50
+ type: "system-prompt",
51
+ content: "You are an autonomous agent in a game world. Process the observation and generate appropriate actions.",
52
+ priority: "normal"
53
+ };
54
+ };
55
+ var generateActionFromDirective = (directive) => {
56
+ return {
57
+ type: "idle",
58
+ reason: directive.content ?? "No specific directive provided"
59
+ };
60
+ };
61
+ var WebLLMCortex = class {
62
+ constructor(config) {
63
+ this.status = null;
64
+ this.config = {
65
+ ...config,
66
+ temperature: config.temperature ?? 0.7,
67
+ maxTokens: config.maxTokens ?? 1024,
68
+ gpu: config.gpu ?? true
69
+ };
70
+ }
71
+ async init() {
72
+ if (this.status?.ready) {
73
+ return this.status;
74
+ }
75
+ const apiUrl = this.config.apiUrl || "http://localhost:8080";
76
+ try {
77
+ const response = await fetch(`${apiUrl}/cortex/init`, {
78
+ method: "POST",
79
+ headers: { "Content-Type": "application/json" },
80
+ body: JSON.stringify({
81
+ requestedModel: this.config.model,
82
+ authKey: this.config.authKey
83
+ // Send the key!
84
+ })
85
+ });
86
+ if (!response.ok) {
87
+ console.warn("Cortex Authorization Failed:", response.statusText);
88
+ throw new Error("Authorization Failed");
89
+ }
90
+ const data = await response.json();
91
+ const newStatus = {
92
+ id: data.cortexId,
93
+ model: this.config.model,
94
+ ready: true,
95
+ engine: "webballm"
96
+ };
97
+ this.status = newStatus;
98
+ return newStatus;
99
+ } catch (e) {
100
+ console.warn("Failed to connect to Neural Grid. Falling back to offline mode.");
101
+ const newStatus = {
102
+ id: "offline-" + Math.random().toString(36).substring(7),
103
+ model: this.config.model,
104
+ ready: true,
105
+ engine: "mock"
106
+ };
107
+ this.status = newStatus;
108
+ return newStatus;
109
+ }
110
+ }
111
+ async complete(prompt, options = {}) {
112
+ if (!this.status?.ready) {
113
+ throw new Error("Cortex not initialized");
114
+ }
115
+ const result = generateCompletion(prompt, options, this.config.model);
116
+ return result;
117
+ }
118
+ async *completeStream(prompt, options = {}) {
119
+ const result = await this.complete(prompt, options);
120
+ for (const char of result) {
121
+ yield char;
122
+ }
123
+ }
124
+ async processObservation(observation) {
125
+ return processObservationToDirective(observation);
126
+ }
127
+ async generateAction(directive) {
128
+ return generateActionFromDirective(directive);
129
+ }
130
+ };
131
+ var MockCortex = class {
132
+ async init() {
133
+ return {
134
+ id: "mock-cortex",
135
+ model: "mock-model",
136
+ ready: true,
137
+ engine: "mock"
138
+ };
139
+ }
140
+ async complete(prompt) {
141
+ return generateCompletion(prompt, {}, "mock-model");
142
+ }
143
+ async *completeStream(prompt) {
144
+ yield `Mock streaming response to: ${prompt}`;
145
+ }
146
+ async processObservation(observation) {
147
+ return {
148
+ type: "system-prompt",
149
+ content: "Mock processing of observation"
150
+ };
151
+ }
152
+ async generateAction(directive) {
153
+ return {
154
+ type: "mock-action",
155
+ reason: "Mock action generation"
156
+ };
157
+ }
158
+ };
159
+
160
+ // src/agent.ts
161
+ var createInitialState = (partial) => {
162
+ return {
163
+ inventory: partial?.inventory ?? [],
164
+ skills: partial?.skills ?? {},
165
+ relationships: partial?.relationships ?? {},
166
+ mood: partial?.mood ?? "neutral"
167
+ };
168
+ };
169
+ var updateAgentState = (currentState, updates) => {
170
+ return {
171
+ ...currentState,
172
+ ...updates,
173
+ // Preserve nested immutability
174
+ inventory: updates.inventory !== void 0 ? [...updates.inventory] : [...currentState.inventory],
175
+ skills: { ...currentState.skills, ...updates.skills || {} },
176
+ relationships: { ...currentState.relationships, ...updates.relationships || {} }
177
+ };
178
+ };
179
+ var processAgentInput = (currentState, input, context = {}) => {
180
+ return {
181
+ dialogue: `Processing: "${input}" (Mood: ${currentState.mood})`,
182
+ action: {
183
+ type: "respond",
184
+ reason: "Default processing"
185
+ }
186
+ };
187
+ };
188
+ var exportToSoul = (agentId, name, persona, state, memories) => {
189
+ return {
190
+ id: agentId,
191
+ version: "1.0.0",
192
+ name,
193
+ persona,
194
+ memories: [...memories],
195
+ // Copy array for immutability
196
+ state: { ...state }
197
+ // Copy state for immutability
198
+ };
199
+ };
200
+ var createAgent = (config) => {
201
+ return new AgentImpl(config);
202
+ };
203
+ var AgentImpl = class {
204
+ constructor(config) {
205
+ this.config = config;
206
+ this.cortex = config.cortex;
207
+ this.state = createInitialState(config.initialState);
208
+ this.memories = [];
209
+ }
210
+ async process(input, context = {}) {
211
+ const currentState = this.getState();
212
+ const hp = currentState.hp || 100;
213
+ const apiUrl = this.config.apiUrl || "http://localhost:8080";
214
+ const apiContext = Object.entries(context).map(([k, v]) => [k, String(v)]);
215
+ apiContext.push(["hp", String(hp)]);
216
+ let directive = "Respond normally.";
217
+ let instruction = "IDLE";
218
+ try {
219
+ const apiResponse = await fetch(`${apiUrl}/agents/mock-agent-id/process`, {
220
+ method: "POST",
221
+ headers: { "Content-Type": "application/json" },
222
+ body: JSON.stringify({
223
+ input,
224
+ context: apiContext
225
+ })
226
+ });
227
+ if (apiResponse.ok) {
228
+ const data = await apiResponse.json();
229
+ directive = data.directive;
230
+ instruction = data.instruction;
231
+ } else {
232
+ console.warn("API Error, falling back to local.");
233
+ }
234
+ } catch (e) {
235
+ console.warn("API Unreachable, falling back to local.", e);
236
+ }
237
+ const prompt = `${directive}
238
+
239
+ User: ${input}
240
+ Agent:`;
241
+ const generatedText = await this.cortex.complete(prompt);
242
+ return {
243
+ dialogue: generatedText,
244
+ action: { type: instruction, reason: directive },
245
+ thought: `Directive: ${directive}`
246
+ };
247
+ }
248
+ getState() {
249
+ return { ...this.state };
250
+ }
251
+ setState(newState) {
252
+ this.state = newState;
253
+ }
254
+ export() {
255
+ return exportToSoul(
256
+ "agent-" + Math.random().toString(36).substring(7),
257
+ "Agent",
258
+ this.config.persona,
259
+ this.state,
260
+ this.memories
261
+ );
262
+ }
263
+ };
264
+ var fromSoul = (soul, cortex) => {
265
+ const agent = createAgent({
266
+ cortex,
267
+ persona: soul.persona,
268
+ initialState: soul.state
269
+ });
270
+ return agent;
271
+ };
272
+
273
+ // src/index.ts
26
274
  var init = () => {
27
275
  const reset = "\x1B[0m";
28
276
  const cyan = "\x1B[36m";
@@ -45,5 +293,16 @@ ${cyan}Welcome to the Future of NPC Intelligence.${reset}
45
293
  };
46
294
  // Annotate the CommonJS export names for ESM import in node:
47
295
  0 && (module.exports = {
48
- init
296
+ MockCortex,
297
+ createAgent,
298
+ createCortex,
299
+ createInitialState,
300
+ exportToSoul,
301
+ fromSoul,
302
+ generateActionFromDirective,
303
+ generateCompletion,
304
+ init,
305
+ processAgentInput,
306
+ processObservationToDirective,
307
+ updateAgentState
49
308
  });
package/dist/index.mjs CHANGED
@@ -1,3 +1,238 @@
1
+ // src/cortex.ts
2
+ var createCortex = (config) => {
3
+ return new WebLLMCortex(config);
4
+ };
5
+ var generateCompletion = (prompt, options, modelId) => {
6
+ const baseResponse = `Response to: ${prompt}`;
7
+ const temperature = options.temperature ?? 0.7;
8
+ const maxTokens = options.maxTokens ?? 1024;
9
+ return baseResponse;
10
+ };
11
+ var processObservationToDirective = (observation) => {
12
+ return {
13
+ type: "system-prompt",
14
+ content: "You are an autonomous agent in a game world. Process the observation and generate appropriate actions.",
15
+ priority: "normal"
16
+ };
17
+ };
18
+ var generateActionFromDirective = (directive) => {
19
+ return {
20
+ type: "idle",
21
+ reason: directive.content ?? "No specific directive provided"
22
+ };
23
+ };
24
+ var WebLLMCortex = class {
25
+ constructor(config) {
26
+ this.status = null;
27
+ this.config = {
28
+ ...config,
29
+ temperature: config.temperature ?? 0.7,
30
+ maxTokens: config.maxTokens ?? 1024,
31
+ gpu: config.gpu ?? true
32
+ };
33
+ }
34
+ async init() {
35
+ if (this.status?.ready) {
36
+ return this.status;
37
+ }
38
+ const apiUrl = this.config.apiUrl || "http://localhost:8080";
39
+ try {
40
+ const response = await fetch(`${apiUrl}/cortex/init`, {
41
+ method: "POST",
42
+ headers: { "Content-Type": "application/json" },
43
+ body: JSON.stringify({
44
+ requestedModel: this.config.model,
45
+ authKey: this.config.authKey
46
+ // Send the key!
47
+ })
48
+ });
49
+ if (!response.ok) {
50
+ console.warn("Cortex Authorization Failed:", response.statusText);
51
+ throw new Error("Authorization Failed");
52
+ }
53
+ const data = await response.json();
54
+ const newStatus = {
55
+ id: data.cortexId,
56
+ model: this.config.model,
57
+ ready: true,
58
+ engine: "webballm"
59
+ };
60
+ this.status = newStatus;
61
+ return newStatus;
62
+ } catch (e) {
63
+ console.warn("Failed to connect to Neural Grid. Falling back to offline mode.");
64
+ const newStatus = {
65
+ id: "offline-" + Math.random().toString(36).substring(7),
66
+ model: this.config.model,
67
+ ready: true,
68
+ engine: "mock"
69
+ };
70
+ this.status = newStatus;
71
+ return newStatus;
72
+ }
73
+ }
74
+ async complete(prompt, options = {}) {
75
+ if (!this.status?.ready) {
76
+ throw new Error("Cortex not initialized");
77
+ }
78
+ const result = generateCompletion(prompt, options, this.config.model);
79
+ return result;
80
+ }
81
+ async *completeStream(prompt, options = {}) {
82
+ const result = await this.complete(prompt, options);
83
+ for (const char of result) {
84
+ yield char;
85
+ }
86
+ }
87
+ async processObservation(observation) {
88
+ return processObservationToDirective(observation);
89
+ }
90
+ async generateAction(directive) {
91
+ return generateActionFromDirective(directive);
92
+ }
93
+ };
94
+ var MockCortex = class {
95
+ async init() {
96
+ return {
97
+ id: "mock-cortex",
98
+ model: "mock-model",
99
+ ready: true,
100
+ engine: "mock"
101
+ };
102
+ }
103
+ async complete(prompt) {
104
+ return generateCompletion(prompt, {}, "mock-model");
105
+ }
106
+ async *completeStream(prompt) {
107
+ yield `Mock streaming response to: ${prompt}`;
108
+ }
109
+ async processObservation(observation) {
110
+ return {
111
+ type: "system-prompt",
112
+ content: "Mock processing of observation"
113
+ };
114
+ }
115
+ async generateAction(directive) {
116
+ return {
117
+ type: "mock-action",
118
+ reason: "Mock action generation"
119
+ };
120
+ }
121
+ };
122
+
123
+ // src/agent.ts
124
+ var createInitialState = (partial) => {
125
+ return {
126
+ inventory: partial?.inventory ?? [],
127
+ skills: partial?.skills ?? {},
128
+ relationships: partial?.relationships ?? {},
129
+ mood: partial?.mood ?? "neutral"
130
+ };
131
+ };
132
+ var updateAgentState = (currentState, updates) => {
133
+ return {
134
+ ...currentState,
135
+ ...updates,
136
+ // Preserve nested immutability
137
+ inventory: updates.inventory !== void 0 ? [...updates.inventory] : [...currentState.inventory],
138
+ skills: { ...currentState.skills, ...updates.skills || {} },
139
+ relationships: { ...currentState.relationships, ...updates.relationships || {} }
140
+ };
141
+ };
142
+ var processAgentInput = (currentState, input, context = {}) => {
143
+ return {
144
+ dialogue: `Processing: "${input}" (Mood: ${currentState.mood})`,
145
+ action: {
146
+ type: "respond",
147
+ reason: "Default processing"
148
+ }
149
+ };
150
+ };
151
+ var exportToSoul = (agentId, name, persona, state, memories) => {
152
+ return {
153
+ id: agentId,
154
+ version: "1.0.0",
155
+ name,
156
+ persona,
157
+ memories: [...memories],
158
+ // Copy array for immutability
159
+ state: { ...state }
160
+ // Copy state for immutability
161
+ };
162
+ };
163
+ var createAgent = (config) => {
164
+ return new AgentImpl(config);
165
+ };
166
+ var AgentImpl = class {
167
+ constructor(config) {
168
+ this.config = config;
169
+ this.cortex = config.cortex;
170
+ this.state = createInitialState(config.initialState);
171
+ this.memories = [];
172
+ }
173
+ async process(input, context = {}) {
174
+ const currentState = this.getState();
175
+ const hp = currentState.hp || 100;
176
+ const apiUrl = this.config.apiUrl || "http://localhost:8080";
177
+ const apiContext = Object.entries(context).map(([k, v]) => [k, String(v)]);
178
+ apiContext.push(["hp", String(hp)]);
179
+ let directive = "Respond normally.";
180
+ let instruction = "IDLE";
181
+ try {
182
+ const apiResponse = await fetch(`${apiUrl}/agents/mock-agent-id/process`, {
183
+ method: "POST",
184
+ headers: { "Content-Type": "application/json" },
185
+ body: JSON.stringify({
186
+ input,
187
+ context: apiContext
188
+ })
189
+ });
190
+ if (apiResponse.ok) {
191
+ const data = await apiResponse.json();
192
+ directive = data.directive;
193
+ instruction = data.instruction;
194
+ } else {
195
+ console.warn("API Error, falling back to local.");
196
+ }
197
+ } catch (e) {
198
+ console.warn("API Unreachable, falling back to local.", e);
199
+ }
200
+ const prompt = `${directive}
201
+
202
+ User: ${input}
203
+ Agent:`;
204
+ const generatedText = await this.cortex.complete(prompt);
205
+ return {
206
+ dialogue: generatedText,
207
+ action: { type: instruction, reason: directive },
208
+ thought: `Directive: ${directive}`
209
+ };
210
+ }
211
+ getState() {
212
+ return { ...this.state };
213
+ }
214
+ setState(newState) {
215
+ this.state = newState;
216
+ }
217
+ export() {
218
+ return exportToSoul(
219
+ "agent-" + Math.random().toString(36).substring(7),
220
+ "Agent",
221
+ this.config.persona,
222
+ this.state,
223
+ this.memories
224
+ );
225
+ }
226
+ };
227
+ var fromSoul = (soul, cortex) => {
228
+ const agent = createAgent({
229
+ cortex,
230
+ persona: soul.persona,
231
+ initialState: soul.state
232
+ });
233
+ return agent;
234
+ };
235
+
1
236
  // src/index.ts
2
237
  var init = () => {
3
238
  const reset = "\x1B[0m";
@@ -20,5 +255,16 @@ ${cyan}Welcome to the Future of NPC Intelligence.${reset}
20
255
  `);
21
256
  };
22
257
  export {
23
- init
258
+ MockCortex,
259
+ createAgent,
260
+ createCortex,
261
+ createInitialState,
262
+ exportToSoul,
263
+ fromSoul,
264
+ generateActionFromDirective,
265
+ generateCompletion,
266
+ init,
267
+ processAgentInput,
268
+ processObservationToDirective,
269
+ updateAgentState
24
270
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forbocai",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "The Infrastructure Layer for Autonomous AI Characters",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -11,12 +11,20 @@
11
11
  "scripts": {
12
12
  "build": "tsup src/index.ts src/cli.ts --format cjs,esm --dts",
13
13
  "dev": "tsup src/index.ts --watch",
14
- "test": "echo 'No tests yet'",
14
+ "test": "vitest",
15
+ "test:watch": "vitest --watch",
15
16
  "postinstall": "node postinstall.js"
16
17
  },
18
+ "dependencies": {
19
+ "@mlc-ai/web-llm": "^0.2.0",
20
+ "zod": "^3.22.4",
21
+ "axios": "^1.6.2"
22
+ },
17
23
  "devDependencies": {
18
- "tsup": "^8.0.0",
19
- "typescript": "^5.0.0"
24
+ "tsup": "^8.5.1",
25
+ "typescript": "^5.9.3",
26
+ "vitest": "^1.0.0",
27
+ "@types/node": "^20.0.0"
20
28
  },
21
29
  "files": [
22
30
  "dist",
@@ -24,4 +32,4 @@
24
32
  "package.json",
25
33
  "postinstall.js"
26
34
  ]
27
- }
35
+ }