forbocai 0.2.0 → 0.3.2

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
@@ -17,7 +17,14 @@ interface CortexStatus {
17
17
  id: string;
18
18
  model: string;
19
19
  ready: boolean;
20
- engine: 'webballm' | 'mock' | 'remote';
20
+ engine: 'webllm' | 'mock' | 'remote' | 'node-llama-cpp';
21
+ }
22
+ interface ICortex {
23
+ init(): Promise<CortexStatus>;
24
+ complete(prompt: string, options?: CompletionOptions): Promise<string>;
25
+ completeStream(prompt: string, options?: CompletionOptions): AsyncGenerator<string>;
26
+ processObservation(observation: Observation): Promise<Directive>;
27
+ generateAction(directive: Directive): Promise<AgentAction>;
21
28
  }
22
29
  interface CompletionOptions {
23
30
  temperature?: number;
@@ -34,7 +41,9 @@ interface AgentState {
34
41
  [key: string]: unknown;
35
42
  }
36
43
  interface AgentConfig {
37
- cortex: any;
44
+ id: string;
45
+ cortex: ICortex;
46
+ memory: any;
38
47
  persona: string;
39
48
  initialState?: Partial<AgentState>;
40
49
  memoryConfig?: MemoryConfig;
@@ -65,11 +74,12 @@ interface Observation {
65
74
  timestamp: number;
66
75
  agentId?: string;
67
76
  gameId?: string;
68
- data: Record<string, unknown>;
77
+ content: string;
78
+ data?: Record<string, unknown>;
69
79
  context?: Record<string, unknown>;
70
80
  }
71
81
  interface Directive {
72
- type: 'system-prompt' | 'action-constraints' | 'behavior-rules';
82
+ type: 'system-prompt' | 'action-constraints' | 'behavior-rules' | 'thought';
73
83
  content: string;
74
84
  constraints?: Record<string, unknown>;
75
85
  priority?: 'high' | 'normal' | 'low';
@@ -92,43 +102,9 @@ interface Soul {
92
102
  signature?: string;
93
103
  }
94
104
 
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
- }
105
+ declare const createCortex: (config: CortexConfig) => ICortex & {
106
+ embed: (text: string) => Promise<number[]>;
107
+ };
132
108
 
133
109
  /**
134
110
  * Interface for Agent operations
@@ -157,70 +133,123 @@ declare const processAgentInput: (currentState: AgentState, input: string, conte
157
133
  */
158
134
  declare const exportToSoul: (agentId: string, name: string, persona: string, state: AgentState, memories: MemoryItem[]) => Soul;
159
135
  /**
160
- * Factory function to create Agent
136
+ * Factory function to create Agent (Functional/Closure based)
161
137
  */
162
138
  declare const createAgent: (config: AgentConfig) => IAgent;
163
139
  /**
164
140
  * Pure function to import Agent from Soul
165
141
  */
166
- declare const fromSoul: (soul: Soul, cortex: ICortex) => IAgent;
142
+ declare const fromSoul: (soul: Soul, cortex: ICortex, memory?: any) => IAgent;
167
143
 
168
144
  /**
169
- * Interface for Memory operations (Local Vector DB)
145
+ * Soul export configuration
170
146
  */
171
- interface IMemory {
172
- store(text: string, type?: MemoryType, importance?: number): Promise<MemoryItem>;
173
- recall(query: string, limit?: number): Promise<MemoryItem[]>;
174
- list(limit?: number, offset?: number): Promise<MemoryItem[]>;
175
- clear(): Promise<void>;
176
- export(): MemoryItem[];
177
- import(memories: MemoryItem[]): Promise<void>;
147
+ interface SoulExportConfig {
148
+ /** API URL for IPFS pinning */
149
+ apiUrl?: string;
150
+ /** Include memories in export */
151
+ includeMemories?: boolean;
152
+ /** Sign with wallet (for NFT minting) */
153
+ sign?: boolean;
154
+ /** Use local IPFS node (Helia) */
155
+ useLocalNode?: boolean;
178
156
  }
179
157
  /**
180
- * Configuration for the memory module
158
+ * Soul export result
181
159
  */
182
- interface MemoryModuleConfig extends MemoryConfig {
183
- /** Storage key for IndexedDB persistence */
184
- storageKey?: string;
185
- /** API URL for optional cloud sync */
160
+ interface SoulExportResult {
161
+ cid: string;
162
+ ipfsUrl: string;
163
+ signature?: string;
164
+ soul: Soul;
165
+ }
166
+ /**
167
+ * Soul import configuration
168
+ */
169
+ interface SoulImportConfig {
170
+ /** API URL for IPFS retrieval */
186
171
  apiUrl?: string;
187
- /** Agent ID for API calls */
188
- agentId?: string;
172
+ /** Verify signature before import */
173
+ verifySignature?: boolean;
174
+ /** Use local IPFS node (Helia) */
175
+ useLocalNode?: boolean;
189
176
  }
190
177
  /**
191
- * Pure function to create a new memory item
178
+ * Interface for Soul operations
192
179
  */
193
- declare const createMemoryItem: (text: string, type?: MemoryType, importance?: number) => MemoryItem;
180
+ interface ISoul {
181
+ export(config?: SoulExportConfig): Promise<SoulExportResult>;
182
+ toJSON(): Soul;
183
+ }
194
184
  /**
195
- * Pure function to calculate temporal decay
196
- * Older memories become less important over time
185
+ * Pure function to create a Soul from agent data
197
186
  */
198
- declare const applyTemporalDecay: (memory: MemoryItem, currentTime: number, decayRate?: number) => MemoryItem;
187
+ declare const createSoul: (id: string, name: string, persona: string, state: AgentState, memories?: MemoryItem[]) => Soul;
199
188
  /**
200
- * Pure function to compute simple text similarity (cosine-like)
201
- * In production, this would use actual embeddings
189
+ * Pure function to serialize Soul to JSON string
202
190
  */
203
- declare const computeSimilarity: (text1: string, text2: string) => number;
191
+ declare const serializeSoul: (soul: Soul) => string;
204
192
  /**
205
- * Pure function to rank memories by relevance
193
+ * Pure function to deserialize Soul from JSON string
206
194
  */
207
- declare const rankMemoriesByRelevance: (memories: readonly MemoryItem[], query: string, limit?: number) => MemoryItem[];
195
+ declare const deserializeSoul: (json: string) => Soul;
208
196
  /**
209
- * Factory function to create Memory instance
197
+ * Pure function to validate Soul schema
210
198
  */
211
- declare const createMemory: (config?: MemoryModuleConfig) => IMemory;
199
+ declare const validateSoul: (soul: Soul) => {
200
+ valid: boolean;
201
+ errors: string[];
202
+ };
203
+ /**
204
+ * Export agent Soul to IPFS (Helia or API)
205
+ */
206
+ declare const exportSoulToIPFS: (agentId: string, soul: Soul, config?: SoulExportConfig) => Promise<SoulExportResult>;
207
+ /**
208
+ * Import Soul from IPFS by CID (Helia or API)
209
+ */
210
+ declare const importSoulFromIPFS: (cid: string, config?: SoulImportConfig) => Promise<Soul>;
211
+ /**
212
+ * Soul entry in the listing
213
+ */
214
+ interface SoulListEntry {
215
+ cid: string;
216
+ name: string;
217
+ agentId?: string;
218
+ exportedAt: string;
219
+ ipfsUrl: string;
220
+ }
212
221
  /**
213
- * Mock Memory for testing
222
+ * Get list of all exported Souls
214
223
  */
215
- declare class MockMemory implements IMemory {
216
- private memories;
224
+ declare const getSoulList: (limit?: number, apiUrl?: string) => Promise<SoulListEntry[]>;
225
+ /**
226
+ * Create agent from imported Soul via API
227
+ */
228
+ declare const createAgentFromSoul: (cid: string, cortexId: string, config?: SoulImportConfig) => Promise<{
229
+ agentId: string;
230
+ persona: string;
231
+ }>;
232
+ /**
233
+ * Factory function to create Soul instance (Functional/Closure based)
234
+ */
235
+ declare const createSoulInstance: (id: string, name: string, persona: string, state: AgentState, memories?: MemoryItem[], initialApiUrl?: string) => ISoul;
236
+
237
+ /**
238
+ * Interface
239
+ */
240
+ interface IMemory {
217
241
  store(text: string, type?: MemoryType, importance?: number): Promise<MemoryItem>;
218
242
  recall(query: string, limit?: number): Promise<MemoryItem[]>;
219
243
  list(limit?: number, offset?: number): Promise<MemoryItem[]>;
220
244
  clear(): Promise<void>;
221
- export(): MemoryItem[];
222
- import(memories: MemoryItem[]): Promise<void>;
223
245
  }
246
+ interface MemoryModuleConfig extends MemoryConfig {
247
+ storageKey?: string;
248
+ apiUrl?: string;
249
+ agentId?: string;
250
+ }
251
+ declare const createMemoryItem: (text: string, type?: MemoryType, importance?: number) => MemoryItem;
252
+ declare const createMemory: (config?: MemoryModuleConfig) => IMemory;
224
253
 
225
254
  /**
226
255
  * Validation rule definition
@@ -286,108 +315,14 @@ declare const speakRule: ValidationRule;
286
315
  */
287
316
  declare const resourceRule: ValidationRule;
288
317
  /**
289
- * Factory function to create Bridge instance
318
+ * Factory function to create Bridge instance (Functional/Closure based)
290
319
  */
291
320
  declare const createBridge: (config?: BridgeConfig) => IBridge;
292
- /**
293
- * Mock Bridge for testing
294
- */
295
- declare class MockBridge implements IBridge {
296
- validate(action: AgentAction): Promise<ValidationResult>;
297
- registerRule(_rule: ValidationRule): void;
298
- listRules(): ValidationRule[];
299
- removeRule(_ruleId: string): boolean;
300
- }
301
321
  /**
302
322
  * Pure function to validate action (standalone, no class needed)
303
323
  */
304
324
  declare const validateAction: (action: AgentAction, rules: readonly ValidationRule[], context?: ValidationContext) => ValidationResult;
305
325
 
306
- /**
307
- * Soul export configuration
308
- */
309
- interface SoulExportConfig {
310
- /** API URL for IPFS pinning */
311
- apiUrl?: string;
312
- /** Include memories in export */
313
- includeMemories?: boolean;
314
- /** Sign with wallet (for NFT minting) */
315
- sign?: boolean;
316
- }
317
- /**
318
- * Soul export result
319
- */
320
- interface SoulExportResult {
321
- cid: string;
322
- ipfsUrl: string;
323
- signature?: string;
324
- soul: Soul;
325
- }
326
- /**
327
- * Soul import configuration
328
- */
329
- interface SoulImportConfig {
330
- /** API URL for IPFS retrieval */
331
- apiUrl?: string;
332
- /** Verify signature before import */
333
- verifySignature?: boolean;
334
- }
335
- /**
336
- * Interface for Soul operations
337
- */
338
- interface ISoul {
339
- export(config?: SoulExportConfig): Promise<SoulExportResult>;
340
- toJSON(): Soul;
341
- }
342
- /**
343
- * Pure function to create a Soul from agent data
344
- */
345
- declare const createSoul: (id: string, name: string, persona: string, state: AgentState, memories?: MemoryItem[]) => Soul;
346
- /**
347
- * Pure function to serialize Soul to JSON string
348
- */
349
- declare const serializeSoul: (soul: Soul) => string;
350
- /**
351
- * Pure function to deserialize Soul from JSON string
352
- */
353
- declare const deserializeSoul: (json: string) => Soul;
354
- /**
355
- * Pure function to validate Soul schema
356
- */
357
- declare const validateSoul: (soul: Soul) => {
358
- valid: boolean;
359
- errors: string[];
360
- };
361
- /**
362
- * Export agent Soul to IPFS via API
363
- */
364
- declare const exportSoulToIPFS: (agentId: string, soul: Soul, config?: SoulExportConfig) => Promise<SoulExportResult>;
365
- /**
366
- * Import Soul from IPFS by CID
367
- */
368
- declare const importSoulFromIPFS: (cid: string, config?: SoulImportConfig) => Promise<Soul>;
369
- /**
370
- * Create agent from imported Soul via API
371
- */
372
- declare const createAgentFromSoul: (cid: string, cortexId: string, config?: SoulImportConfig) => Promise<{
373
- agentId: string;
374
- persona: string;
375
- }>;
376
- /**
377
- * Soul class for object-oriented usage
378
- */
379
- declare class SoulImpl implements ISoul {
380
- private soul;
381
- private apiUrl;
382
- constructor(id: string, name: string, persona: string, state: AgentState, memories?: MemoryItem[], apiUrl?: string);
383
- export(config?: SoulExportConfig): Promise<SoulExportResult>;
384
- toJSON(): Soul;
385
- }
386
- /**
387
- * Factory function to create Soul instance
388
- */
389
- declare const createSoulInstance: (id: string, name: string, persona: string, state: AgentState, memories?: MemoryItem[], apiUrl?: string) => ISoul;
390
-
391
326
  /**
392
327
  * Ghost test configuration
393
328
  */
@@ -467,35 +402,38 @@ declare const getGhostResults: (sessionId: string, apiUrl?: string) => Promise<G
467
402
  */
468
403
  declare const waitForGhostCompletion: (sessionId: string, pollIntervalMs?: number, timeoutMs?: number, apiUrl?: string, onProgress?: (status: GhostStatus) => void) => Promise<GhostResults>;
469
404
  /**
470
- * Ghost class for object-oriented usage
405
+ * Stop a running Ghost session
471
406
  */
472
- declare class GhostSession implements IGhost {
473
- private config;
474
- private sessionId;
475
- private apiUrl;
476
- constructor(config: GhostConfig);
477
- run(): Promise<string>;
478
- status(): Promise<GhostStatus>;
479
- results(): Promise<GhostResults>;
480
- stop(): Promise<void>;
481
- waitForCompletion(pollIntervalMs?: number, timeoutMs?: number, onProgress?: (status: GhostStatus) => void): Promise<GhostResults>;
407
+ declare const stopGhostSession: (sessionId: string, apiUrl?: string) => Promise<{
408
+ stopped: boolean;
409
+ status: string;
410
+ }>;
411
+ /**
412
+ * Get Ghost session history
413
+ */
414
+ interface GhostHistoryEntry {
415
+ sessionId: string;
416
+ testSuite: string;
417
+ startedAt: string;
418
+ completedAt?: string;
419
+ status: string;
420
+ passRate: number;
482
421
  }
422
+ declare const getGhostHistory: (limit?: number, apiUrl?: string) => Promise<GhostHistoryEntry[]>;
483
423
  /**
484
- * Factory function to create Ghost session
424
+ * Factory function to create Ghost session (Functional/Closure based)
485
425
  */
486
426
  declare const createGhost: (config: GhostConfig) => IGhost;
487
427
 
488
- /**
489
- * ForbocAI SDK
490
- * The Infrastructure Layer for Autonomous AI Characters
491
- *
492
- * Functional Programming Principles:
493
- * - Pure functions with deterministic outputs
494
- * - Immutability - state never mutated directly
495
- * - No side effects in core logic
496
- * - Factory pattern for object creation
497
- */
428
+ interface VectorStatus {
429
+ ready: boolean;
430
+ backend: 'lancedb' | 'memory';
431
+ }
432
+ declare const initVectorEngine: () => Promise<void>;
433
+ declare const generateEmbedding: (text: string) => Promise<number[]>;
434
+ declare const getVectorTable: (dbPath: string, tableName?: string) => Promise<any>;
435
+ declare const createTable: (dbPath: string, tableName: string, data: any[]) => Promise<any>;
498
436
 
499
437
  declare const init: () => void;
500
438
 
501
- export { type AgentAction, type AgentConfig, type AgentResponse, type AgentState, type BridgeConfig, type CompletionOptions, type CortexConfig, type CortexStatus, type Directive, type GhostConfig, type GhostResults, GhostSession, type GhostStatus, type GhostTestResult, type IAgent, type IBridge, type ICortex, type IGhost, type IMemory, type ISoul, type MemoryConfig, type MemoryItem, type MemoryModuleConfig, type MemoryType, MockBridge, MockCortex, MockMemory, type Mood, type Observation, type Soul, type SoulExportConfig, type SoulExportResult, SoulImpl, type SoulImportConfig, type ValidationContext, type ValidationResult, type ValidationRule, applyTemporalDecay, attackRule, computeSimilarity, createAgent, createAgentFromSoul, createBridge, createCortex, createGhost, createInitialState, createMemory, createMemoryItem, createSoul, createSoulInstance, deserializeSoul, exportSoulToIPFS, exportToSoul, fromSoul, generateActionFromDirective, generateCompletion, getGhostResults, getGhostStatus, importSoulFromIPFS, init, interactRule, movementRule, processAgentInput, processObservationToDirective, rankMemoriesByRelevance, resourceRule, serializeSoul, speakRule, startGhostSession, updateAgentState, validateAction, validateSoul, waitForGhostCompletion };
439
+ export { type AgentAction, type AgentConfig, type AgentResponse, type AgentState, type BridgeConfig, type CompletionOptions, type CortexConfig, type CortexStatus, type Directive, type GhostConfig, type GhostHistoryEntry, type GhostResults, type GhostStatus, type GhostTestResult, type IAgent, type IBridge, type ICortex, type IGhost, type IMemory, type ISoul, type MemoryConfig, type MemoryItem, type MemoryModuleConfig, type MemoryType, type Mood, type Observation, type Soul, type SoulExportConfig, type SoulExportResult, type SoulImportConfig, type SoulListEntry, type ValidationContext, type ValidationResult, type ValidationRule, type VectorStatus, attackRule, createAgent, createAgentFromSoul, createBridge, createCortex, createGhost, createInitialState, createMemory, createMemoryItem, createSoul, createSoulInstance, createTable, deserializeSoul, exportSoulToIPFS, exportToSoul, fromSoul, generateEmbedding, getGhostHistory, getGhostResults, getGhostStatus, getSoulList, getVectorTable, importSoulFromIPFS, init, initVectorEngine, interactRule, movementRule, processAgentInput, resourceRule, serializeSoul, speakRule, startGhostSession, stopGhostSession, updateAgentState, validateAction, validateSoul, waitForGhostCompletion };