v0.7.0

Responses and SSE

Last updated


How HakoRun turns function output into JSON responses, and the event format of stream mode.

Type Tagging


Non-stream mode returns {"data": ..., "type": ...}. The result is the first valid JSON line found scanning stdout from the bottom; without one, it is the full output after filtering Node.js warnings (Warning:, ExperimentalWarning, and similar).
typeConditionExample data
stringJSON string"done"
numberJSON number8
jsonJSON object, array, boolean, or null{"sum": 30}
textNot valid JSONhello world

SSE Events


With stream: true the response uses text/event-stream, and each event is one data: <JSON> line:
  1. data: {"event":"log","data":0,"type":"number"}
  2. data: {"event":"result","data":"done","type":"string"}

eventSent When
logEach stdout line, once the next line arrives
resultThe process exits normally; content is the last stdout line
errorStderr output, timeout, client disconnect, or non-zero exit

Each event's type follows the table above; newlines inside result / error are replaced with spaces.

Completion and Abort


  • After sending result or error, the server hijacks and closes the connection.
  • The first stderr line triggers termination, with error reading stopped to run script: <that line>.
  • On client disconnect, error is stopped to run script: client disconnected (the client never receives it).


中文