From 17a985cb41727b8a1bca4d95f334106c09386040 Mon Sep 17 00:00:00 2001 From: t Date: Sun, 7 Jun 2026 14:57:58 -0600 Subject: Alias Conversation instead of facading it; merge addAssistantMessage A facade that forwards every method 1:1 is worse than paring the real type down to the intended surface and aliasing it. conversation.Conversation's interface is already the public surface we want (init/deinit, the add*/replace* builders, and messages/allocator as plain data fields), so public.zig now aliases it straight through and Agent.conversation() returns a borrowed *Conversation for in-place surgery. Drops the ConversationData alias and the pointer-wrapper. Merged addAssistantMessageWithUsage into addAssistantMessage(blocks, ?usage) on the real type (separate method deleted), so the alias has the intended one-method shape; all call sites updated. Only Agent and Stream remain true facades -- they have genuinely-internal fields plus API-shaping renames (Stream.phase->state, Phase->State) an alias can't express. --- libpanto/src/conversation.zig | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'libpanto/src/conversation.zig') diff --git a/libpanto/src/conversation.zig b/libpanto/src/conversation.zig index 1fc5016..a436378 100644 --- a/libpanto/src/conversation.zig +++ b/libpanto/src/conversation.zig @@ -292,15 +292,11 @@ pub const Conversation = struct { }); } - /// Append an assistant message. Ownership of the blocks is transferred - /// to the conversation; the caller must not deinit them after this call. - pub fn addAssistantMessage(self: *Conversation, blocks: []const ContentBlock) !void { - return self.addAssistantMessageWithUsage(blocks, null); - } - - /// Append an assistant message tagged with its provider-reported - /// `usage`. Ownership of the blocks is transferred to the conversation. - pub fn addAssistantMessageWithUsage( + /// Append an assistant message, optionally tagged with its + /// provider-reported `usage` (pass `null` for none). Ownership of the + /// blocks is transferred to the conversation; the caller must not + /// deinit them after this call. + pub fn addAssistantMessage( self: *Conversation, blocks: []const ContentBlock, usage: ?Usage, @@ -415,7 +411,7 @@ test "Conversation - add messages and verify content" { try conv.addUserMessage("Hello!"); try conv.addAssistantMessage(&.{ .{ .Text = try textualBlockFromSlice(allocator, "Hi there!") }, - }); + }, null); try std.testing.expectEqual(@as(usize, 3), conv.messages.items.len); @@ -455,7 +451,7 @@ test "Conversation - deinit frees without leaks" { try conv.addUserMessage("user message"); try conv.addAssistantMessage(&.{ .{ .Text = try textualBlockFromSlice(allocator, "response") }, - }); + }, null); conv.deinit(); } @@ -468,7 +464,7 @@ test "ContentBlock - Thinking variant" { try conv.addAssistantMessage(&.{ .{ .Thinking = .{ .text = try textualBlockFromSlice(allocator, "hmm...") } }, .{ .Text = try textualBlockFromSlice(allocator, "answer") }, - }); + }, null); try std.testing.expectEqual(@as(usize, 2), conv.messages.items[0].content.items.len); try std.testing.expectEqualStrings("hmm...", conv.messages.items[0].content.items[0].Thinking.text.items); @@ -574,7 +570,7 @@ test "latestCompactionIndex - null when never compacted" { try conv.addUserMessage("hi"); try conv.addAssistantMessage(&.{ .{ .Text = try textualBlockFromSlice(allocator, "hello") }, - }); + }, null); try std.testing.expect(latestCompactionIndex(conv.messages.items) == null); } -- cgit v1.3