xonecas.io
7814
Ta

tiny-c-agent / commit 3865700

chore: temp name to `tiny-c-agent`

xonecas2026-10-03 38657004170088f2a0006d7aba5d67ff2859ee40 parent 6b67007

58 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

AGENTS.md+1−1
@@ -1,6 +1,6 @@
11 # Project file for agents
22
3-## c-agent (`cage` for short)
3+## tiny-c-agent (`tiny` for short)
44
55 A fast, minimal and config first agent for your terminal.
66
Makefile+2−2
@@ -1,4 +1,4 @@
1-# cage - config-first agent for the terminal.
1+# tiny-c-agent - config-first agent for the terminal.
22 #
33 # make build
44 # make deps report build dependencies
@@ -11,7 +11,7 @@ OPT ?= -O2 -g
1111 WARN := -Wall -Wextra -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith
1212
1313 BUILD := build
14-BIN := $(BUILD)/cage
14+BIN := $(BUILD)/tiny
1515
1616 PKGS := libcurl yyjson tree-sitter \
1717 tree-sitter-javascript tree-sitter-bash \
initial.md+1−1
@@ -1,4 +1,4 @@
1-# c-agent (`cage` for short)
1+# tiny-c-agent (`tiny` for short)
22
33 A fast, minimal and config-first agent for your terminal.
44
src/agent.c+64−64
@@ -15,31 +15,31 @@
1515
1616 // Per-turn state passed to the provider and tool callbacks.
1717 typedef struct {
18- cage_agent *a;
18+ tiny_agent *a;
1919 bool streaming;
2020 } turn_state;
2121
2222 // ---- event helpers --------------------------------------------------------
2323
24-static void emit(cage_agent *a, const cage_event *e) {
24+static void emit(tiny_agent *a, const tiny_event *e) {
2525 if (a->on_event) a->on_event(e, a->user);
2626 }
2727
28-static void emit_phase(cage_agent *a, cage_phase phase, const char *detail) {
29- cage_event e = {.type = CAGE_EVENT_PHASE};
28+static void emit_phase(tiny_agent *a, tiny_phase phase, const char *detail) {
29+ tiny_event e = {.type = TINY_EVENT_PHASE};
3030 e.u.phase.phase = phase;
3131 e.u.phase.detail = detail;
3232 emit(a, &e);
3333 }
3434
35-static void emit_error(cage_agent *a, const char *msg) {
36- cage_event e = {.type = CAGE_EVENT_ERROR};
35+static void emit_error(tiny_agent *a, const char *msg) {
36+ tiny_event e = {.type = TINY_EVENT_ERROR};
3737 e.u.error.message = msg ? msg : "";
3838 emit(a, &e);
3939 }
4040
41-static void emit_simple(cage_agent *a, cage_event_type type) {
42- cage_event e = {.type = type};
41+static void emit_simple(tiny_agent *a, tiny_event_type type) {
42+ tiny_event e = {.type = type};
4343 emit(a, &e);
4444 }
4545
@@ -47,7 +47,7 @@ static void emit_simple(cage_agent *a, cage_event_type type) {
4747
4848 // Appends the message to the transcript and, when configured, to the session.
4949 // On a persistence failure the turn must stop, so this reports the error.
50-static int push_message(cage_agent *a, cage_message *m, char **err) {
50+static int push_message(tiny_agent *a, tiny_message *m, char **err) {
5151 a->messages = realloc(a->messages, (a->messages_len + 1) * sizeof *a->messages);
5252 if (!a->messages) abort();
5353 a->messages[a->messages_len++] = *m;
@@ -57,9 +57,9 @@ static int push_message(cage_agent *a, cage_message *m, char **err) {
5757 yyjson_mut_val *record = yyjson_mut_obj(doc);
5858 yyjson_mut_doc_set_root(doc, record);
5959 yyjson_mut_obj_add_strcpy(doc, record, "type", "message");
60- yyjson_mut_obj_add_val(doc, record, "message", cage_message_to_val(doc, m));
60+ yyjson_mut_obj_add_val(doc, record, "message", tiny_message_to_val(doc, m));
6161 char *serr = NULL;
62- int rc = cage_session_append(a->session, record, &serr);
62+ int rc = tiny_session_append(a->session, record, &serr);
6363 yyjson_mut_doc_free(doc);
6464 if (rc != 0) {
6565 *err = serr ? serr : xstrdup("session append failed");
@@ -68,8 +68,8 @@ static int push_message(cage_agent *a, cage_message *m, char **err) {
6868 return 0;
6969 }
7070
71-static int push_user(cage_agent *a, const char *text, char **err) {
72- cage_message m = cage_message_user(text);
71+static int push_user(tiny_agent *a, const char *text, char **err) {
72+ tiny_message m = tiny_message_user(text);
7373 return push_message(a, &m, err);
7474 }
7575
@@ -77,14 +77,14 @@ static int push_user(cage_agent *a, const char *text, char **err) {
7777
7878 // Checks the cancel flag and, at a step boundary, a pause request. On pause it
7979 // blocks for steering. Returns false when the turn was cancelled.
80-static bool pause_step(cage_agent *a, char **steer) {
80+static bool pause_step(tiny_agent *a, char **steer) {
8181 *steer = NULL;
8282 if (a->cancel && *a->cancel) return false;
8383 if (!a->is_pause_requested || !a->is_pause_requested(a->user)) return true;
8484 if (a->clear_pause) a->clear_pause(a->user);
85- emit_phase(a, CAGE_PHASE_PAUSING, NULL);
85+ emit_phase(a, TINY_PHASE_PAUSING, NULL);
8686 char *s = a->request_steering ? a->request_steering(a->user) : NULL;
87- emit_phase(a, CAGE_PHASE_IDLE, NULL);
87+ emit_phase(a, TINY_PHASE_IDLE, NULL);
8888 if (a->cancel && *a->cancel) {
8989 free(s);
9090 return false;
@@ -95,24 +95,24 @@ static bool pause_step(cage_agent *a, char **steer) {
9595
9696 // ---- provider and tool callbacks ------------------------------------------
9797
98-static void on_stream(const cage_stream_event *ev, void *user) {
98+static void on_stream(const tiny_stream_event *ev, void *user) {
9999 turn_state *st = user;
100100 if (!st->streaming) {
101101 st->streaming = true;
102- emit_phase(st->a, CAGE_PHASE_STREAMING, NULL);
102+ emit_phase(st->a, TINY_PHASE_STREAMING, NULL);
103103 }
104- cage_event e = {0};
104+ tiny_event e = {0};
105105 switch (ev->type) {
106- case CAGE_STREAM_TEXT_DELTA:
107- e.type = CAGE_EVENT_TEXT;
106+ case TINY_STREAM_TEXT_DELTA:
107+ e.type = TINY_EVENT_TEXT;
108108 e.u.text.delta = ev->delta;
109109 break;
110- case CAGE_STREAM_REASONING_DELTA:
111- e.type = CAGE_EVENT_REASONING;
110+ case TINY_STREAM_REASONING_DELTA:
111+ e.type = TINY_EVENT_REASONING;
112112 e.u.reasoning.delta = ev->delta;
113113 break;
114- case CAGE_STREAM_TOOL_CALL:
115- e.type = CAGE_EVENT_TOOL_CALL;
114+ case TINY_STREAM_TOOL_CALL:
115+ e.type = TINY_EVENT_TOOL_CALL;
116116 e.u.tool_call.name = ev->tool_name;
117117 e.u.tool_call.arguments = ev->tool_arguments;
118118 break;
@@ -124,38 +124,38 @@ static void on_stream(const cage_stream_event *ev, void *user) {
124124
125125 static void on_tool_output(const char *chunk, void *user) {
126126 turn_state *st = user;
127- cage_event e = {.type = CAGE_EVENT_TOOL_OUTPUT};
127+ tiny_event e = {.type = TINY_EVENT_TOOL_OUTPUT};
128128 e.u.tool_output.chunk = chunk;
129129 emit(st->a, &e);
130130 }
131131
132-static cage_tool_result run_tool(cage_agent *a, turn_state *st, const cage_block *b) {
132+static tiny_tool_result run_tool(tiny_agent *a, turn_state *st, const tiny_block *b) {
133133 const char *name = b->tool_name ? b->tool_name : "";
134134 const char *args = b->arguments ? b->arguments : "{}";
135135
136136 // Only the tools that can write get a tree diff around them.
137137 if (strcmp(name, "edit") != 0 && strcmp(name, "bash") != 0)
138- return cage_tool_run(name, args, a->model.supports_images, on_tool_output, st, a->cancel);
138+ return tiny_tool_run(name, args, a->model.supports_images, on_tool_output, st, a->cancel);
139139
140140 // The tool may write anywhere under the working directory, so a diff of the
141141 // tree around it is the only way to report what changed.
142142 struct timespec start;
143143 clock_gettime(CLOCK_REALTIME, &start);
144- struct cage_snapshot *before = cage_snapshot_capture(NULL);
145- cage_tool_result r =
146- cage_tool_run(name, args, a->model.supports_images, on_tool_output, st, a->cancel);
147- struct cage_snapshot *after = cage_snapshot_capture(&start);
148- r.diffs = cage_snapshot_diff(before, after, &r.diffs_len);
149- cage_snapshot_free(before);
150- cage_snapshot_free(after);
144+ struct tiny_snapshot *before = tiny_snapshot_capture(NULL);
145+ tiny_tool_result r =
146+ tiny_tool_run(name, args, a->model.supports_images, on_tool_output, st, a->cancel);
147+ struct tiny_snapshot *after = tiny_snapshot_capture(&start);
148+ r.diffs = tiny_snapshot_diff(before, after, &r.diffs_len);
149+ tiny_snapshot_free(before);
150+ tiny_snapshot_free(after);
151151 return r;
152152 }
153153
154154 // ---- the loop -------------------------------------------------------------
155155
156-void cage_agent_turn(cage_agent *a, const char *input) {
156+void tiny_agent_turn(tiny_agent *a, const char *input) {
157157 if (!a->model.model || !a->model.base_url) {
158- emit_simple(a, CAGE_EVENT_NO_MODEL);
158+ emit_simple(a, TINY_EVENT_NO_MODEL);
159159 return;
160160 }
161161
@@ -169,7 +169,7 @@ void cage_agent_turn(cage_agent *a, const char *input) {
169169 for (;;) {
170170 char *steer = NULL;
171171 if (!pause_step(a, &steer)) {
172- emit_simple(a, CAGE_EVENT_CANCELLED);
172+ emit_simple(a, TINY_EVENT_CANCELLED);
173173 return;
174174 }
175175 if (steer && steer[0] && push_user(a, steer, &perr) != 0) {
@@ -180,28 +180,28 @@ void cage_agent_turn(cage_agent *a, const char *input) {
180180 }
181181 free(steer);
182182
183- emit_phase(a, CAGE_PHASE_PREPARING, NULL);
183+ emit_phase(a, TINY_PHASE_PREPARING, NULL);
184184
185185 turn_state st = {.a = a, .streaming = false};
186- cage_context ctx = {
186+ tiny_context ctx = {
187187 .system_prompt = a->system_prompt,
188188 .tools = a->tools,
189189 .tools_len = a->tools_len,
190190 .messages = a->messages,
191191 .messages_len = a->messages_len,
192192 };
193- cage_stream_opts opts = {
193+ tiny_stream_opts opts = {
194194 .effort = a->model.effort,
195- .session_id = a->session ? cage_session_id(a->session) : NULL,
195+ .session_id = a->session ? tiny_session_id(a->session) : NULL,
196196 };
197197
198- emit_phase(a, CAGE_PHASE_WAITING_MODEL, NULL);
199- cage_message asst = {0};
198+ emit_phase(a, TINY_PHASE_WAITING_MODEL, NULL);
199+ tiny_message asst = {0};
200200 char *serr = NULL;
201- if (cage_provider_stream(&a->model, &ctx, &opts, on_stream, &st, a->cancel, &asst, &serr) != 0) {
201+ if (tiny_provider_stream(&a->model, &ctx, &opts, on_stream, &st, a->cancel, &asst, &serr) != 0) {
202202 emit_error(a, serr ? serr : "provider error");
203203 free(serr);
204- cage_message_free(&asst);
204+ tiny_message_free(&asst);
205205 return;
206206 }
207207
@@ -210,14 +210,14 @@ void cage_agent_turn(cage_agent *a, const char *input) {
210210 free(perr);
211211 return;
212212 }
213- char *json = cage_message_to_json(&asst);
214- cage_event me = {.type = CAGE_EVENT_MESSAGE};
213+ char *json = tiny_message_to_json(&asst);
214+ tiny_event me = {.type = TINY_EVENT_MESSAGE};
215215 me.u.message.json = json ? json : "{}";
216216 emit(a, &me);
217217 free(json);
218218
219219 if (asst.stop_reason && strcmp(asst.stop_reason, "aborted") == 0) {
220- emit_simple(a, CAGE_EVENT_CANCELLED);
220+ emit_simple(a, TINY_EVENT_CANCELLED);
221221 return;
222222 }
223223 if (asst.stop_reason && strcmp(asst.stop_reason, "error") == 0) {
@@ -227,18 +227,18 @@ void cage_agent_turn(cage_agent *a, const char *input) {
227227
228228 size_t calls = 0;
229229 for (size_t i = 0; i < asst.blocks_len; i++)
230- if (asst.blocks[i].type == CAGE_BLOCK_TOOL_CALL) calls++;
230+ if (asst.blocks[i].type == TINY_BLOCK_TOOL_CALL) calls++;
231231 if (calls == 0) {
232- emit_simple(a, CAGE_EVENT_COMPLETE);
232+ emit_simple(a, TINY_EVENT_COMPLETE);
233233 return;
234234 }
235235
236236 // Steering is held until every result of this assistant turn has landed.
237- cage_buf held = {0};
237+ tiny_buf held = {0};
238238 bool cancelled = false;
239239 for (size_t i = 0; i < asst.blocks_len && !cancelled; i++) {
240- cage_block *b = &asst.blocks[i];
241- if (b->type != CAGE_BLOCK_TOOL_CALL) continue;
240+ tiny_block *b = &asst.blocks[i];
241+ if (b->type != TINY_BLOCK_TOOL_CALL) continue;
242242
243243 char *s2 = NULL;
244244 if (!pause_step(a, &s2)) {
@@ -252,12 +252,12 @@ void cage_agent_turn(cage_agent *a, const char *input) {
252252 }
253253 free(s2);
254254
255- emit_phase(a, CAGE_PHASE_RUNNING_TOOL, b->tool_name);
256- cage_tool_result tr = run_tool(a, &st, b);
257- cage_message tm = cage_message_tool(b->tool_call_id, tr.text, tr.is_error);
255+ emit_phase(a, TINY_PHASE_RUNNING_TOOL, b->tool_name);
256+ tiny_tool_result tr = run_tool(a, &st, b);
257+ tiny_message tm = tiny_message_tool(b->tool_call_id, tr.text, tr.is_error);
258258 free(tr.text);
259259 for (size_t k = 0; k < tr.images_len; k++) {
260- cage_block *ib = cage_message_add_block(&tm, CAGE_BLOCK_IMAGE);
260+ tiny_block *ib = tiny_message_add_block(&tm, TINY_BLOCK_IMAGE);
261261 ib->media_type = xstrdup(tr.images[k].media_type);
262262 ib->data = xstrdup(tr.images[k].data);
263263 free(tr.images[k].media_type);
@@ -267,24 +267,24 @@ void cage_agent_turn(cage_agent *a, const char *input) {
267267
268268 if (push_message(a, &tm, &perr) != 0) {
269269 free(held.data);
270- cage_file_diffs_free(tr.diffs, tr.diffs_len);
270+ tiny_file_diffs_free(tr.diffs, tr.diffs_len);
271271 emit_error(a, perr);
272272 free(perr);
273273 return;
274274 }
275- cage_event re = {.type = CAGE_EVENT_TOOL_RESULT};
275+ tiny_event re = {.type = TINY_EVENT_TOOL_RESULT};
276276 re.u.tool_result.name = b->tool_name;
277277 re.u.tool_result.text = tm.blocks_len ? tm.blocks[0].text : "";
278278 re.u.tool_result.is_error = tm.is_error;
279279 re.u.tool_result.diffs = tr.diffs;
280280 re.u.tool_result.diffs_len = tr.diffs_len;
281281 emit(a, &re);
282- cage_file_diffs_free(tr.diffs, tr.diffs_len);
282+ tiny_file_diffs_free(tr.diffs, tr.diffs_len);
283283 }
284284
285285 if (cancelled) {
286286 free(held.data);
287- emit_simple(a, CAGE_EVENT_CANCELLED);
287+ emit_simple(a, TINY_EVENT_CANCELLED);
288288 return;
289289 }
290290 if (held.len && push_user(a, held.data, &perr) != 0) {
@@ -297,8 +297,8 @@ void cage_agent_turn(cage_agent *a, const char *input) {
297297 }
298298 }
299299
300-void cage_agent_free(cage_agent *a) {
301- for (size_t i = 0; i < a->messages_len; i++) cage_message_free(&a->messages[i]);
300+void tiny_agent_free(tiny_agent *a) {
301+ for (size_t i = 0; i < a->messages_len; i++) tiny_message_free(&a->messages[i]);
302302 free(a->messages);
303303 a->messages = NULL;
304304 a->messages_len = 0;
src/agent.h+11−11
@@ -1,7 +1,7 @@
1-// cage agent: the loop that binds provider, session, and tool.
1+// tiny agent: the loop that binds provider, session, and tool.
22
3-#ifndef CAGE_AGENT_H
4-#define CAGE_AGENT_H
3+#ifndef TINY_AGENT_H
4+#define TINY_AGENT_H
55
66 #include <stdbool.h>
77
@@ -12,16 +12,16 @@
1212
1313 typedef struct {
1414 // Model and request shape.
15- cage_model model;
15+ tiny_model model;
1616 const char *system_prompt;
17- const cage_tool *tools;
17+ const tiny_tool *tools;
1818 size_t tools_len;
1919
2020 // Persistence. NULL disables session logging.
21- cage_session *session;
21+ tiny_session *session;
2222
2323 // Projection. Both projections receive the same event stream.
24- cage_event_fn on_event;
24+ tiny_event_fn on_event;
2525 void *user;
2626
2727 // Interruption. All optional; NULL means the feature is absent.
@@ -31,16 +31,16 @@ typedef struct {
3131 const volatile bool *cancel;
3232
3333 // Transcript, owned by the agent and kept across turns.
34- cage_message *messages;
34+ tiny_message *messages;
3535 size_t messages_len;
36-} cage_agent;
36+} tiny_agent;
3737
3838 // Appends `input` as a user message, then loops until the model stops without
3939 // tool calls. Every outcome is reported as an event: complete, cancelled, or
4040 // error. The caller owns `model`, `runtime`, `session`, and the tools.
41-void cage_agent_turn(cage_agent *a, const char *input);
41+void tiny_agent_turn(tiny_agent *a, const char *input);
4242
4343 // Frees the transcript. Does not free the runtime, session, or model strings.
44-void cage_agent_free(cage_agent *a);
44+void tiny_agent_free(tiny_agent *a);
4545
4646 #endif
src/api.h+24−24
@@ -1,7 +1,7 @@
11 // Internal contract between the provider dispatcher and each API adapter.
22
3-#ifndef CAGE_API_H
4-#define CAGE_API_H
3+#ifndef TINY_API_H
4+#define TINY_API_H
55
66 #include <yyjson.h>
77
@@ -9,42 +9,42 @@
99
1010 // Adds a tool's "name", "description", and schema (under `params_key`) to `obj`.
1111 // Shared by every adapter's tool serialization.
12-void cage_json_tool(yyjson_mut_doc *doc, yyjson_mut_val *obj, const cage_tool *t,
12+void tiny_json_tool(yyjson_mut_doc *doc, yyjson_mut_val *obj, const tiny_tool *t,
1313 const char *params_key);
1414
1515 // Emits one delta to the adapter's stream callback, if any.
16-void cage_emit_delta(cage_stream_fn emit, void *user, cage_stream_type type, const char *delta);
16+void tiny_emit_delta(tiny_stream_fn emit, void *user, tiny_stream_type type, const char *delta);
1717
1818 // Appends a text/thinking block when `text` is non-NULL and non-empty.
19-void cage_add_text_block(cage_message *out, cage_block_type type, const char *text);
19+void tiny_add_text_block(tiny_message *out, tiny_block_type type, const char *text);
2020
2121 // Appends a tool-call block (defaulting empty arguments to "{}") and emits the
22-// corresponding CAGE_STREAM_TOOL_CALL event.
23-void cage_add_tool_block(cage_message *out, const char *id, const char *name,
24- const char *args, cage_stream_fn emit, void *user);
22+// corresponding TINY_STREAM_TOOL_CALL event.
23+void tiny_add_tool_block(tiny_message *out, const char *id, const char *name,
24+ const char *args, tiny_stream_fn emit, void *user);
2525
26-int cage_openai_completions_stream(const cage_model *model, const cage_context *ctx,
27- const cage_stream_opts *opts,
28- cage_stream_fn emit, void *user,
26+int tiny_openai_completions_stream(const tiny_model *model, const tiny_context *ctx,
27+ const tiny_stream_opts *opts,
28+ tiny_stream_fn emit, void *user,
2929 const volatile bool *cancel,
30- cage_message *out, char **err);
30+ tiny_message *out, char **err);
3131
32-int cage_openai_responses_stream(const cage_model *model, const cage_context *ctx,
33- const cage_stream_opts *opts,
34- cage_stream_fn emit, void *user,
32+int tiny_openai_responses_stream(const tiny_model *model, const tiny_context *ctx,
33+ const tiny_stream_opts *opts,
34+ tiny_stream_fn emit, void *user,
3535 const volatile bool *cancel,
36- cage_message *out, char **err);
36+ tiny_message *out, char **err);
3737
38-int cage_anthropic_messages_stream(const cage_model *model, const cage_context *ctx,
39- const cage_stream_opts *opts,
40- cage_stream_fn emit, void *user,
38+int tiny_anthropic_messages_stream(const tiny_model *model, const tiny_context *ctx,
39+ const tiny_stream_opts *opts,
40+ tiny_stream_fn emit, void *user,
4141 const volatile bool *cancel,
42- cage_message *out, char **err);
42+ tiny_message *out, char **err);
4343
44-int cage_google_generative_ai_stream(const cage_model *model, const cage_context *ctx,
45- const cage_stream_opts *opts,
46- cage_stream_fn emit, void *user,
44+int tiny_google_generative_ai_stream(const tiny_model *model, const tiny_context *ctx,
45+ const tiny_stream_opts *opts,
46+ tiny_stream_fn emit, void *user,
4747 const volatile bool *cancel,
48- cage_message *out, char **err);
48+ tiny_message *out, char **err);
4949
5050 #endif
src/api/anthropic_messages.c+46−46
@@ -16,7 +16,7 @@
1616 // ---- request --------------------------------------------------------------
1717
1818 static void add_image_block(yyjson_mut_doc *doc, yyjson_mut_val *content,
19- const cage_block *b) {
19+ const tiny_block *b) {
2020 yyjson_mut_val *img = yyjson_mut_obj(doc);
2121 yyjson_mut_arr_add_val(content, img);
2222 yyjson_mut_obj_add_strcpy(doc, img, "type", "image");
@@ -27,7 +27,7 @@ static void add_image_block(yyjson_mut_doc *doc, yyjson_mut_val *content,
2727 yyjson_mut_obj_add_strcpy(doc, src, "data", b->data ? b->data : "");
2828 }
2929
30-static void add_tool_result(yyjson_mut_doc *doc, yyjson_mut_val *messages, const cage_message *m) {
30+static void add_tool_result(yyjson_mut_doc *doc, yyjson_mut_val *messages, const tiny_message *m) {
3131 yyjson_mut_val *um = yyjson_mut_obj(doc);
3232 yyjson_mut_arr_add_val(messages, um);
3333 yyjson_mut_obj_add_strcpy(doc, um, "role", "user");
@@ -40,11 +40,11 @@ static void add_tool_result(yyjson_mut_doc *doc, yyjson_mut_val *messages, const
4040 yyjson_mut_obj_add_strcpy(doc, tr, "tool_use_id", m->tool_call_id ? m->tool_call_id : "");
4141 if (m->is_error) yyjson_mut_obj_add_bool(doc, tr, "is_error", true);
4242
43- bool has_images = cage_message_has_image(m);
43+ bool has_images = tiny_message_has_image(m);
4444 if (!has_images) {
45- cage_buf t = {0};
45+ tiny_buf t = {0};
4646 for (size_t i = 0; i < m->blocks_len; i++)
47- if (m->blocks[i].type == CAGE_BLOCK_TEXT && m->blocks[i].text)
47+ if (m->blocks[i].type == TINY_BLOCK_TEXT && m->blocks[i].text)
4848 buf_add(&t, m->blocks[i].text, strlen(m->blocks[i].text));
4949 yyjson_mut_obj_add_strcpy(doc, tr, "content", t.data ? t.data : "");
5050 free(t.data);
@@ -53,34 +53,34 @@ static void add_tool_result(yyjson_mut_doc *doc, yyjson_mut_val *messages, const
5353 yyjson_mut_val *blocks = yyjson_mut_arr(doc);
5454 yyjson_mut_obj_add_val(doc, tr, "content", blocks);
5555 for (size_t i = 0; i < m->blocks_len; i++) {
56- const cage_block *b = &m->blocks[i];
57- if (b->type == CAGE_BLOCK_TEXT) {
56+ const tiny_block *b = &m->blocks[i];
57+ if (b->type == TINY_BLOCK_TEXT) {
5858 yyjson_mut_val *tx = yyjson_mut_obj(doc);
5959 yyjson_mut_arr_add_val(blocks, tx);
6060 yyjson_mut_obj_add_strcpy(doc, tx, "type", "text");
6161 yyjson_mut_obj_add_strcpy(doc, tx, "text", b->text ? b->text : "");
62- } else if (b->type == CAGE_BLOCK_IMAGE) {
62+ } else if (b->type == TINY_BLOCK_IMAGE) {
6363 add_image_block(doc, blocks, b);
6464 }
6565 }
6666 }
6767
68-static void add_message(yyjson_mut_doc *doc, yyjson_mut_val *messages, const cage_message *m) {
68+static void add_message(yyjson_mut_doc *doc, yyjson_mut_val *messages, const tiny_message *m) {
6969 yyjson_mut_val *o = yyjson_mut_obj(doc);
7070 yyjson_mut_arr_add_val(messages, o);
71- yyjson_mut_obj_add_strcpy(doc, o, "role", m->role == CAGE_ROLE_ASSISTANT ? "assistant" : "user");
71+ yyjson_mut_obj_add_strcpy(doc, o, "role", m->role == TINY_ROLE_ASSISTANT ? "assistant" : "user");
7272 yyjson_mut_val *content = yyjson_mut_arr(doc);
7373 yyjson_mut_obj_add_val(doc, o, "content", content);
7474 for (size_t i = 0; i < m->blocks_len; i++) {
75- const cage_block *b = &m->blocks[i];
76- if (b->type == CAGE_BLOCK_TEXT) {
75+ const tiny_block *b = &m->blocks[i];
76+ if (b->type == TINY_BLOCK_TEXT) {
7777 yyjson_mut_val *tx = yyjson_mut_obj(doc);
7878 yyjson_mut_arr_add_val(content, tx);
7979 yyjson_mut_obj_add_strcpy(doc, tx, "type", "text");
8080 yyjson_mut_obj_add_strcpy(doc, tx, "text", b->text ? b->text : "");
81- } else if (b->type == CAGE_BLOCK_IMAGE) {
81+ } else if (b->type == TINY_BLOCK_IMAGE) {
8282 add_image_block(doc, content, b);
83- } else if (b->type == CAGE_BLOCK_TOOL_CALL) {
83+ } else if (b->type == TINY_BLOCK_TOOL_CALL) {
8484 yyjson_mut_val *tu = yyjson_mut_obj(doc);
8585 yyjson_mut_arr_add_val(content, tu);
8686 yyjson_mut_obj_add_strcpy(doc, tu, "type", "tool_use");
@@ -99,15 +99,15 @@ static void add_message(yyjson_mut_doc *doc, yyjson_mut_val *messages, const cag
9999 }
100100 }
101101
102-static void add_tools(yyjson_mut_doc *doc, yyjson_mut_val *root, const cage_context *ctx) {
102+static void add_tools(yyjson_mut_doc *doc, yyjson_mut_val *root, const tiny_context *ctx) {
103103 if (ctx->tools_len == 0) return;
104104 yyjson_mut_val *tools = yyjson_mut_arr(doc);
105105 yyjson_mut_obj_add_val(doc, root, "tools", tools);
106106 for (size_t i = 0; i < ctx->tools_len; i++) {
107- const cage_tool *t = &ctx->tools[i];
107+ const tiny_tool *t = &ctx->tools[i];
108108 yyjson_mut_val *tool = yyjson_mut_obj(doc);
109109 yyjson_mut_arr_add_val(tools, tool);
110- cage_json_tool(doc, tool, t, "input_schema");
110+ tiny_json_tool(doc, tool, t, "input_schema");
111111 }
112112 }
113113
@@ -123,8 +123,8 @@ static long budget_for(const char *effort) {
123123 return 0;
124124 }
125125
126-static char *build_request(const cage_model *model, const cage_context *ctx,
127- const cage_stream_opts *opts) {
126+static char *build_request(const tiny_model *model, const tiny_context *ctx,
127+ const tiny_stream_opts *opts) {
128128 yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
129129 yyjson_mut_val *root = yyjson_mut_obj(doc);
130130 yyjson_mut_doc_set_root(doc, root);
@@ -148,10 +148,10 @@ static char *build_request(const cage_model *model, const cage_context *ctx,
148148 yyjson_mut_val *messages = yyjson_mut_arr(doc);
149149 yyjson_mut_obj_add_val(doc, root, "messages", messages);
150150 for (size_t i = 0; i < ctx->messages_len;) {
151- if (ctx->messages[i].role == CAGE_ROLE_TOOL) {
151+ if (ctx->messages[i].role == TINY_ROLE_TOOL) {
152152 // All results of one assistant turn share a single user message.
153153 size_t j = i;
154- for (; j < ctx->messages_len && ctx->messages[j].role == CAGE_ROLE_TOOL; j++)
154+ for (; j < ctx->messages_len && ctx->messages[j].role == TINY_ROLE_TOOL; j++)
155155 add_tool_result(doc, messages, &ctx->messages[j]);
156156 i = j;
157157 } else {
@@ -174,10 +174,10 @@ enum { BLK_TEXT, BLK_THINKING, BLK_TOOL };
174174
175175 typedef struct {
176176 int type;
177- cage_buf text;
177+ tiny_buf text;
178178 char *id;
179179 char *name;
180- cage_buf args;
180+ tiny_buf args;
181181 } block_acc;
182182
183183 typedef struct {
@@ -187,7 +187,7 @@ typedef struct {
187187 long tokens_out;
188188 char *stop_reason;
189189 char *error;
190- cage_stream_fn emit;
190+ tiny_stream_fn emit;
191191 void *user;
192192 } anth_state;
193193
@@ -215,7 +215,7 @@ static void on_data(const char *json, size_t len, void *user) {
215215 if (strcmp(type, "error") == 0) {
216216 yyjson_val *err = yyjson_obj_get(root, "error");
217217 yyjson_val *m = yyjson_is_obj(err) ? yyjson_obj_get(err, "message") : NULL;
218- cage_set_str(&st->error, yyjson_is_str(m) ? yyjson_get_str(m) : "stream: provider error");
218+ tiny_set_str(&st->error, yyjson_is_str(m) ? yyjson_get_str(m) : "stream: provider error");
219219 } else if (strcmp(type, "message_start") == 0) {
220220 yyjson_val *msg = yyjson_obj_get(root, "message");
221221 yyjson_val *usage = yyjson_is_obj(msg) ? yyjson_obj_get(msg, "usage") : NULL;
@@ -238,8 +238,8 @@ static void on_data(const char *json, size_t len, void *user) {
238238 b->type = BLK_TOOL;
239239 yyjson_val *id = yyjson_obj_get(cb, "id");
240240 yyjson_val *nm = yyjson_obj_get(cb, "name");
241- if (yyjson_is_str(id)) cage_set_str(&b->id, yyjson_get_str(id));
242- if (yyjson_is_str(nm)) cage_set_str(&b->name, yyjson_get_str(nm));
241+ if (yyjson_is_str(id)) tiny_set_str(&b->id, yyjson_get_str(id));
242+ if (yyjson_is_str(nm)) tiny_set_str(&b->name, yyjson_get_str(nm));
243243 } else if (strcmp(bts, "thinking") == 0 || strcmp(bts, "redacted_thinking") == 0) {
244244 b->type = BLK_THINKING;
245245 } else {
@@ -264,13 +264,13 @@ static void on_data(const char *json, size_t len, void *user) {
264264 yyjson_val *t = yyjson_obj_get(d, "text");
265265 if (yyjson_is_str(t) && yyjson_get_str(t)[0]) {
266266 buf_add(&b->text, yyjson_get_str(t), strlen(yyjson_get_str(t)));
267- cage_emit_delta(st->emit, st->user, CAGE_STREAM_TEXT_DELTA, yyjson_get_str(t));
267+ tiny_emit_delta(st->emit, st->user, TINY_STREAM_TEXT_DELTA, yyjson_get_str(t));
268268 }
269269 } else if (strcmp(dts, "thinking_delta") == 0) {
270270 yyjson_val *t = yyjson_obj_get(d, "thinking");
271271 if (yyjson_is_str(t) && yyjson_get_str(t)[0]) {
272272 buf_add(&b->text, yyjson_get_str(t), strlen(yyjson_get_str(t)));
273- cage_emit_delta(st->emit, st->user, CAGE_STREAM_REASONING_DELTA, yyjson_get_str(t));
273+ tiny_emit_delta(st->emit, st->user, TINY_STREAM_REASONING_DELTA, yyjson_get_str(t));
274274 }
275275 } else if (strcmp(dts, "input_json_delta") == 0) {
276276 yyjson_val *p = yyjson_obj_get(d, "partial_json");
@@ -279,7 +279,7 @@ static void on_data(const char *json, size_t len, void *user) {
279279 } else if (strcmp(type, "message_delta") == 0) {
280280 yyjson_val *d = yyjson_obj_get(root, "delta");
281281 yyjson_val *sr = yyjson_is_obj(d) ? yyjson_obj_get(d, "stop_reason") : NULL;
282- if (yyjson_is_str(sr)) cage_set_str(&st->stop_reason, yyjson_get_str(sr));
282+ if (yyjson_is_str(sr)) tiny_set_str(&st->stop_reason, yyjson_get_str(sr));
283283 yyjson_val *usage = yyjson_obj_get(root, "usage");
284284 if (yyjson_is_obj(usage)) {
285285 yyjson_val *v;
@@ -307,7 +307,7 @@ static const char *map_stop(const char *reason, bool has_calls) {
307307 return "stop";
308308 }
309309
310-static void finalize(anth_state *st, cage_message *out) {
310+static void finalize(anth_state *st, tiny_message *out) {
311311 bool has_calls = false;
312312 for (size_t i = 0; i < st->blocks_len; i++) {
313313 block_acc *b = &st->blocks[i];
@@ -316,14 +316,14 @@ static void finalize(anth_state *st, cage_message *out) {
316316 for (size_t i = 0; i < st->blocks_len; i++) {
317317 block_acc *b = &st->blocks[i];
318318 if (b->type == BLK_THINKING)
319- cage_add_text_block(out, CAGE_BLOCK_THINKING, b->text.data);
319+ tiny_add_text_block(out, TINY_BLOCK_THINKING, b->text.data);
320320 else if (b->type == BLK_TEXT)
321- cage_add_text_block(out, CAGE_BLOCK_TEXT, b->text.data);
321+ tiny_add_text_block(out, TINY_BLOCK_TEXT, b->text.data);
322322 }
323323 for (size_t i = 0; i < st->blocks_len; i++) {
324324 block_acc *b = &st->blocks[i];
325325 if (b->type != BLK_TOOL) continue;
326- cage_add_tool_block(out, b->id, b->name, b->args.len ? b->args.data : NULL, st->emit, st->user);
326+ tiny_add_tool_block(out, b->id, b->name, b->args.len ? b->args.data : NULL, st->emit, st->user);
327327 }
328328 out->tokens_in = st->tokens_in;
329329 out->tokens_out = st->tokens_out;
@@ -334,21 +334,21 @@ static void finalize(anth_state *st, cage_message *out) {
334334 // ---- transport ------------------------------------------------------------
335335
336336
337-int cage_anthropic_messages_stream(const cage_model *model, const cage_context *ctx,
338- const cage_stream_opts *opts,
339- cage_stream_fn emit, void *user,
337+int tiny_anthropic_messages_stream(const tiny_model *model, const tiny_context *ctx,
338+ const tiny_stream_opts *opts,
339+ tiny_stream_fn emit, void *user,
340340 const volatile bool *cancel,
341- cage_message *out, char **err) {
341+ tiny_message *out, char **err) {
342342 if (err) *err = NULL;
343343 memset(out, 0, sizeof *out);
344- out->role = CAGE_ROLE_ASSISTANT;
344+ out->role = TINY_ROLE_ASSISTANT;
345345
346- char *url = cage_url_endpoint(model->base_url, "v1/messages");
347- if (!url) return cage_fail(err, "provider: no base url");
346+ char *url = tiny_url_endpoint(model->base_url, "v1/messages");
347+ if (!url) return tiny_fail(err, "provider: no base url");
348348 char *body = build_request(model, ctx, opts);
349349 if (!body) {
350350 free(url);
351- return cage_fail(err, "provider: cannot build request");
351+ return tiny_fail(err, "provider: cannot build request");
352352 }
353353
354354 anth_state st = {0};
@@ -356,15 +356,15 @@ int cage_anthropic_messages_stream(const cage_model *model, const cage_context *
356356 st.user = user;
357357
358358 const char *extra[] = {"anthropic-version: " ANTHROPIC_VERSION, NULL};
359- cage_api_result r = cage_api_post(url, body, "x-api-key: ", model->api_key,
359+ tiny_api_result r = tiny_api_post(url, body, "x-api-key: ", model->api_key,
360360 extra, cancel, on_data, &st, st.error, err);
361361
362362 int rc = 0;
363- if (r == CAGE_API_ABORTED) {
363+ if (r == TINY_API_ABORTED) {
364364 out->stop_reason = xstrdup("aborted");
365- } else if (r == CAGE_API_TRANSPORT_ERROR) {
365+ } else if (r == TINY_API_TRANSPORT_ERROR) {
366366 rc = -1;
367- } else if (r == CAGE_API_STREAM_ERROR) {
367+ } else if (r == TINY_API_STREAM_ERROR) {
368368 out->stop_reason = xstrdup("error");
369369 out->error_message = xstrdup(st.error);
370370 } else {
src/api/google_generative_ai.c+40−40
@@ -19,7 +19,7 @@ static void add_text_part(yyjson_mut_doc *doc, yyjson_mut_val *parts, const char
1919 yyjson_mut_obj_add_strcpy(doc, p, "text", text ? text : "");
2020 }
2121
22-static void add_function_call(yyjson_mut_doc *doc, yyjson_mut_val *parts, const cage_block *b) {
22+static void add_function_call(yyjson_mut_doc *doc, yyjson_mut_val *parts, const tiny_block *b) {
2323 yyjson_mut_val *p = yyjson_mut_obj(doc);
2424 yyjson_mut_arr_add_val(parts, p);
2525 yyjson_mut_val *fc = yyjson_mut_obj(doc);
@@ -34,36 +34,36 @@ static void add_function_call(yyjson_mut_doc *doc, yyjson_mut_val *parts, const
3434 if (adoc) yyjson_doc_free(adoc);
3535 }
3636
37-static void add_message(yyjson_mut_doc *doc, yyjson_mut_val *contents, const cage_message *m) {
37+static void add_message(yyjson_mut_doc *doc, yyjson_mut_val *contents, const tiny_message *m) {
3838 yyjson_mut_val *o = yyjson_mut_obj(doc);
3939 yyjson_mut_arr_add_val(contents, o);
40- yyjson_mut_obj_add_strcpy(doc, o, "role", m->role == CAGE_ROLE_ASSISTANT ? "model" : "user");
40+ yyjson_mut_obj_add_strcpy(doc, o, "role", m->role == TINY_ROLE_ASSISTANT ? "model" : "user");
4141 yyjson_mut_val *parts = yyjson_mut_arr(doc);
4242 yyjson_mut_obj_add_val(doc, o, "parts", parts);
4343 for (size_t i = 0; i < m->blocks_len; i++) {
44- const cage_block *b = &m->blocks[i];
45- if (b->type == CAGE_BLOCK_TEXT) {
44+ const tiny_block *b = &m->blocks[i];
45+ if (b->type == TINY_BLOCK_TEXT) {
4646 add_text_part(doc, parts, b->text);
47- } else if (b->type == CAGE_BLOCK_IMAGE) {
47+ } else if (b->type == TINY_BLOCK_IMAGE) {
4848 yyjson_mut_val *p = yyjson_mut_obj(doc);
4949 yyjson_mut_arr_add_val(parts, p);
5050 yyjson_mut_val *inl = yyjson_mut_obj(doc);
5151 yyjson_mut_obj_add_val(doc, p, "inlineData", inl);
5252 yyjson_mut_obj_add_strcpy(doc, inl, "mimeType", b->media_type ? b->media_type : "");
5353 yyjson_mut_obj_add_strcpy(doc, inl, "data", b->data ? b->data : "");
54- } else if (b->type == CAGE_BLOCK_TOOL_CALL) {
54+ } else if (b->type == TINY_BLOCK_TOOL_CALL) {
5555 add_function_call(doc, parts, b);
5656 }
5757 }
5858 }
5959
6060 // A run of tool results becomes one user turn of functionResponse parts.
61-static const char *tool_name_for(const cage_context *ctx, const char *id) {
61+static const char *tool_name_for(const tiny_context *ctx, const char *id) {
6262 for (size_t i = 0; i < ctx->messages_len; i++) {
63- const cage_message *m = &ctx->messages[i];
63+ const tiny_message *m = &ctx->messages[i];
6464 for (size_t k = 0; k < m->blocks_len; k++) {
65- const cage_block *b = &m->blocks[k];
66- if (b->type == CAGE_BLOCK_TOOL_CALL && b->tool_call_id && id &&
65+ const tiny_block *b = &m->blocks[k];
66+ if (b->type == TINY_BLOCK_TOOL_CALL && b->tool_call_id && id &&
6767 strcmp(b->tool_call_id, id) == 0)
6868 return b->tool_name ? b->tool_name : "";
6969 }
@@ -72,15 +72,15 @@ static const char *tool_name_for(const cage_context *ctx, const char *id) {
7272 }
7373
7474 static void add_tool_results(yyjson_mut_doc *doc, yyjson_mut_val *contents,
75- const cage_context *ctx, size_t from, size_t to) {
75+ const tiny_context *ctx, size_t from, size_t to) {
7676 yyjson_mut_val *o = yyjson_mut_obj(doc);
7777 yyjson_mut_arr_add_val(contents, o);
7878 yyjson_mut_obj_add_strcpy(doc, o, "role", "user");
7979 yyjson_mut_val *parts = yyjson_mut_arr(doc);
8080 yyjson_mut_obj_add_val(doc, o, "parts", parts);
8181 for (size_t i = from; i < to; i++) {
82- const cage_message *m = &ctx->messages[i];
83- char *t = cage_message_text(m);
82+ const tiny_message *m = &ctx->messages[i];
83+ char *t = tiny_message_text(m);
8484 yyjson_mut_val *p = yyjson_mut_obj(doc);
8585 yyjson_mut_arr_add_val(parts, p);
8686 yyjson_mut_val *fr = yyjson_mut_obj(doc);
@@ -93,7 +93,7 @@ static void add_tool_results(yyjson_mut_doc *doc, yyjson_mut_val *contents,
9393 }
9494 }
9595
96-static void add_tools(yyjson_mut_doc *doc, yyjson_mut_val *root, const cage_context *ctx) {
96+static void add_tools(yyjson_mut_doc *doc, yyjson_mut_val *root, const tiny_context *ctx) {
9797 if (ctx->tools_len == 0) return;
9898 yyjson_mut_val *tools = yyjson_mut_arr(doc);
9999 yyjson_mut_obj_add_val(doc, root, "tools", tools);
@@ -104,7 +104,7 @@ static void add_tools(yyjson_mut_doc *doc, yyjson_mut_val *root, const cage_cont
104104 for (size_t i = 0; i < ctx->tools_len; i++) {
105105 yyjson_mut_val *d = yyjson_mut_obj(doc);
106106 yyjson_mut_arr_add_val(decls, d);
107- cage_json_tool(doc, d, &ctx->tools[i], "parametersJsonSchema");
107+ tiny_json_tool(doc, d, &ctx->tools[i], "parametersJsonSchema");
108108 }
109109 }
110110
@@ -120,7 +120,7 @@ static long budget_for(const char *effort) {
120120 return -1;
121121 }
122122
123-static char *build_request(const cage_context *ctx, const cage_stream_opts *opts) {
123+static char *build_request(const tiny_context *ctx, const tiny_stream_opts *opts) {
124124 yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
125125 yyjson_mut_val *root = yyjson_mut_obj(doc);
126126 yyjson_mut_doc_set_root(doc, root);
@@ -128,9 +128,9 @@ static char *build_request(const cage_context *ctx, const cage_stream_opts *opts
128128 yyjson_mut_val *contents = yyjson_mut_arr(doc);
129129 yyjson_mut_obj_add_val(doc, root, "contents", contents);
130130 for (size_t i = 0; i < ctx->messages_len;) {
131- if (ctx->messages[i].role == CAGE_ROLE_TOOL) {
131+ if (ctx->messages[i].role == TINY_ROLE_TOOL) {
132132 size_t j = i;
133- for (; j < ctx->messages_len && ctx->messages[j].role == CAGE_ROLE_TOOL; j++) {}
133+ for (; j < ctx->messages_len && ctx->messages[j].role == TINY_ROLE_TOOL; j++) {}
134134 add_tool_results(doc, contents, ctx, i, j);
135135 i = j;
136136 } else {
@@ -175,12 +175,12 @@ static char *build_request(const cage_context *ctx, const cage_stream_opts *opts
175175 typedef struct {
176176 char *id;
177177 char *name;
178- cage_buf args;
178+ tiny_buf args;
179179 } gcall;
180180
181181 typedef struct {
182- cage_buf text;
183- cage_buf reasoning;
182+ tiny_buf text;
183+ tiny_buf reasoning;
184184 gcall *calls;
185185 size_t calls_len;
186186 long tokens_in;
@@ -188,7 +188,7 @@ typedef struct {
188188 long tokens_total;
189189 char *finish;
190190 char *error;
191- cage_stream_fn emit;
191+ tiny_stream_fn emit;
192192 void *user;
193193 } google_state;
194194
@@ -250,10 +250,10 @@ static void on_data(const char *json, size_t len, void *user) {
250250 const char *s = yyjson_get_str(txt);
251251 if (yyjson_is_bool(thought) && yyjson_get_bool(thought)) {
252252 buf_add(&st->reasoning, s, strlen(s));
253- cage_emit_delta(st->emit, st->user, CAGE_STREAM_REASONING_DELTA, s);
253+ tiny_emit_delta(st->emit, st->user, TINY_STREAM_REASONING_DELTA, s);
254254 } else {
255255 buf_add(&st->text, s, strlen(s));
256- cage_emit_delta(st->emit, st->user, CAGE_STREAM_TEXT_DELTA, s);
256+ tiny_emit_delta(st->emit, st->user, TINY_STREAM_TEXT_DELTA, s);
257257 }
258258 }
259259 }
@@ -288,12 +288,12 @@ static void free_state(google_state *st) {
288288 free(st->error);
289289 }
290290
291-static void finalize(google_state *st, cage_message *out) {
292- cage_add_text_block(out, CAGE_BLOCK_THINKING, st->reasoning.data);
293- cage_add_text_block(out, CAGE_BLOCK_TEXT, st->text.data);
291+static void finalize(google_state *st, tiny_message *out) {
292+ tiny_add_text_block(out, TINY_BLOCK_THINKING, st->reasoning.data);
293+ tiny_add_text_block(out, TINY_BLOCK_TEXT, st->text.data);
294294 for (size_t i = 0; i < st->calls_len; i++) {
295295 gcall *c = &st->calls[i];
296- cage_add_tool_block(out, c->id, c->name, c->args.len ? c->args.data : NULL, st->emit, st->user);
296+ tiny_add_tool_block(out, c->id, c->name, c->args.len ? c->args.data : NULL, st->emit, st->user);
297297 }
298298 out->tokens_in = st->tokens_in;
299299 out->tokens_out = st->tokens_out;
@@ -324,36 +324,36 @@ static char *endpoint_url(const char *base, const char *model) {
324324 return url;
325325 }
326326
327-int cage_google_generative_ai_stream(const cage_model *model, const cage_context *ctx,
328- const cage_stream_opts *opts,
329- cage_stream_fn emit, void *user,
327+int tiny_google_generative_ai_stream(const tiny_model *model, const tiny_context *ctx,
328+ const tiny_stream_opts *opts,
329+ tiny_stream_fn emit, void *user,
330330 const volatile bool *cancel,
331- cage_message *out, char **err) {
331+ tiny_message *out, char **err) {
332332 if (err) *err = NULL;
333333 memset(out, 0, sizeof *out);
334- out->role = CAGE_ROLE_ASSISTANT;
334+ out->role = TINY_ROLE_ASSISTANT;
335335
336336 char *url = endpoint_url(model->base_url, model->model);
337- if (!url) return cage_fail(err, "provider: no base url");
337+ if (!url) return tiny_fail(err, "provider: no base url");
338338 char *body = build_request(ctx, opts);
339339 if (!body) {
340340 free(url);
341- return cage_fail(err, "provider: cannot build request");
341+ return tiny_fail(err, "provider: cannot build request");
342342 }
343343
344344 google_state st = {0};
345345 st.emit = emit;
346346 st.user = user;
347347
348- cage_api_result r = cage_api_post(url, body, "x-goog-api-key: ", model->api_key,
348+ tiny_api_result r = tiny_api_post(url, body, "x-goog-api-key: ", model->api_key,
349349 NULL, cancel, on_data, &st, st.error, err);
350350
351351 int rc = 0;
352- if (r == CAGE_API_ABORTED) {
352+ if (r == TINY_API_ABORTED) {
353353 out->stop_reason = xstrdup("aborted");
354- } else if (r == CAGE_API_TRANSPORT_ERROR) {
354+ } else if (r == TINY_API_TRANSPORT_ERROR) {
355355 rc = -1;
356- } else if (r == CAGE_API_STREAM_ERROR) {
356+ } else if (r == TINY_API_STREAM_ERROR) {
357357 out->stop_reason = xstrdup("error");
358358 out->error_message = xstrdup(st.error);
359359 } else {
src/api/http.c+17−17
@@ -10,13 +10,13 @@
1010 #include "util.h"
1111
1212 typedef struct {
13- cage_sse sse;
13+ tiny_sse sse;
1414 char *raw;
1515 size_t raw_len;
1616 size_t raw_cap;
1717 long status;
1818 const volatile bool *cancel;
19- cage_http_data_fn on_data;
19+ tiny_http_data_fn on_data;
2020 void *user;
2121 } http_state;
2222
@@ -38,7 +38,7 @@ static size_t on_write(char *ptr, size_t size, size_t nmemb, void *ud) {
3838 size_t n = size * nmemb;
3939 if (st->cancel && *st->cancel) return 0;
4040 if (st->status >= 400) raw_add(st, ptr, n);
41- else cage_sse_feed(&st->sse, ptr, n, st->on_data, st->user);
41+ else tiny_sse_feed(&st->sse, ptr, n, st->on_data, st->user);
4242 return n;
4343 }
4444
@@ -85,16 +85,16 @@ static char *http_error(long status, const char *body, size_t len) {
8585 return xstrdup(detail);
8686 }
8787
88-int cage_http_stream(cage_http_request *req) {
88+int tiny_http_stream(tiny_http_request *req) {
8989 http_state st = {0};
9090 st.cancel = req->cancel;
9191 st.on_data = req->on_data;
9292 st.user = req->user;
93- cage_sse_init(&st.sse);
93+ tiny_sse_init(&st.sse);
9494
9595 CURL *curl = curl_easy_init();
9696 if (!curl) {
97- cage_sse_free(&st.sse);
97+ tiny_sse_free(&st.sse);
Cut short: this commit's diff is over 1000 lines.
src/api/http.h+14−14
Cut short: this commit's diff is over 1000 lines.
src/api/openai_completions.c+42−42
Cut short: this commit's diff is over 1000 lines.
src/api/openai_responses.c+48−48
Cut short: this commit's diff is over 1000 lines.
src/api/sse.c+6−6
Cut short: this commit's diff is over 1000 lines.
src/api/sse.h+7−7
Cut short: this commit's diff is over 1000 lines.
src/catalog.c+10−10
Cut short: this commit's diff is over 1000 lines.
src/catalog.generated.c+3−3
Cut short: this commit's diff is over 1000 lines.
src/catalog.h+7−7
Cut short: this commit's diff is over 1000 lines.
src/config.c+27−27
Cut short: this commit's diff is over 1000 lines.
src/config.h+19−19
Cut short: this commit's diff is over 1000 lines.
src/diff.c+11−11
Cut short: this commit's diff is over 1000 lines.
src/diff.h+10−10
Cut short: this commit's diff is over 1000 lines.
src/event.h+27−27
Cut short: this commit's diff is over 1000 lines.
src/headless.c+26−26
Cut short: this commit's diff is over 1000 lines.
src/headless.h+8−8
Cut short: this commit's diff is over 1000 lines.
src/main.c+23−23
Cut short: this commit's diff is over 1000 lines.
src/message.c+28−28
Cut short: this commit's diff is over 1000 lines.
src/message.h+25−25
Cut short: this commit's diff is over 1000 lines.
src/provider.c+22−22
Cut short: this commit's diff is over 1000 lines.
src/provider.h+22−22
Cut short: this commit's diff is over 1000 lines.
src/resolve.c+10−10
Cut short: this commit's diff is over 1000 lines.
src/resolve.h+4−4
Cut short: this commit's diff is over 1000 lines.
src/resources.c+19−19
Cut short: this commit's diff is over 1000 lines.
src/resources.h+10−10
Cut short: this commit's diff is over 1000 lines.
src/session.c+17−17
Cut short: this commit's diff is over 1000 lines.
src/session.h+8−8
Cut short: this commit's diff is over 1000 lines.
src/tool.c+22−22
Cut short: this commit's diff is over 1000 lines.
src/tool.h+12−12
Cut short: this commit's diff is over 1000 lines.
src/tui/commands.c+43−43
Cut short: this commit's diff is over 1000 lines.
src/tui/commands.h+18−18
Cut short: this commit's diff is over 1000 lines.
src/tui/complete.c+3−3
Cut short: this commit's diff is over 1000 lines.
src/tui/complete.h+5−5
Cut short: this commit's diff is over 1000 lines.
src/tui/editor.c+73−73
Cut short: this commit's diff is over 1000 lines.
src/tui/editor.h+17−17
Cut short: this commit's diff is over 1000 lines.
src/tui/highlight.c+13−13
Cut short: this commit's diff is over 1000 lines.
src/tui/highlight.h+5−5
Cut short: this commit's diff is over 1000 lines.
src/tui/stream.c+36−36
Cut short: this commit's diff is over 1000 lines.
src/tui/stream.h+24−24
Cut short: this commit's diff is over 1000 lines.
src/tui/term.c+63−63
Cut short: this commit's diff is over 1000 lines.
src/tui/term.h+42−42
Cut short: this commit's diff is over 1000 lines.
src/tui/theme.c+20−20
Cut short: this commit's diff is over 1000 lines.
src/tui/theme.h+15−15
Cut short: this commit's diff is over 1000 lines.
src/tui/tui.c+167−167
Cut short: this commit's diff is over 1000 lines.
src/tui/tui.h+8−8
Cut short: this commit's diff is over 1000 lines.
src/tui/usage.c+5−5
Cut short: this commit's diff is over 1000 lines.
src/tui/usage.h+5−5
Cut short: this commit's diff is over 1000 lines.
src/util.c+25−25
Cut short: this commit's diff is over 1000 lines.
src/util.h+31−31
Cut short: this commit's diff is over 1000 lines.
tools/gen_catalog.py+4−4
Cut short: this commit's diff is over 1000 lines.