@@ -10,8 +10,11 @@ const InputItem = struct {
1010 name: ?[]const u8 = null,
1111 arguments: ?[]const u8 = null,
1212 output: ?[]const u8 = null,
13+ summary: ?[]const SummaryPart = null,
14+ encrypted_content: ?[]const u8 = null,
1315
1416 const ContentPart = struct { type: []const u8 = "input_text", text: []const u8 };
17+ const SummaryPart = struct { type: []const u8 = "summary_text", text: []const u8 };
1518 };
1619
1720 const Body = struct {
@@ -52,7 +55,16 @@ fn buildInput(a: std.mem.Allocator, req: api.Request) ![]const InputItem {
5255 .name = c.name,
5356 .arguments = api.argumentsOrObject(c.arguments),
5457 }),
55- .thinking => {},
58+ .thinking => |t| {
59+ const enc = t.signature orelse continue;
60+ const summary = try a.alloc(InputItem.SummaryPart, if (t.text.len > 0) 1 else 0);
61+ if (t.text.len > 0) summary[0] = .{ .text = t.text };
62+ try out.append(a, .{
63+ .type = "reasoning",
64+ .encrypted_content = enc,
65+ .summary = summary,
66+ });
67+ },
5668 };
5769 },
5870 }
@@ -99,6 +111,7 @@ const Chunk = struct {
99111 call_id: ?[]const u8 = null,
100112 name: ?[]const u8 = null,
101113 arguments: ?[]const u8 = null,
114+ encrypted_content: ?[]const u8 = null,
102115 };
103116
104117 const Response = struct {
@@ -129,6 +142,7 @@ const State = struct {
129142 msg: *types.AssistantMessage,
130143 text: std.ArrayList(u8) = .empty,
131144 reasoning: std.ArrayList(u8) = .empty,
145+ encrypted: ?[]const u8 = null,
132146 calls: std.ArrayList(api.Call) = .empty,
133147 usage: types.Usage = .{},
134148 status: ?[]const u8 = null,
@@ -204,6 +218,10 @@ const State = struct {
204218
205219 if (std.mem.eql(u8, event_type, "response.output_item.done")) {
206220 const item = chunk.item orelse return;
221+ if (std.mem.eql(u8, item.type orelse "", "reasoning")) {
222+ try api.keepString(&st.encrypted, st.req.pers, item.encrypted_content);
223+ return;
224+ }
207225 if (!std.mem.eql(u8, item.type orelse "", "function_call")) return;
208226 const index = streamIndex(chunk, st.calls.items.len);
209227 if (index >= st.calls.items.len) return;
@@ -250,7 +268,13 @@ const State = struct {
250268
251269 fn finalize(st: *State) !void {
252270 const a = st.req.pers;
253- try api.appendParts(st.msg, a, st.reasoning.items, null, st.text.items);
271+ if (st.reasoning.items.len > 0 or st.encrypted != null) {
272+ try st.msg.content.append(a, .{ .thinking = .{
273+ .text = st.reasoning.items,
274+ .signature = st.encrypted,
275+ } });
276+ }
277+ if (st.text.items.len > 0) try st.msg.content.append(a, .{ .text = st.text.items });
254278
255279 const has_calls = try api.appendCalls(st.msg, st.sink, a, st.calls.items, st.failed);