forbocai 0.3.0 → 0.3.3

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: 'webllm' | '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 (Fallback/Mock)
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(): Promise<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/Database name 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>;
212
211
  /**
213
- * Mock Memory for testing (In-Memory Fallback)
212
+ * Soul entry in the listing
214
213
  */
215
- declare class MockMemory implements IMemory {
216
- private memories;
214
+ interface SoulListEntry {
215
+ cid: string;
216
+ name: string;
217
+ agentId?: string;
218
+ exportedAt: string;
219
+ ipfsUrl: string;
220
+ }
221
+ /**
222
+ * Get list of all exported Souls
223
+ */
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(): Promise<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,112 +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
- /** Use local IPFS node (Helia) */
317
- useLocalNode?: boolean;
318
- }
319
- /**
320
- * Soul export result
321
- */
322
- interface SoulExportResult {
323
- cid: string;
324
- ipfsUrl: string;
325
- signature?: string;
326
- soul: Soul;
327
- }
328
- /**
329
- * Soul import configuration
330
- */
331
- interface SoulImportConfig {
332
- /** API URL for IPFS retrieval */
333
- apiUrl?: string;
334
- /** Verify signature before import */
335
- verifySignature?: boolean;
336
- /** Use local IPFS node (Helia) */
337
- useLocalNode?: boolean;
338
- }
339
- /**
340
- * Interface for Soul operations
341
- */
342
- interface ISoul {
343
- export(config?: SoulExportConfig): Promise<SoulExportResult>;
344
- toJSON(): Soul;
345
- }
346
- /**
347
- * Pure function to create a Soul from agent data
348
- */
349
- declare const createSoul: (id: string, name: string, persona: string, state: AgentState, memories?: MemoryItem[]) => Soul;
350
- /**
351
- * Pure function to serialize Soul to JSON string
352
- */
353
- declare const serializeSoul: (soul: Soul) => string;
354
- /**
355
- * Pure function to deserialize Soul from JSON string
356
- */
357
- declare const deserializeSoul: (json: string) => Soul;
358
- /**
359
- * Pure function to validate Soul schema
360
- */
361
- declare const validateSoul: (soul: Soul) => {
362
- valid: boolean;
363
- errors: string[];
364
- };
365
- /**
366
- * Export agent Soul to IPFS (Helia or API)
367
- */
368
- declare const exportSoulToIPFS: (agentId: string, soul: Soul, config?: SoulExportConfig) => Promise<SoulExportResult>;
369
- /**
370
- * Import Soul from IPFS by CID (Helia or API)
371
- */
372
- declare const importSoulFromIPFS: (cid: string, config?: SoulImportConfig) => Promise<Soul>;
373
- /**
374
- * Create agent from imported Soul via API
375
- */
376
- declare const createAgentFromSoul: (cid: string, cortexId: string, config?: SoulImportConfig) => Promise<{
377
- agentId: string;
378
- persona: string;
379
- }>;
380
- /**
381
- * Soul class for object-oriented usage
382
- */
383
- declare class SoulImpl implements ISoul {
384
- private soul;
385
- private apiUrl;
386
- constructor(id: string, name: string, persona: string, state: AgentState, memories?: MemoryItem[], apiUrl?: string);
387
- export(config?: SoulExportConfig): Promise<SoulExportResult>;
388
- toJSON(): Soul;
389
- }
390
- /**
391
- * Factory function to create Soul instance
392
- */
393
- declare const createSoulInstance: (id: string, name: string, persona: string, state: AgentState, memories?: MemoryItem[], apiUrl?: string) => ISoul;
394
-
395
326
  /**
396
327
  * Ghost test configuration
397
328
  */
@@ -471,35 +402,38 @@ declare const getGhostResults: (sessionId: string, apiUrl?: string) => Promise<G
471
402
  */
472
403
  declare const waitForGhostCompletion: (sessionId: string, pollIntervalMs?: number, timeoutMs?: number, apiUrl?: string, onProgress?: (status: GhostStatus) => void) => Promise<GhostResults>;
473
404
  /**
474
- * Ghost class for object-oriented usage
405
+ * Stop a running Ghost session
475
406
  */
476
- declare class GhostSession implements IGhost {
477
- private config;
478
- private sessionId;
479
- private apiUrl;
480
- constructor(config: GhostConfig);
481
- run(): Promise<string>;
482
- status(): Promise<GhostStatus>;
483
- results(): Promise<GhostResults>;
484
- stop(): Promise<void>;
485
- 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;
486
421
  }
422
+ declare const getGhostHistory: (limit?: number, apiUrl?: string) => Promise<GhostHistoryEntry[]>;
487
423
  /**
488
- * Factory function to create Ghost session
424
+ * Factory function to create Ghost session (Functional/Closure based)
489
425
  */
490
426
  declare const createGhost: (config: GhostConfig) => IGhost;
491
427
 
492
- /**
493
- * ForbocAI SDK
494
- * The Infrastructure Layer for Autonomous AI Characters
495
- *
496
- * Functional Programming Principles:
497
- * - Pure functions with deterministic outputs
498
- * - Immutability - state never mutated directly
499
- * - No side effects in core logic
500
- * - Factory pattern for object creation
501
- */
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>;
502
436
 
503
437
  declare const init: () => void;
504
438
 
505
- 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 };