TypeScript SDK
TypeScript SDK Guide
Section titled “TypeScript SDK Guide”The official MindFry SDK for TypeScript/Node.js applications.
Installation
Section titled “Installation”npm install @mindfry/clientConnection
Section titled “Connection”import { MindFry } from '@mindfry/client'
const brain = new MindFry({ host: 'localhost', port: 9527,})
await brain.connect()
// ... operations
await brain.disconnect()Namespace API
Section titled “Namespace API”The SDK organizes operations by namespace:
brain.lineage
Section titled “brain.lineage”// Createawait brain.lineage.create({ key: 'hello', energy: 0.8 })
// Getconst memory = await brain.lineage.get('hello')console.log(memory.energy) // 0.8
// Get with bypass (forensic mode)const forensic = await brain.lineage.get('hello', 0x07)
// Stimulate (triggers cascade)await brain.lineage.stimulate({ key: 'hello', delta: 0.5 })
// Stimulate without cascadeawait brain.lineage.stimulate({ key: 'hello', delta: 0.5, flags: 0x01 })
// Forgetawait brain.lineage.forget('hello')brain.bond
Section titled “brain.bond”// Create synergy bondawait brain.bond.connect({ from: 'fire', to: 'heat', strength: 0.8, polarity: 1, // +1 = synergy})
// Create antagonism bondawait brain.bond.connect({ from: 'fire', to: 'ice', strength: 0.7, polarity: -1, // -1 = antagonism})
// Get neighborsconst neighbors = await brain.query.neighbors('fire')brain.system
Section titled “brain.system”// Pingconst uptime = await brain.system.ping()
// Statsconst stats = await brain.system.stats()console.log(stats.lineage_count)console.log(stats.bond_count)console.log(stats.mood)
// Set moodawait brain.system.setMood(0.8) // Euphoric
// Snapshotawait brain.system.snapshot('checkpoint_1')Pipelining
Section titled “Pipelining”The SDK supports high-throughput pipelining:
// These are sent immediately without waitingconst p1 = brain.lineage.create({ key: 'a', energy: 0.5 })const p2 = brain.lineage.create({ key: 'b', energy: 0.5 })const p3 = brain.bond.connect({ from: 'a', to: 'b', strength: 0.8, polarity: 1 })
// Responses matched in FIFO orderawait Promise.all([p1, p2, p3])Error Handling
Section titled “Error Handling”import { MindFryError, LineageStatus } from '@mindfry/client'
try { const memory = await brain.lineage.get('nonexistent')} catch (e) { if (e instanceof MindFryError) { switch (e.status) { case LineageStatus.NotFound: console.log('Memory does not exist') break case LineageStatus.Repressed: console.log('Memory below consciousness threshold') break case LineageStatus.Dormant: console.log('Memory in deep subconscious') break } }}Query Flags
Section titled “Query Flags”| Flag | Value | Description |
|---|---|---|
BYPASS_FILTERS | 0x01 | Skip mood/threshold |
INCLUDE_REPRESSED | 0x02 | Include below-threshold |
NO_SIDE_EFFECTS | 0x04 | Skip Observer Effect |
FORENSIC | 0x07 | All bypass flags |
See API Reference for complete type definitions.