Integration Workflow

Source-accurate setup for protocol execution

View as Markdown

1. Configure API Access

$export FORBOCAI_API_URL=https://api.forboc.ai
$export FORBOCAI_API_KEY=fb_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

2. Create Store and Runtime Components

1import {
2 createSDKStore,
3 setNPCInfo,
4 processNPC,
5 listMemoryRemoteThunk,
6 validateBridgeThunk,
7 remoteExportSoulThunk
8} from '@forbocai/core';
9import { createNodeCortex } from '@forbocai/node';
10
11const store = createSDKStore();
12
13store.dispatch(setNPCInfo({
14 id: 'npc_guard_001',
15 persona: 'A strict city gate guard.',
16 initialState: { alertLevel: 0 }
17}));
18
19const cortex = createNodeCortex('smollm2-135m');
20await cortex.init();

3. Run Protocol Turn

1const turn = await store.dispatch(processNPC({
2 npcId: 'npc_guard_001',
3 text: 'I need entry to the city.',
4 context: { playerReputation: 12 },
5 apiUrl: process.env.FORBOCAI_API_URL || 'https://api.forboc.ai',
6 apiKey: process.env.FORBOCAI_API_KEY,
7 cortex
8})).unwrap();
9
10console.log(turn.dialogue);
11console.log(turn.action);

4. Optional Remote Operations

1// memory list
2const memories = await store.dispatch(listMemoryRemoteThunk({
3 npcId: 'npc_guard_001',
4 apiUrl: 'https://api.forboc.ai',
5 apiKey: process.env.FORBOCAI_API_KEY
6})).unwrap();
7
8// bridge validate
9const validation = await store.dispatch(validateBridgeThunk({
10 action: { type: 'OPEN_GATE' },
11 context: { npcState: { alertLevel: 0 } },
12 apiUrl: 'https://api.forboc.ai',
13 apiKey: process.env.FORBOCAI_API_KEY
14})).unwrap();
15
16// soul export
17const soul = await store.dispatch(remoteExportSoulThunk({
18 npcId: 'npc_guard_001',
19 apiUrl: 'https://api.forboc.ai',
20 apiKey: process.env.FORBOCAI_API_KEY
21})).unwrap();
22
23console.log(memories.length, validation.valid, soul.txId);

5. CLI Workflow Alternative

$npx forbocai config set apiUrl https://api.forboc.ai
$npx forbocai config set apiKey fb_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
$
$npx forbocai npc create "A strict city guard"
$npx forbocai npc process <npcId> "I need entry to the city"
$npx forbocai memory list <npcId>
$npx forbocai soul export <npcId>