Artifact 26c298a9fb8182d9a112233c4cfb74adb75b56eb69fb3aeddb71098c374b14f8:
- File
src/events.h
— part of check-in
[c55dfbb163]
at
2026-11-19 23:39:49
on branch images
— Images, as Pi's
User messages, steering and follow-ups, and tool results can carry images. Journal version 9 keeps their bytes in SQLite (pic_image, deduplicated by SHA3-256, deflated only when smaller) linked by pic_attachment, written in the same transaction as the entry; pic check covers them. Each adapter sends its native shape (Anthropic base64 blocks, Chat image_url data URLs, Responses input_image); a model whose catalog input lacks images gets Pi's placeholders. pic ask --image PATH, the RPC images field and the read tool on image files add them; the Pi and HTML exports include them. (user: dmestas, size: 3832) [annotate] [blame] [check-ins using]
/* Live events while pic runs (events.c). JSON mode writes one event per line * on out with Pi's names and shapes (agent_start, turn_start, message_start, * message_update, message_end, tool_execution_start/end, compaction_start/end, * auto_retry_start, turn_end, agent_end), so a client of Pi's JSON mode can * read it. Text mode streams the reply text to out as it arrives and puts * tool calls and notices on notes. Events are not journaled: the journal is * the record, and a reply cut off mid-stream ends in message_end with * stopReason "error" before it is requested again. */ #ifndef PIC_EVENTS_H #define PIC_EVENTS_H #include <stddef.h> #include <stdint.h> #include <stdio.h> typedef struct pic_events { FILE *out; /* JSON lines, or the streamed reply text */ FILE *notes; /* text mode: tool calls and notices (NULL: none) */ int json; /* 1: JSON lines on out */ int stream; /* text mode: stream reply text to out */ int streamed; /* text mode: reply text written for this request */ int midline; /* text mode: out does not end in a newline */ int turn_open; /* a turn_start not yet ended */ int msg_open; /* an assistant message_start not yet ended */ int block; /* contentIndex of the current delta block, -1 none */ int thinking; /* the current block is thinking */ } pic_events; void pic_events_init(pic_events *e, FILE *out, FILE *notes, int json, int stream); struct pic_store; /* conversation, model ("provider/model"), context_window (tokens, 0 * unknown) and thinking (the level in effect, "" when none) are pic's * additions to Pi's event, for clients. */ void pic_ev_agent_start(struct pic_store *s, const char *request_key, const char *text, const char *images, const char *conversation, const char *model, long context_window, const char *thinking); void pic_ev_agent_end(struct pic_store *s, const char *request_key, const char *status, const char *error); void pic_ev_turn_start(struct pic_store *s); /* A reply's text or thinking as it streams (decoders call it). */ void pic_ev_delta(void *store, int thinking, const char *text, size_t len); /* The reply as journaled: neutral content (JSON), Pi stop reason, origin. usage is * Pi's usage object (JSON) or NULL. */ void pic_ev_message_end(struct pic_store *s, const char *neutral, const char *stop_reason, const char *provider, const char *api, const char *model, const char *usage); /* A provider request failed; attempt is the one that failed (1-based). */ void pic_ev_message_error(struct pic_store *s, const char *error, int attempt, int max_attempts, int will_retry); void pic_ev_tool_start(struct pic_store *s, const char *call_id, const char *tool, const char *args_json, const char *summary); /* images: a JSON array of Pi image blocks after the text, or NULL. */ void pic_ev_tool_end(struct pic_store *s, const char *call_id, const char *tool, const char *result, const char *images, int is_error); void pic_ev_compaction_start(struct pic_store *s, const char *reason, long long tokens); void pic_ev_compaction_end(struct pic_store *s, const char *reason, const char *summary, long long first_kept, long long tokens_before, const char *error); void pic_ev_note(struct pic_store *s, const char *text); /* A user message: a request's text, or steering or a follow-up delivered * into one (message_start and message_end, as Pi); images, when not NULL, * a JSON array of Pi image blocks that follow the text. */ void pic_ev_user_message(struct pic_store *s, const char *text, const char *images); /* One JSON object as a line on out, in JSON mode (queue_update, command * responses). */ void pic_ev_line(struct pic_store *s, const char *json); #endif