@forbocai/core 0.4.4

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.
@@ -0,0 +1,597 @@
1
+ /**
2
+ * ForbocAI Core Types
3
+ * The foundational interfaces for the Neuro-Symbolic Protocol.
4
+ */
5
+ interface CortexConfig {
6
+ /** The model to load (e.g., 'smollm2-135m', 'llama3-8b-q4') */
7
+ model: string;
8
+ /** Optional overrides for model parameters */
9
+ temperature?: number;
10
+ maxTokens?: number;
11
+ gpu?: boolean;
12
+ /** Connection Config */
13
+ authKey?: string;
14
+ apiUrl?: string;
15
+ }
16
+ interface CortexStatus {
17
+ id: string;
18
+ model: string;
19
+ ready: boolean;
20
+ engine: 'mock' | 'remote' | 'node-llama-cpp' | 'web-llm';
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
+ }
27
+ interface CompletionOptions {
28
+ temperature?: number;
29
+ maxTokens?: number;
30
+ stop?: string[];
31
+ jsonSchema?: object;
32
+ }
33
+ type Mood = string;
34
+ interface AgentState {
35
+ [key: string]: unknown;
36
+ }
37
+ interface AgentConfig {
38
+ id: string;
39
+ cortex: ICortex;
40
+ memory: any;
41
+ persona: string;
42
+ initialState?: Partial<AgentState>;
43
+ memoryConfig?: MemoryConfig;
44
+ apiUrl?: string;
45
+ }
46
+ interface AgentResponse {
47
+ dialogue: string;
48
+ action?: AgentAction;
49
+ thought?: string;
50
+ }
51
+ type MemoryType = string;
52
+ interface MemoryConfig {
53
+ /** Decay strategy: 'none' | 'temporal' */
54
+ decay?: 'none' | 'temporal';
55
+ /** Max memories to keep in active context during retrieval */
56
+ maxContextWindow?: number;
57
+ }
58
+ interface MemoryItem {
59
+ id: string;
60
+ text: string;
61
+ embedding?: number[];
62
+ timestamp: number;
63
+ type: MemoryType;
64
+ importance: number;
65
+ }
66
+ interface Observation {
67
+ type: 'event' | 'state' | 'request';
68
+ timestamp: number;
69
+ agentId?: string;
70
+ gameId?: string;
71
+ content: string;
72
+ data?: Record<string, unknown>;
73
+ context?: Record<string, unknown>;
74
+ }
75
+ interface Directive {
76
+ type: 'system-prompt' | 'action-constraints' | 'behavior-rules' | 'thought';
77
+ content: string;
78
+ constraints?: Record<string, unknown>;
79
+ priority?: 'high' | 'normal' | 'low';
80
+ expiresAt?: number;
81
+ }
82
+ interface AgentAction {
83
+ type: string;
84
+ target?: string;
85
+ payload?: Record<string, unknown>;
86
+ reason?: string;
87
+ confidence?: number;
88
+ signature?: string;
89
+ }
90
+ interface ValidationContext {
91
+ agentState?: Record<string, unknown>;
92
+ worldState?: Record<string, unknown>;
93
+ constraints?: Record<string, unknown>;
94
+ }
95
+ interface ValidationResult {
96
+ valid: boolean;
97
+ reason?: string;
98
+ correctedAction?: AgentAction;
99
+ }
100
+ interface ValidationRule {
101
+ id: string;
102
+ name: string;
103
+ description: string;
104
+ actionTypes: string[];
105
+ validate: (action: AgentAction, context: ValidationContext) => ValidationResult;
106
+ }
107
+ interface Soul {
108
+ id: string;
109
+ version: string;
110
+ name: string;
111
+ persona: string;
112
+ memories: MemoryItem[];
113
+ state: AgentState;
114
+ signature?: string;
115
+ }
116
+
117
+ /**
118
+ * Interface for Agent operations
119
+ */
120
+ /**
121
+ * Interface for Agent operations
122
+ */
123
+ interface IAgent {
124
+ /**
125
+ * Processes an input string with optional context to generate a response.
126
+ * @param input - The input string from the user or system.
127
+ * @param context - Optional context data to influence the agent's response.
128
+ * @returns A promise that resolves to the agent's response.
129
+ */
130
+ process(input: string, context?: Record<string, unknown>): Promise<AgentResponse>;
131
+ /**
132
+ * Retrieves the current state of the agent.
133
+ * @returns The current AgentState.
134
+ */
135
+ getState(): AgentState;
136
+ /**
137
+ * Updates the agent's state.
138
+ * @param newState - The new state to set.
139
+ */
140
+ setState(newState: AgentState): void;
141
+ /**
142
+ * Exports the agent's data to a Soul object.
143
+ * @returns A promise resolving to the Soul representation of the agent.
144
+ */
145
+ export(): Promise<Soul>;
146
+ }
147
+ /**
148
+ * Pure function to create initial agent state
149
+ * @param partial - Optional partial state to initialize with.
150
+ * @returns The initialized AgentState.
151
+ */
152
+ declare const createInitialState: (partial?: Partial<AgentState>) => AgentState;
153
+ /**
154
+ * Pure function to update agent state
155
+ * Returns new state without mutating original
156
+ * @param currentState - The current state of the agent.
157
+ * @param updates - The updates to apply to the state.
158
+ * @returns A new AgentState object with the updates applied.
159
+ */
160
+ declare const updateAgentState: (currentState: AgentState, updates: Partial<AgentState>) => AgentState;
161
+ /**
162
+ * Pure function to process input and generate response
163
+ * @param currentState - The current state of the agent.
164
+ * @param input - The input string to process.
165
+ * @param context - Optional context data.
166
+ * @returns The agent's response including dialogue and action.
167
+ */
168
+ declare const processAgentInput: (currentState: AgentState, input: string, context?: Record<string, unknown>) => AgentResponse;
169
+ /**
170
+ * Pure function to export agent to Soul
171
+ * @param agentId - The ID of the agent.
172
+ * @param name - The name of the agent.
173
+ * @param persona - The persona description of the agent.
174
+ * @param state - The current state of the agent.
175
+ * @param memories - The list of memories associated with the agent.
176
+ * @returns A Soul object representing the agent.
177
+ */
178
+ declare const exportToSoul: (agentId: string, name: string, persona: string, state: AgentState, memories: MemoryItem[]) => Soul;
179
+ /**
180
+ * Factory function to create Agent (Functional/Closure based)
181
+ * @param config - The configuration object for creating the agent.
182
+ * @returns An instance of IAgent.
183
+ */
184
+ declare const createAgent: (config: AgentConfig) => IAgent;
185
+ /**
186
+ * Pure function to import Agent from Soul
187
+ * @param soul - The Soul object to import from.
188
+ * @param cortex - The Cortex instance for the agent.
189
+ * @param memory - Optional memory instance.
190
+ * @returns An instantiated IAgent.
191
+ */
192
+ declare const fromSoul: (soul: Soul, cortex: ICortex, memory?: any) => Promise<IAgent>;
193
+
194
+ /**
195
+ * Bridge configuration
196
+ */
197
+ interface BridgeConfig {
198
+ /** Base URL for the API. */
199
+ apiUrl?: string;
200
+ /** If true, reject any unknown action types. */
201
+ strictMode?: boolean;
202
+ /** Custom validation rules to apply. */
203
+ customRules?: ValidationRule[];
204
+ }
205
+ /**
206
+ * Interface for Bridge operations
207
+ */
208
+ interface IBridge {
209
+ /**
210
+ * Validates an agent action against registered rules.
211
+ * @param action - The action to validate.
212
+ * @param context - Optional validation context.
213
+ * @returns A promise that resolves to the validation result.
214
+ */
215
+ validate(action: AgentAction, context?: ValidationContext): Promise<ValidationResult>;
216
+ /**
217
+ * Registers a new validation rule.
218
+ * @param rule - The rule to register.
219
+ */
220
+ registerRule(rule: ValidationRule): void;
221
+ /**
222
+ * Lists all registered validation rules.
223
+ * @returns An array of ValidationRule objects.
224
+ */
225
+ listRules(): ValidationRule[];
226
+ /**
227
+ * Removes a validation rule by its ID.
228
+ * @param ruleId - The ID of the rule to remove.
229
+ * @returns True if the rule was removed, false otherwise.
230
+ */
231
+ removeRule(ruleId: string): boolean;
232
+ }
233
+ /**
234
+ * Factory function to create Bridge instance (Functional/Closure based)
235
+ * @param config - Optional configuration for the Bridge.
236
+ * @returns An instance of IBridge.
237
+ */
238
+ declare const createBridge: (config?: BridgeConfig) => IBridge;
239
+ /**
240
+ * Pure function to validate action (standalone, no class needed)
241
+ * @param action - The action to validate.
242
+ * @param rules - The list of rules to validate against.
243
+ * @param context - Optional validation context.
244
+ * @returns The result of the validation.
245
+ */
246
+ declare const validateAction: (action: AgentAction, rules: readonly ValidationRule[], context?: ValidationContext) => ValidationResult;
247
+
248
+ /**
249
+ * Soul export configuration
250
+ */
251
+ interface SoulExportConfig {
252
+ /** API URL for remote upload/pinning */
253
+ apiUrl?: string;
254
+ /** Include memories in export */
255
+ includeMemories?: boolean;
256
+ /** Private key for signing/uploading directly to Arweave via Irys */
257
+ privateKey?: string;
258
+ /** RPC URL for Irys (defaults to https://node1.irys.xyz) */
259
+ irysUrl?: string;
260
+ /** Token/Currency (default: 'solana') */
261
+ token?: string;
262
+ }
263
+ /**
264
+ * Soul export result
265
+ */
266
+ interface SoulExportResult {
267
+ /** Arweave Transaction ID (TXID) */
268
+ txId: string;
269
+ /** Gateway URL to access the soul. */
270
+ url: string;
271
+ /** The exported Soul object. */
272
+ soul: Soul;
273
+ }
274
+ /**
275
+ * Soul import configuration
276
+ */
277
+ interface SoulImportConfig {
278
+ /** API URL for retrieval */
279
+ apiUrl?: string;
280
+ /** Gateway URL for Arweave (defaults to https://gateway.irys.xyz) */
281
+ gatewayUrl?: string;
282
+ }
283
+ /**
284
+ * Interface for Soul operations
285
+ */
286
+ interface ISoul {
287
+ /**
288
+ * Exports the Soul to Arweave.
289
+ * @param config - Export configuration.
290
+ * @returns A promise resolving to the export result.
291
+ */
292
+ export(config?: SoulExportConfig): Promise<SoulExportResult>;
293
+ /**
294
+ * Returns the raw Soul data object.
295
+ * @returns The Soul object.
296
+ */
297
+ toJSON(): Soul;
298
+ }
299
+ /**
300
+ * Pure function to create a Soul from agent data
301
+ */
302
+ declare const createSoul: (id: string, name: string, persona: string, state: AgentState, memories?: MemoryItem[]) => Soul;
303
+ /**
304
+ * Pure function to serialize Soul to JSON string
305
+ */
306
+ declare const serializeSoul: (soul: Soul) => string;
307
+ /**
308
+ * Pure function to deserialize Soul from JSON string
309
+ */
310
+ declare const deserializeSoul: (json: string) => Soul;
311
+ /**
312
+ * Pure function to upload Soul to Arweave via Irys
313
+ */
314
+ declare const uploadToArweave: (soul: Soul, config: SoulExportConfig) => Promise<SoulExportResult>;
315
+ /**
316
+ * Export agent Soul to Arweave (Irys or API)
317
+ */
318
+ declare const exportSoul: (agentId: string, soul: Soul, config?: SoulExportConfig) => Promise<SoulExportResult>;
319
+ /**
320
+ * Import Soul from Arweave by TXID
321
+ */
322
+ declare const importSoulFromArweave: (txId: string, config?: SoulImportConfig) => Promise<Soul>;
323
+ /**
324
+ * Soul entry in the listing
325
+ */
326
+ interface SoulListEntry {
327
+ txId: string;
328
+ name: string;
329
+ agentId?: string;
330
+ exportedAt: string;
331
+ url: string;
332
+ }
333
+ /**
334
+ * Get list of all exported Souls
335
+ */
336
+ declare const getSoulList: (limit?: number, apiUrl?: string) => Promise<SoulListEntry[]>;
337
+ /**
338
+ * Factory function to create Soul instance
339
+ */
340
+ declare const createSoulInstance: (id: string, name: string, persona: string, state: AgentState, memories?: MemoryItem[], initialApiUrl?: string) => ISoul;
341
+ /**
342
+ * Pure function to validate a Soul object
343
+ */
344
+ declare const validateSoul: (soul: Soul) => {
345
+ valid: boolean;
346
+ errors: string[];
347
+ };
348
+
349
+ /**
350
+ * Ghost test configuration
351
+ */
352
+ /**
353
+ * Ghost test configuration
354
+ */
355
+ interface GhostConfig {
356
+ /** API URL for ghost orchestration */
357
+ apiUrl?: string;
358
+ /** Test suite to run */
359
+ testSuite: 'exploration' | 'combat' | 'dialogue' | 'pathfinding' | 'full';
360
+ /** Maximum duration in seconds */
361
+ duration: number;
362
+ /** Capture screenshots on failure */
363
+ captureScreenshots?: boolean;
364
+ /** Custom test parameters */
365
+ params?: Record<string, unknown>;
366
+ }
367
+ /**
368
+ * Ghost session status
369
+ */
370
+ /**
371
+ * Ghost session status
372
+ */
373
+ interface GhostStatus {
374
+ /** The unique ID of the session. */
375
+ sessionId: string;
376
+ /** The current status of the session. */
377
+ status: 'pending' | 'running' | 'completed' | 'failed';
378
+ /** Progress percentage (0-100). */
379
+ progress: number;
380
+ /** ISO timestamp when the session started. */
381
+ startedAt: string;
382
+ /** Duration in seconds elapsed. */
383
+ duration: number;
384
+ /** Number of errors encountered. */
385
+ errors: number;
386
+ }
387
+ /**
388
+ * Individual test result
389
+ */
390
+ /**
391
+ * Individual test result
392
+ */
393
+ interface GhostTestResult {
394
+ /** Name of the test case. */
395
+ name: string;
396
+ /** Whether the test passed. */
397
+ passed: boolean;
398
+ /** Duration of the test in milliseconds. */
399
+ duration: number;
400
+ /** Error message if the test failed. */
401
+ error?: string;
402
+ /** URL or path to a screenshot if captured. */
403
+ screenshot?: string;
404
+ }
405
+ /**
406
+ * Complete session results
407
+ */
408
+ /**
409
+ * Complete session results
410
+ */
411
+ interface GhostResults {
412
+ /** The session ID. */
413
+ sessionId: string;
414
+ /** Total number of tests run. */
415
+ totalTests: number;
416
+ /** Number of passed tests. */
417
+ passed: number;
418
+ /** Number of failed tests. */
419
+ failed: number;
420
+ /** Number of skipped tests. */
421
+ skipped: number;
422
+ /** Total duration in milliseconds. */
423
+ duration: number;
424
+ /** List of individual test results. */
425
+ tests: GhostTestResult[];
426
+ /** Code/Feature coverage (0.0-1.0). */
427
+ coverage: number;
428
+ /** Additional metrics collected during the session. */
429
+ metrics: Record<string, number>;
430
+ }
431
+ /**
432
+ * Interface for Ghost operations
433
+ */
434
+ /**
435
+ * Interface for Ghost operations
436
+ */
437
+ interface IGhost {
438
+ /**
439
+ * Starts a Ghost session.
440
+ * @returns A promise resolving to the session ID.
441
+ */
442
+ run(): Promise<string>;
443
+ /**
444
+ * Gets the current status of the session.
445
+ * @returns A promise resolving to the GhostStatus.
446
+ */
447
+ status(): Promise<GhostStatus>;
448
+ /**
449
+ * Gets the results of the session.
450
+ * @returns A promise resolving to the GhostResults.
451
+ */
452
+ results(): Promise<GhostResults>;
453
+ /**
454
+ * Stops the current session.
455
+ */
456
+ stop(): Promise<void>;
457
+ /**
458
+ * Waits for the session to complete.
459
+ * @param pollIntervalMs - Polling interval in milliseconds.
460
+ * @param timeoutMs - Timeout in milliseconds.
461
+ * @param onProgress - Optional callback for progress updates.
462
+ * @returns A promise resolving to the GhostResults.
463
+ */
464
+ waitForCompletion(pollIntervalMs?: number, timeoutMs?: number, onProgress?: (status: GhostStatus) => void): Promise<GhostResults>;
465
+ }
466
+ /**
467
+ * Start a Ghost testing session
468
+ * @param config - The configuration for the Ghost session.
469
+ * @returns A promise resolving to an object containing the session ID and initial status.
470
+ */
471
+ declare const startGhostSession: (config: GhostConfig) => Promise<{
472
+ sessionId: string;
473
+ status: string;
474
+ }>;
475
+ /**
476
+ * Get Ghost session status
477
+ * @param sessionId - The ID of the session to check.
478
+ * @param apiUrl - Optional API URL override.
479
+ * @returns A promise resolving to the GhostStatus.
480
+ */
481
+ declare const getGhostStatus: (sessionId: string, apiUrl?: string) => Promise<GhostStatus>;
482
+ /**
483
+ * Get Ghost session results
484
+ * @param sessionId - The ID of the session to retrieve results for.
485
+ * @param apiUrl - Optional API URL override.
486
+ * @returns A promise resolving to the GhostResults.
487
+ */
488
+ declare const getGhostResults: (sessionId: string, apiUrl?: string) => Promise<GhostResults>;
489
+ /**
490
+ * Poll Ghost session until completion
491
+ * @param sessionId - The ID of the session to wait for.
492
+ * @param pollIntervalMs - Polling interval in milliseconds.
493
+ * @param timeoutMs - Timeout in milliseconds.
494
+ * @param apiUrl - Optional API URL override.
495
+ * @param onProgress - Optional callback for progress updates.
496
+ * @returns A promise resolving to the GhostResults upon completion.
497
+ */
498
+ declare const waitForGhostCompletion: (sessionId: string, pollIntervalMs?: number, timeoutMs?: number, apiUrl?: string, onProgress?: (status: GhostStatus) => void) => Promise<GhostResults>;
499
+ /**
500
+ * Stop a running Ghost session
501
+ * @param sessionId - The ID of the session to stop.
502
+ * @param apiUrl - Optional API URL override.
503
+ * @returns A promise resolving to the stop status.
504
+ */
505
+ declare const stopGhostSession: (sessionId: string, apiUrl?: string) => Promise<{
506
+ stopped: boolean;
507
+ status: string;
508
+ }>;
509
+ /**
510
+ * Get Ghost session history
511
+ */
512
+ interface GhostHistoryEntry {
513
+ sessionId: string;
514
+ testSuite: string;
515
+ startedAt: string;
516
+ completedAt?: string;
517
+ status: string;
518
+ passRate: number;
519
+ }
520
+ /**
521
+ * Get Ghost session history
522
+ * @param limit - Max number of entries to retrieve.
523
+ * @param apiUrl - Optional API URL override.
524
+ * @returns A promise resolving to an array of GhostHistoryEntry.
525
+ */
526
+ declare const getGhostHistory: (limit?: number, apiUrl?: string) => Promise<GhostHistoryEntry[]>;
527
+ /**
528
+ * Factory function to create Ghost session (Functional/Closure based)
529
+ * @param config - The configuration for the Ghost session.
530
+ * @returns An instance of IGhost.
531
+ */
532
+ declare const createGhost: (config: GhostConfig) => IGhost;
533
+
534
+ /**
535
+ * Remote Cortex implementation that proxies inference to the ForbocAI API.
536
+ * This is environment-agnostic as it only uses the standard fetch API.
537
+ */
538
+ declare class RemoteCortex implements ICortex {
539
+ private apiUrl;
540
+ constructor(apiUrl: string);
541
+ init(): Promise<CortexStatus>;
542
+ complete(prompt: string, options?: CompletionOptions): Promise<string>;
543
+ completeStream(prompt: string, options?: CompletionOptions): AsyncGenerator<string>;
544
+ }
545
+
546
+ interface RPGAgentState extends AgentState {
547
+ inventory: string[];
548
+ hp: number;
549
+ mana: number;
550
+ skills: Record<string, number>;
551
+ relationships: Record<string, number>;
552
+ mood: string;
553
+ }
554
+ declare const RPG_MOODS: {
555
+ readonly hostile: "hostile";
556
+ readonly suspicious: "suspicious";
557
+ readonly neutral: "neutral";
558
+ readonly friendly: "friendly";
559
+ readonly loyal: "loyal";
560
+ };
561
+ declare const RPG_MEMORY_TYPES: {
562
+ readonly observation: "observation";
563
+ readonly experience: "experience";
564
+ readonly knowledge: "knowledge";
565
+ readonly emotion: "emotion";
566
+ };
567
+ declare const createRPGState: (partial?: Partial<RPGAgentState>) => RPGAgentState;
568
+ declare const movementRule: ValidationRule;
569
+ declare const attackRule: ValidationRule;
570
+ declare const interactRule: ValidationRule;
571
+ declare const speakRule: ValidationRule;
572
+ declare const resourceRule: ValidationRule;
573
+ declare const rpgRules: ValidationRule[];
574
+ declare const spatialRules: ValidationRule[];
575
+ declare const socialRules: ValidationRule[];
576
+ declare const puzzleRules: ValidationRule[];
577
+
578
+ type index_RPGAgentState = RPGAgentState;
579
+ declare const index_RPG_MEMORY_TYPES: typeof RPG_MEMORY_TYPES;
580
+ declare const index_RPG_MOODS: typeof RPG_MOODS;
581
+ declare const index_attackRule: typeof attackRule;
582
+ declare const index_createRPGState: typeof createRPGState;
583
+ declare const index_interactRule: typeof interactRule;
584
+ declare const index_movementRule: typeof movementRule;
585
+ declare const index_puzzleRules: typeof puzzleRules;
586
+ declare const index_resourceRule: typeof resourceRule;
587
+ declare const index_rpgRules: typeof rpgRules;
588
+ declare const index_socialRules: typeof socialRules;
589
+ declare const index_spatialRules: typeof spatialRules;
590
+ declare const index_speakRule: typeof speakRule;
591
+ declare namespace index {
592
+ export { type index_RPGAgentState as RPGAgentState, index_RPG_MEMORY_TYPES as RPG_MEMORY_TYPES, index_RPG_MOODS as RPG_MOODS, index_attackRule as attackRule, index_createRPGState as createRPGState, index_interactRule as interactRule, index_movementRule as movementRule, index_puzzleRules as puzzleRules, index_resourceRule as resourceRule, index_rpgRules as rpgRules, index_socialRules as socialRules, index_spatialRules as spatialRules, index_speakRule as speakRule };
593
+ }
594
+
595
+ declare const SDK_VERSION = "0.4.4";
596
+
597
+ 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 ISoul, type MemoryConfig, type MemoryItem, type MemoryType, type Mood, type Observation, RemoteCortex, SDK_VERSION, type Soul, type SoulExportConfig, type SoulExportResult, type SoulImportConfig, type SoulListEntry, type ValidationContext, type ValidationResult, type ValidationRule, createAgent, createBridge, createGhost, createInitialState, createSoul, createSoulInstance, deserializeSoul, exportSoul, exportToSoul, fromSoul, getGhostHistory, getGhostResults, getGhostStatus, getSoulList, importSoulFromArweave, index as presets, processAgentInput, serializeSoul, startGhostSession, stopGhostSession, updateAgentState, uploadToArweave, validateAction, validateSoul, waitForGhostCompletion };