API Reference
Every method of the SDK.
createHronika(options?)
Creates a client. It reads the API URL from the HRONIKA_API environment variable and throws HRONIKA_API is not set if it is missing.
import { createHronika } from 'hronika';
const hronika = createHronika();| Option | Type | Default | Description |
|---|---|---|---|
fetch | typeof fetch | global fetch | Custom fetch implementation, for example in tests. |
Every method below returns a promise.
init()
Creates a loop and returns its id.
const { loopId } = await hronika.init();save(input)
Appends a checkpoint to the loop and moves the cursor to it. Returns the saved checkpoint.
type CheckpointInput =
| { loopId: string; type: 'inference_request' | 'tool_call_request'; parameters: unknown; agentState?: unknown }
| { loopId: string; type: 'inference_result' | 'tool_call_result'; result: unknown; agentState?: unknown };get({ loopId, checkpointId })
Returns one checkpoint by id.
current(loopId)
Returns the checkpoint under the cursor.
undo(loopId)
Moves the cursor one checkpoint back and returns that checkpoint.
redo(loopId)
Moves the cursor one checkpoint forward and returns that checkpoint.
Checkpoint
The value returned by save, get, current, undo and redo:
type Checkpoint = {
id: string;
type: 'inference_request' | 'tool_call_request' | 'inference_result' | 'tool_call_result';
parameters?: unknown; // requests
result?: unknown; // results
agentState?: unknown;
createdAt: string; // ISO date
};Errors
A failed request throws a HronikaError with the HTTP status and the API's message.
import { HronikaError } from 'hronika';
try {
await hronika.undo(loopId);
} catch (error) {
if (error instanceof HronikaError && error.status === 404) {
// e.g. "No checkpoint to undo" or "Loop <id> not found"
}
}| Message | Status | When |
|---|---|---|
Loop <id> not found | 404 | The loop does not exist. |
Checkpoint <id> not found | 404 | get with an id that is not in the loop. |
No checkpoint to undo | 404 | undo on the first checkpoint. |
No checkpoint to redo | 404 | redo on the last checkpoint. |
No checkpoint to get | 404 | current before anything has been saved. |