Artifact 5df237d573b0dfdf7e2aa9caf93317696fe0822fb6ae64a8438b33ce1fb8ae0a:
- File
test/pic/decode.sh
— part of check-in
[55cff08c2c]
at
2026-11-19 00:56:53
on branch stage-4
— Add the Chat Completions adapter for OpenAI, OpenRouter and compatibles
A chunk decoder following Pi: text, reasoning from reasoning_content, reasoning or reasoning_text kept under its field, OpenRouter reasoning_details verbatim, tool calls by index, usage, finish_reason, and in-stream errors. Requests follow Pi too: system or developer role, tools as functions, tool messages, stream_options, store and reasoning by dialect. The retry loop and header assembly move into a shared module both adapters use. Recorded streams, a fuzz target and fake server cases cover it, including a conversation moving between the two APIs in both directions. (user: dmestas, size: 902) [annotate] [blame] [check-ins using]
#!/bin/sh # Decodes every recorded stream and compares it with its checked-in summary: # Messages API streams in streams/, Chat Completions streams in chat-streams/. # Usage: decode.sh DECODER [--update] set -eu decoder=$1 here=$(dirname "$0") for dir in streams chat-streams; do mode= [ "$dir" = chat-streams ] && mode=--chat for stream in "$here/$dir"/*.sse; do want=${stream%.sse}.want if [ "${2:-}" = --update ]; then # shellcheck disable=SC2086 "$decoder" $mode "$stream" > "$want" continue fi # shellcheck disable=SC2086 if ! "$decoder" $mode "$stream" | cmp -s - "$want"; then echo "FAIL $stream" >&2 # shellcheck disable=SC2086 "$decoder" $mode "$stream" | diff "$want" - >&2 || true exit 1 fi done done echo "decode: all recorded streams match"