Skip to content
pi-c Documentation
Login

Documentation

/* Peers (docs/design/grapevine.md, stage 4): the send_message tool, by which one conversation
 * messages another of the same user, in this workspace or another, through the receiver's inbox
 * (inbox.h); the frame its text arrives in; and the wake component, which starts a pic run for a
 * conversation with nothing running when grapevine.wake allows. Bundled: core records each
 * message, its hops and what it made; what the model may send, and when to wake, are decided here. */
#ifndef PIC_PEER_H
#define PIC_PEER_H

#include <stdio.h>

#include "pic.h"
#include "toolreg.h"

/* The tool's definition sent to providers, and its registration (toolreg.h). */
extern const char pic_peer_schema[];
extern const pic_tool_def pic_peer_tool;

/* send_message: HOOKS->journal, effect and input name the call (its key is
 * fx:JOURNAL_ID:EFFECT, so a replay after a crash sends nothing new). */
char *pic_peer_send(const char *workspace, const pic_tool_args *args, const pic_tool_hooks *hooks, int *is_error);

/* Whether send_message is in the default tool set: yes unless grapevine.sendMessage is false. */
int pic_peer_default(void);

/* Whether a request runs in CONV of S, or a pic holds its lease. */
int pic_peer_running(pic_store *s, const char *conv);

/* One plain line, malloc'd, on where the message KEY just saved pending in CONV of S stands, after
 * starting a request there when nothing runs, PROMPT is set and grapevine.wake is not false (DB and
 * WS are what the run is started on). The sender's tool result, and pic send's stderr. */
char *pic_peer_standing(pic_store *s, const char *db, const char *ws, const char *conv, const char *key, int prompt,
                        int *is_error);

/* A pic run for conversation CONV of journal DB in workspace WS, in a session of its own, outliving
 * this process, its output discarded: the run takes the lease and admits the waiting prompt. The
 * starter for grapevine.wake and for loops (wake.h). 0 when it was started. */
int pic_peer_start(const char *db, const char *ws, const char *conv);
/* pic_peer_start, unless grapevine.wake is off: a prompt the inbox found left over when a run let
 * go of its conversation (pic_inbox_starter). */
int pic_peer_wake(const char *db, const char *ws, const char *conv);

/* This executable, which a wake runs as pic run; main sets it once. */
void pic_peer_self(const char *path);

/* pic sessions --all: every workspace this user has opened, with its conversations, one line
 * each (WORKSPACE  ID  NAME  REQUESTS  FIRST), live ones marked; JSON: one {workspace, id, name,
 * updatedMs, requests, first, running} object per line. 0, or -1 with ERR. */
int pic_peer_sessions_all(FILE *out, int json, char *err, size_t cap);

#endif