Artifact 6ad7ae8a2adfe925efc549452504c7e3a260a84c5a61530083684fb443c3babf:
- File
src/cred.c
— part of check-in
[3ff8346a3f]
at
2026-11-19 00:38:38
on branch stage-4
— Journal every reply in two forms and convert across models
Assistant entries keep the provider content verbatim with its origin (provider, api, model) and Pi neutral form; tool calls come from the neutral form, the same for every provider. A turn goes back verbatim to the model that wrote it and is otherwise rebuilt from the neutral form, without thinking and with tool-call ids normalised identically in calls and results. --model resolves through the registry, keys come from the model, and schema 3 journals migrate in place on open. (user: dmestas, size: 1225) [annotate] [blame] [check-ins using] [more...]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "cred.h" void pic_cred_wipe(void *p, size_t n) { volatile unsigned char *v = p; while (n--) { *v++ = 0; } } int pic_cred_get(const char *env, const char *literal, char *buf, size_t cap, char *err, size_t errcap) { const char *value = literal && *literal ? literal : NULL; const char *what = value ? "the models file's apiKey" : env; size_t n; if (!value) { if (!env || !*env) { return 1; /* nothing configured: a server that needs no key */ } value = getenv(env); if (!value || !*value) { (void)snprintf(err, errcap, "%s is not set (run pic under `doppler run --`)", env); return -1; } } n = strlen(value); if (n >= cap) { (void)snprintf(err, errcap, "%s is longer than %zu bytes", what, cap - 1); return -1; } for (size_t i = 0; i < n; i++) { if ((unsigned char)value[i] < 0x21 || (unsigned char)value[i] > 0x7e) { (void)snprintf(err, errcap, "%s has a character that cannot go in a header", what); return -1; } } memcpy(buf, value, n + 1); return 0; }