Quickstart
Build a minimal script that sends a message, streams a response, rewrites text, and reads usage.
1. Install
npm install heylock
2. Set environment
Store your agent key in an environment variable.
HEYLOCK_AGENT_KEY=YOUR_KEY
3. Create script
Create a script that initializes, sends a message, streams another, performs a rewrite, sorts data, and checks balance.
1import Heylock from 'heylock';
2
3const agent = new Heylock(process.env.HEYLOCK_AGENT_KEY);
4
5// Wait for initialization
6while (!agent.isInitialized) {
7 await new Promise(resolve => setTimeout(resolve, 50));
8}
9
10// Basic message
11const hello = await agent.message('Hello');
12console.log('Reply:', hello);
13
14// Streaming
15let streamed = '';
16for await (const chunk of agent.messageStream('Stream a short response')) {
17 streamed += chunk;
18 process.stdout.write(chunk);
19}
20console.log('Streamed Full:', streamed);
21
22// Rewrite
23const rewritten = await agent.rewrite('pls help me i cant sync');
24console.log('Rewrite:', rewritten);
25
26// Sort
27const items = [{ score: 5 }, { score: 1 }, { score: 9 }];
28const sorted = await agent.sort(items, 'Sort descending by score');
29console.log(sorted.array);
30
31// Balance
32await agent.fetchBalanceRemaining();
33console.log(agent.balanceRemaining);
34
4. Run
node script.mjs