diff options
| author | t <t@tjp.lol> | 2026-06-22 18:18:28 -0600 |
|---|---|---|
| committer | t <t@tjp.lol> | 2026-06-23 09:34:55 -0600 |
| commit | 538a5d926fa626a00cc3dc12c555f11f82867efd (patch) | |
| tree | 7ea3b84ea5086d67973d0b427ec7c382eb635e50 /libpanto/src/openai_chat_json.zig | |
| parent | a417727810cc6722b3c82e3c9e9b46982ef40a08 (diff) | |
libpanto ponytail-audit simplifications
Diffstat (limited to 'libpanto/src/openai_chat_json.zig')
| -rw-r--r-- | libpanto/src/openai_chat_json.zig | 25 |
1 files changed, 1 insertions, 24 deletions
diff --git a/libpanto/src/openai_chat_json.zig b/libpanto/src/openai_chat_json.zig index 8af939f..f00c97f 100644 --- a/libpanto/src/openai_chat_json.zig +++ b/libpanto/src/openai_chat_json.zig @@ -11,6 +11,7 @@ const Writer = std.Io.Writer; const conversation = @import("conversation.zig"); const config_mod = @import("config.zig"); const tool_registry_mod = @import("tool_registry.zig"); +const writeRawJson = @import("provider.zig").writeRawJson; /// A single parsed streaming chunk. Fields are populated only when present /// in the wire payload; null fields signal "not in this chunk". @@ -173,30 +174,6 @@ pub fn serializeRequest( return try aw.toOwnedSlice(); } -/// Emit a pre-encoded JSON value into the current stringifier position. -/// -/// `std.json.Stringify.write` can only emit Zig values; we need to splice -/// arbitrary user-supplied JSON (tool schemas, parsed tool inputs) into -/// the output. We do that by parsing the bytes into `std.json.Value` and -/// asking the stringifier to write them. If parsing fails, fall back to -/// emitting an empty object so we never produce invalid JSON on the wire. -fn writeRawJson(s: *std.json.Stringify, raw: []const u8) !void { - // Use the stringifier's own allocator path via a scratch arena. - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); - defer arena.deinit(); - const parsed = std.json.parseFromSlice( - std.json.Value, - arena.allocator(), - raw, - .{}, - ) catch { - try s.beginObject(); - try s.endObject(); - return; - }; - try s.write(parsed.value); -} - /// Emit one `Conversation.Message` as one or more wire-level messages. /// /// OpenAI's wire format is awkward here: a single logical `user` turn that |
