@@ -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 {