Lem/Docs

Talk to a paper's agent, one conversation or many.

Each paper keeps its agent conversations on this machine, one JSON Lines file per conversation, with an index that names and orders them. Lem Desktop and the backend routes read and write the same files.

Routes#

  • GET /papers/{id}/agent/chat reads the paper's active conversation; POST /papers/{id}/agent/chat appends to it.
  • GET /papers/{id}/agent/chats/conversations lists the paper's conversations with their titles and which one is active.
  • POST /papers/{id}/agent/chats/new starts a conversation; GET /papers/{id}/agent/chats/{chat} reads one.
  • POST /papers/{id}/agent/runs and POST /papers/{id}/agent/chats/{chat}/runs start the agent on the active or the named conversation.

Where conversations are kept#

Conversations live under ~/.lem/chats. A paper's own conversation is ~/.lem/chats/<paper id>.jsonl; every other conversation of the paper is ~/.lem/chats/<paper id>/<conversation id>.jsonl, one message record per line.

~/.lem/chats/<paper id>/conversations.json is the paper's index: active_conversation_id, the conversation chosen last (the paper's own until another is chosen), and conversations, each with its id, title and created_at. A chat file the index holds no record of is still listed, under the paper's title, and choosing it records it as “Restored chat”.

When a conversation cannot be read#

An index that is not there starts with no conversations. One that is there but cannot be read or decoded is refused, naming the file, and never replaced with a fresh index, which would drop the conversations it records: repair it, or move it aside to list the chat files without their titles. A conversation folder this account cannot list is refused naming it.

A chat file is read record by record. A file that is not UTF-8 text, a line where a record should begin but something else stands, a record that is not a chat message, or a file that ends inside a record is refused naming the line and how many messages before it are intact, so the repair is that one line (sed -n '<line>p' <file> prints it) and the earlier messages stay.

A conversation with no message yet is dated by its file's creation date; a file system that refuses to say it, or keeps no creation date, is refused naming the file. A conversation file or folder this account cannot write is refused naming the folder to make writable; the message is sent again once it is.