summaryrefslogtreecommitdiffstats
path: root/src/agent.h
blob: a18f55ec308e0aeca394861b0a0816935d073eff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef LLSH_AGENT_H
#define LLSH_AGENT_H

#include "config.h"

#include <cjson/cJSON.h>

/* Mirrors agent.rs: provider probe + context-limit fetch (libcurl). */

typedef struct {
    bool ok;
    char *detail; /* owned; release with provider_probe_free */
} provider_probe;

void provider_probe_free(provider_probe *p);

const char *agent_default_base_url(provider_kind p);

/* Model-list endpoint for the probe/fetch. Caller frees. */
char *agent_models_url(const config *cfg);
/* Auth header for the model-list endpoint. Caller frees each non-NULL.
 * Ollama sends no auth: both come back NULL. */
void agent_auth(const config *cfg, char **header, char **value);

/* GET `url` with a 5s timeout. 0 = HTTP response received (*status, *body
 * owned); -1 = transport failure (*err owned, body NULL). */
int agent_http_get(const char *url, const char *auth_header,
                   const char *auth_value, long *status, char **body,
                   char **err);

/* Pull the window size out of a provider's model-info response. 0 = absent. */
unsigned long extract_context_limit(const cJSON *json, const config *cfg);

bool openai_model_present(const char *body, const char *model);
bool anthropic_model_present(const char *body, const char *model);

/* Best effort: network failures / non-2xx / missing fields -> 0. */
unsigned long agent_fetch_context_limit(const config *cfg);
provider_probe agent_probe_provider(const config *cfg);

#endif