xonecas.io
7814
Ta

tiny-c-agent / files

tiny-c-agent / src / api.h

2.6 KB
1// Internal contract between the provider dispatcher and each API adapter.
2
3#ifndef TINY_API_H
4#define TINY_API_H
5
6#include <yyjson.h>
7
8#include "provider.h"
9
10// Adds a tool's "name", "description", and schema (under `params_key`) to `obj`.
11// Shared by every adapter's tool serialization.
12void tiny_json_tool(yyjson_mut_doc *doc, yyjson_mut_val *obj, const tiny_tool *t,
13                    const char *params_key);
14
15// Emits one delta to the adapter's stream callback, if any.
16void tiny_emit_delta(tiny_stream_fn emit, void *user, tiny_stream_type type, const char *delta);
17
18// Emits TINY_STREAM_TOOL_CALL_START. Call once per tool call block, as soon as
19// its name is known, before the arguments have finished streaming.
20void tiny_emit_tool_start(tiny_stream_fn emit, void *user, const char *id, const char *name);
21
22// Appends a text/thinking block when `text` is non-NULL and non-empty.
23void tiny_add_text_block(tiny_message *out, tiny_block_type type, const char *text);
24
25// Appends a tool-call block (defaulting empty arguments to "{}") and emits the
26// corresponding TINY_STREAM_TOOL_CALL event.
27void tiny_add_tool_block(tiny_message *out, const char *id, const char *name,
28                         const char *args, tiny_stream_fn emit, void *user);
29
30int tiny_openai_completions_stream(const tiny_model *model, const tiny_context *ctx,
31                                   const tiny_stream_opts *opts,
32                                   tiny_stream_fn emit, void *user,
33                                   const volatile bool *cancel,
34                                   tiny_message *out, char **err);
35
36int tiny_openai_responses_stream(const tiny_model *model, const tiny_context *ctx,
37                                 const tiny_stream_opts *opts,
38                                 tiny_stream_fn emit, void *user,
39                                 const volatile bool *cancel,
40                                 tiny_message *out, char **err);
41
42int tiny_anthropic_messages_stream(const tiny_model *model, const tiny_context *ctx,
43                                   const tiny_stream_opts *opts,
44                                   tiny_stream_fn emit, void *user,
45                                   const volatile bool *cancel,
46                                   tiny_message *out, char **err);
47
48int tiny_google_generative_ai_stream(const tiny_model *model, const tiny_context *ctx,
49                                     const tiny_stream_opts *opts,
50                                     tiny_stream_fn emit, void *user,
51                                     const volatile bool *cancel,
52                                     tiny_message *out, char **err);
53
54#endif