xonecas.io
7814
Ta

tiny-c-agent / files

tiny-c-agent / src / event.h

2.0 KB
1// tiny events: the single output stream of the agent loop.
2//
3// The loop emits these. The headless projection and the TUI both consume them
4// and own no agent semantics. String payloads are borrowed and valid only for
5// the duration of the callback.
6
7#ifndef TINY_EVENT_H
8#define TINY_EVENT_H
9
10#include <stdbool.h>
11#include <stddef.h>
12
13#include "tool.h"
14
15typedef enum {
16    TINY_PHASE_PREPARING,
17    TINY_PHASE_WAITING_MODEL,
18    TINY_PHASE_STREAMING,
19    TINY_PHASE_RUNNING_TOOL,
20    TINY_PHASE_PAUSING,
21    TINY_PHASE_IDLE,
22} tiny_phase;
23
24typedef enum {
25    TINY_EVENT_PHASE,
26    TINY_EVENT_TEXT,        // assistant text delta
27    TINY_EVENT_REASONING,   // reasoning delta
28    TINY_EVENT_TOOL_CALL_START, // the model began the tool call; name is known
29    TINY_EVENT_TOOL_CALL,   // the model requested the tool; arguments is JSON
30    TINY_EVENT_TOOL_OUTPUT, // stdout/stdout-like chunk from the tool
31    TINY_EVENT_TOOL_RESULT, // the tool finished
32    TINY_EVENT_MESSAGE,     // a complete assistant message, serialized as JSON
33    TINY_EVENT_NO_MODEL,
34    TINY_EVENT_ERROR,       // provider or harness error, surfaced as-is
35    TINY_EVENT_CANCELLED,
36    TINY_EVENT_COMPLETE,
37} tiny_event_type;
38
39typedef struct {
40    tiny_event_type type;
41    union {
42        struct { tiny_phase phase; const char *detail; } phase;
43        struct { const char *delta; } text;
44        struct { const char *delta; } reasoning;
45        struct { const char *name; } tool_call_start;
46        struct { const char *name; const char *arguments; } tool_call;
47        struct { const char *chunk; } tool_output;
48        struct {
49            const char *name;
50            const char *text;
51            bool is_error;
52            const tiny_file_diff *diffs;  // display-only; never reaches the model
53            size_t diffs_len;
54        } tool_result;
55        struct { const char *json; } message;
56        struct { const char *message; } error;
57    } u;
58} tiny_event;
59
60typedef void (*tiny_event_fn)(const tiny_event *event, void *user);
61
62#endif