diff options
| author | t <t@tjp.lol> | 2026-06-18 13:38:32 -0600 |
|---|---|---|
| committer | t <t@tjp.lol> | 2026-06-18 13:39:49 -0600 |
| commit | 7c2d8825660f73198149c0b2ce26166b16ba3532 (patch) | |
| tree | ae57a23e5dcb905b29718c63a0ed2f6c65d93d53 /libpanto/src | |
| parent | fc77c3900ef80ff0e2934c03ca37dfc309a6e7b9 (diff) | |
Preserve content blocks and thinking origin in C store append
Round-trip persistent message content through the C session store bridge
instead of dropping it, including tool-use, tool-result, system, and
thinking blocks. Reconstruct borrowed C content blocks with arena-backed
helpers, carry message identity fields like API style/model/reasoning, and
add tests covering append marshalling and thinking signature origin
round-tripping.
Diffstat (limited to 'libpanto/src')
| -rw-r--r-- | libpanto/src/conversation.zig | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/libpanto/src/conversation.zig b/libpanto/src/conversation.zig index 760f3ee..4338563 100644 --- a/libpanto/src/conversation.zig +++ b/libpanto/src/conversation.zig @@ -370,6 +370,24 @@ pub const Conversation = struct { }); } + /// Append a message of any role from a slice of content blocks, with + /// optional usage. The general form behind `addUserMessage` / + /// `addAssistantMessage`; used to rebuild a persisted message (tool calls, + /// thinking, mixed blocks) losslessly. Ownership of the blocks transfers + /// to the conversation; the caller must not deinit them after this call. + pub fn addMessage(self: *Conversation, role: MessageRole, blocks: []const ContentBlock, usage: ?Usage) !void { + var content: std.ArrayList(ContentBlock) = .empty; + try content.ensureTotalCapacity(self.allocator, blocks.len); + for (blocks) |block| { + content.appendAssumeCapacity(block); + } + try self.messages.append(self.allocator, .{ + .role = role, + .content = content, + .usage = usage, + }); + } + pub fn deinit(self: *Conversation) void { for (self.messages.items) |*msg| { msg.deinit(self.allocator); |
