Artifact 7607ffc50eb0e9ac7e07e8ff7302bb37bc55d07d9b26f719b192ab5b3a3cc088:
- File
src/openai_responses.h
— part of check-in
[dd694d986b]
at
2026-11-19 01:08:50
on branch stage-4
— Add the OpenAI Responses adapter
Output items are kept whole, so reasoning items with encrypted_content go back verbatim to the same model under store:false; the final output list is authoritative and fills in late encrypted_content. The neutral form follows Pi: reasoning to thinking, messages to text, function calls to tool calls with call_id|item_id ids. Requests send input items, function_call_output under the call ids, flat tools, and reasoning effort with encrypted reasoning for reasoning models. Recorded streams, a fuzz target and fake server cases cover it, including conversations moving between the Messages API and Responses both ways. (user: dmestas, size: 1751) [annotate] [blame] [check-ins using] [more...]
/* OpenAI Responses stream decoder: SSE events in, one reply out, as the list * of output items (native, replayed verbatim to the same model, reasoning * items with their encrypted_content) and as Pi's neutral content. The * complete items from response.output_item.done, and the final list in * response.completed, are what count; text deltas are not needed. */ #ifndef PIC_OPENAI_RESPONSES_H #define PIC_OPENAI_RESPONSES_H #include <stddef.h> #include "sqlite3.h" #define PIC_RESPONSES_CAP (16u << 20) #define PIC_RESPONSES_ITEMS 128 typedef struct { sqlite3 *db; char *items[PIC_RESPONSES_ITEMS]; /* by output_index, from output_item.done */ int nitems; char *final_output; /* response.output from the terminal event, verbatim */ char *status; /* completed, incomplete, failed */ char *incomplete; /* incomplete_details.reason */ char *usage; char *response_id; char *error; int terminal; /* saw completed, incomplete or failed */ size_t total; int failed; char err[256]; } pic_responses; int pic_responses_init(pic_responses *r, sqlite3 *db); void pic_responses_free(pic_responses *r); /* Fits pic_sse_event_fn with ctx = the decoder. 0, or -1 with r->err set. */ int pic_responses_event(void *ctx, const char *event, const char *data, size_t len); /* End of stream: 0 when a complete reply arrived, else -1 with r->err. */ int pic_responses_finish(pic_responses *r); /* After a successful finish (malloc'd): the output items as a JSON array; */ char *pic_responses_native(pic_responses *r); /* Pi's neutral content array; */ char *pic_responses_neutral(pic_responses *r); /* Pi's stop reason: stop, toolUse, length. */ const char *pic_responses_stop(pic_responses *r); #endif