Artifact 1b182771693625b7b5463402a8dd24d74ed35c17adfa28793de3e6b15ec8dd5a:
- File
src/catalog.h
— part of check-in
[dd27c70e9d]
at
2026-11-19 16:10:29
on branch userdb
— User state in ~/.pic/pic.sqlite instead of loose files (ticket 2ad667b78b)
pic's user-level state now lives in one SQLite database, shared by every pic process (WAL, a busy timeout), in tables prefixed picu_: settings, the model catalog cache from pi.dev (stored with the SQLite Archive compression rule; sqlar_compress and sqlar_uncompress are registered), project trust, model scopes and the workspaces pic has used. ~/.pic/settings.json and ~/.pic/models-store.json are imported on first open in one transaction and then deleted. pic settings shows and changes settings. Tests and benchmarks now run with a private HOME and an offline catalog, so they no longer read or write the real ~/.pic. (user: dmestas, size: 1437) [annotate] [blame] [check-ins using] [more...]
/* The model catalog (catalog.c): Pi's catalog of models for pic's providers, * as Pi keeps it. A snapshot is built in (model_catalog.inc); fresher * per-provider lists from https://pi.dev/api/models/providers/<id> are kept as * rows of picu_catalog in ~/.pic/pic.sqlite and used when newer than the snapshot. Entries * are Pi model objects (JSON: id, name, api, baseUrl, reasoning, * contextWindow, maxTokens, compat). */ #ifndef PIC_CATALOG_H #define PIC_CATALOG_H #include <stddef.h> /* The model object for provider/id (malloc'd JSON), or NULL. */ char *pic_catalog_find(const char *provider, const char *id); /* Calls fn for each model of the catalog, provider by provider; stops when * fn returns non-zero. 0, or -1 when the store could not be read. */ int pic_catalog_each(int (*fn)(void *ctx, const char *provider, const char *json), void *ctx); /* Refreshes the stored lists from pi.dev: each built-in provider not checked * in the last 4 hours (all of them when force), with If-None-Match. Offline * or failing providers keep what is stored. PIC_MODEL_CATALOG=offline turns * fetching off. 0 when every provider was fresh or refreshed; -1 with err * naming the first failure otherwise. */ int pic_catalog_refresh(int force, char *err, size_t errcap); /* Shared by catalog.c and catalog_fetch.c. */ #define PIC_CATALOG_NPROVIDERS 13 extern const char *const pic_catalog_providers[PIC_CATALOG_NPROVIDERS]; #endif