/* pic attach (attach.c): a read-only view of a conversation another * process runs, rebuilt from the journal's committed rows as Pi's JSON * events (or a short text form), caught up from a seq and then followed. * With -i, each line of stdin goes to the conversation's inbox (inbox.h) * while a request runs, and starts one (in a pic ask child) when none does. * It opens the journal narrowly, takes no lease and writes nothing itself * but inbox rows. Streamed text is not journaled, so it shows only committed * messages. */ #ifndef PIC_ATTACH_H #define PIC_ATTACH_H #include #include "pic.h" typedef struct { const char *db; /* the journal */ const char *session; /* an id, a unique prefix, or "latest" */ long long from; /* entries after this seq; -1: from the latest request's start */ int text; /* --format text: lines for a person */ int interactive; /* -i: stdin lines become steers (follow-ups when idle) */ int follow; /* 0 (--no-follow): what is committed, then exit */ /* -i, nothing running: a line starts a request in a child, SELF --db DB * --workspace WORKSPACE [--model MODEL] [--thinking THINKING] ask * --session ID TEXT, which takes the lease; NULL model or thinking: * ask's own default. */ const char *self, *workspace, *model, *thinking; /* The model such a request runs on: when its key is sealed, the passphrase is asked once on * this terminal and the key handed to each child (cred.h, pic_cred_handoff). NULL: none. */ const char *key_model; } pic_attach_options; /* The process's exit status: 0, or 1 with a message on stderr. */ int pic_attach_main(const pic_attach_options *o); /* The same pass for another sink (pic remote, docs/design/remote-protocol.md): follows the * conversation SESSION (an id) of the journal S, which the caller opened narrowly and keeps, from * after FROM (-1: the latest request's start). NULL with err. */ typedef struct pic_follow pic_follow; pic_follow *pic_follow_new(pic_store *s, const char *session, long long from, char *err, size_t cap); /* One pass over what was committed since the last, at most MAX entries (0: all), in one read * transaction; once it has ended, EMIT gets each event in order with the seq of the entry it came * from (nonzero stops). *LAST is the highest seq the pass read, *RUNNING whether a request was * running, and *MORE whether it stopped at MAX with more to read. 0, or -1. */ int pic_follow_pass(pic_follow *f, int (*emit)(void *ctx, long long seq, const char *event), void *ctx, int max, long long *last, int *running, int *more); void pic_follow_free(pic_follow *f); /* Once, no follow kept: the entries of SESSION after FROM and before BEFORE, as a pass sends them * (pic remote's fetch, a page of what came earlier). A request that goes on at BEFORE is not ended * there. 0, or -1 with the store's error. */ int pic_follow_page(pic_store *s, const char *session, long long from, long long before, int (*emit)(void *ctx, long long seq, const char *event), void *ctx); #endif