Skip to content

TypeScript SDK

The official MindFry SDK for TypeScript/Node.js applications.

Terminal window
npm install @mindfry/client
import { MindFry } from '@mindfry/client'
const brain = new MindFry({
host: 'localhost',
port: 9527,
})
await brain.connect()
// ... operations
await brain.disconnect()

The SDK organizes operations by namespace:

// Create
await brain.lineage.create({ key: 'hello', energy: 0.8 })
// Get
const 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 cascade
await brain.lineage.stimulate({ key: 'hello', delta: 0.5, flags: 0x01 })
// Forget
await brain.lineage.forget('hello')
// Create synergy bond
await brain.bond.connect({
from: 'fire',
to: 'heat',
strength: 0.8,
polarity: 1, // +1 = synergy
})
// Create antagonism bond
await brain.bond.connect({
from: 'fire',
to: 'ice',
strength: 0.7,
polarity: -1, // -1 = antagonism
})
// Get neighbors
const neighbors = await brain.query.neighbors('fire')
// Ping
const uptime = await brain.system.ping()
// Stats
const stats = await brain.system.stats()
console.log(stats.lineage_count)
console.log(stats.bond_count)
console.log(stats.mood)
// Set mood
await brain.system.setMood(0.8) // Euphoric
// Snapshot
await brain.system.snapshot('checkpoint_1')

The SDK supports high-throughput pipelining:

// These are sent immediately without waiting
const 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 order
await Promise.all([p1, p2, p3])
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
}
}
}
FlagValueDescription
BYPASS_FILTERS0x01Skip mood/threshold
INCLUDE_REPRESSED0x02Include below-threshold
NO_SIDE_EFFECTS0x04Skip Observer Effect
FORENSIC0x07All bypass flags

See API Reference for complete type definitions.