summaryrefslogtreecommitdiffstats
path: root/src/provider.h
blob: ae6089663f196c8eadf96a27083ec25f161a19c7 (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_PROVIDER_H
#define LLSH_PROVIDER_H

#include <stdbool.h>

#include "llm.h"
#include "mcp.h"
#include "session.h"

/* The session-bound provider layer: implements the `llsh_model` vtable on
 * top of llm.h's protocol layer, wiring in the session (config, preamble,
 * allowed tools, .agents), the built-in + MCP tool registry, and the
 * session's emit callback. */

/* Which one-shot role this model serves. `complete` uses the matching
 * preamble; `stream` (the agent turn) always uses the session preamble. */
typedef enum {
    PROV_ROLE_MAIN = 0,
    PROV_ROLE_SUMMARIZER,
    PROV_ROLE_EVALUATOR,
    PROV_ROLE_RUBRIC,
} provider_role;

/* Create a session-bound model. `sess` may be NULL until
 * provider_model_attach; `mcp` may be NULL (no MCP tools). */
llsh_model *provider_model_new(session *sess, mcp_registry *mcp,
                               provider_role role);
void provider_model_attach(llsh_model *m, session *sess);

/* Test hook: build the request body (without sending) for the session's
 * current config, preamble, and tool set, for a single one-shot prompt.
 * Caller frees the returned string. */
char *provider_preview_request(session *sess, const char *prompt,
                               bool with_tools);

/* On stop, an assistant message can carry more tool calls than the
 * tool-result messages that follow it (we stopped mid-loop). Trim the
 * surplus calls so the committed history stays a valid request. */
void provider_trim_dangling_calls(message *msgs, size_t n);

#endif /* LLSH_PROVIDER_H */