/* pic --mode rpc (rpc.c): Pi's RPC mode. A long-lived process reading Pi's
* JSONL commands on stdin and writing responses and Pi's JSON events on
* stdout, one object per line. The journal is opened per command and per
* request, as the line mode opens it, so other pic commands can use it
* while the process waits; a crash mid-request recovers as any pic run's. */
#ifndef PIC_RPC_H
#define PIC_RPC_H
#include "pic.h"
typedef struct pic_rpc_host {
const char *db, *workspace;
int exec_seconds;
/* Opens the journal with the hooks attached (0, or -1 with s->err). */
int (*open)(pic_store *s, const char *db);
/* Runs TEXT as a request of MODEL at THINKING, in SESSION, or (SESSION
* NULL) a new conversation with the id NEW_ID; once it is admitted,
* admitted(ctx) runs before the request does. 0, or -1 (s->err). */
int (*prompt)(pic_store *s, const char *model, const char *thinking, const char *session, const char *new_id,
const char *text, pic_image *images, size_t n, void (*admitted)(void *ctx), void *ctx);
/* MODEL's provider at THINKING (0, or -1 with err). */
int (*provider)(pic_provider *p, const char *model, const char *thinking, char *err, size_t errcap);
/* The level MODEL starts at: --thinking, else the saved settings. */
int (*level)(const char *model, char *out, size_t cap, char *err, size_t errcap);
/* A template's or skill's expansion of TEXT (malloc'd), or NULL. */
char *(*expand)(void *workspace, const char *text);
/* SessionEnd for the conversations this process started. */
void (*end)(const char *db, const char *reason);
} pic_rpc_host;
/* Serves stdin until it ends (or SIGTERM/SIGHUP). MODEL and SESSION (NULL:
* a new conversation; "latest" or an id to continue one) start the state.
* The process's exit status. */
int pic_rpc_main(const pic_rpc_host *h, const char *model, const char *session);
#endif