Artifact f8cfcd2a2a4c828237d123e1ec42a4efc62c5e41931b140f00e60d41e8ef07fd:
- File
src/http.h
— part of check-in
[fb82c37817]
at
2026-11-19 14:01:47
on branch models
— Model picker, slash command menu and Pi's model catalog
Models are chosen as in Pi. pic carries a snapshot of Pi's catalog for its providers (653 chat models; tools/model-catalog.sh regenerates it from pi.dev/api/models) and lays fresher per-provider lists from pi.dev over it, cached in ~/.pic/models-store.json with ETags and trusted for four hours, used only when newer than the snapshot. Resolution takes a model's API, endpoint, limits and compat settings from the catalog before the models file. pic models lists the models of providers with a key (--all every one, --json, --refresh); pic models --default saves the model used when none is given.
In the terminal interface, Ctrl+L or /model opens a picker of the models whose provider has a key, filtered by Pi's fuzzy matching as you type, current and default first; Enter uses the model, Ctrl+S also saves it as the default; Ctrl+P cycles. Typing / shows a menu of commands with their arguments (Tab completes, Enter runs) and /model completes model names. New commands show the conversation's details and token counts, copy the last reply (OSC 52 and the system clipboard), export, clone and list the hotkeys. (user: dmestas, size: 2474) [annotate] [blame] [check-ins using] [more...]
/* HTTP/1.1 for one POST per connection. The response parser is a pure * function over bytes (status line, headers, then a body delimited by chunked * encoding, Content-Length or the end of the connection), so it is fuzzed on * its own. */ #ifndef PIC_HTTP_H #define PIC_HTTP_H #include <stddef.h> #include "net.h" /* Body bytes as they arrive. Nonzero stops the response; feed returns it. */ typedef int (*pic_http_body_fn)(void *ctx, const char *bytes, size_t n); typedef struct { int state; /* internal */ int status; /* final status code, once headers are done */ char retry_after[32]; /* Retry-After value, if any */ char request_id[128]; /* request-id header, if any */ char content_type[128]; /* Content-Type, if any */ char etag[128]; /* ETag, if any */ char last_modified[64]; /* Last-Modified, if any */ pic_http_body_fn on_body; void *ctx; char line[8192]; size_t line_len; size_t header_bytes; unsigned long long remaining; /* bytes left of the body or chunk */ int chunked, has_length, body_started; char err[160]; } pic_http_resp; void pic_http_resp_init(pic_http_resp *r, pic_http_body_fn on_body, void *ctx); /* 0, a callback's nonzero value, or -1 on a malformed response (r->err). */ int pic_http_feed(pic_http_resp *r, const char *bytes, size_t n); /* 1 once the body is complete (more bytes are an error). */ int pic_http_done(const pic_http_resp *r); /* At the end of the connection: 0 if the response was complete, else -1. */ int pic_http_end(pic_http_resp *r); /* POSTs body to url (https://host[:port]/path, or http:// to loopback only) * with extra header lines ("Name: value"), streaming the response body to * r's callback. Header values are never copied into errors. 0 when a full * response arrived (any status), -1 on a transport or protocol failure with * err set. pic_net_tls_failed(net) then tells a TLS failure from others. */ int pic_http_post(pic_net *net, const char *url, const char *const *headers, size_t nheaders, const char *body, size_t body_len, pic_http_resp *r, int idle_seconds, int deadline_seconds, char *err, size_t errcap); /* GETs url, as pic_http_post does otherwise (no body). */ int pic_http_get(pic_net *net, const char *url, const char *const *headers, size_t nheaders, pic_http_resp *r, int idle_seconds, int deadline_seconds, char *err, size_t errcap); #endif