summaryrefslogtreecommitdiff
path: root/libpanto/src/provider_anthropic_messages.zig
diff options
context:
space:
mode:
authort <t@tjp.lol>2026-06-10 10:06:07 -0600
committert <t@tjp.lol>2026-06-10 12:17:27 -0600
commitbb85e867bc938138f29fb45230169af1ba60761c (patch)
tree5ad1cf50274c61ccfffab7048b4a4e28003d82b5 /libpanto/src/provider_anthropic_messages.zig
parentd26890bbc52e9f0050db40f208763a7f2b714ddd (diff)
Add addUserText helper; update all call sites
Conversation.addUserMessage now takes a []ContentBlock (symmetric with addAssistantMessage). Introduce a thin addUserText wrapper in agent.zig for the plain-text case and update every call site in agent.zig and anthropic_messages_json.zig accordingly.
Diffstat (limited to 'libpanto/src/provider_anthropic_messages.zig')
-rw-r--r--libpanto/src/provider_anthropic_messages.zig32
1 files changed, 21 insertions, 11 deletions
diff --git a/libpanto/src/provider_anthropic_messages.zig b/libpanto/src/provider_anthropic_messages.zig
index 8e41695..37ce818 100644
--- a/libpanto/src/provider_anthropic_messages.zig
+++ b/libpanto/src/provider_anthropic_messages.zig
@@ -707,12 +707,22 @@ fn runStreamedTurn(
}
}
+/// Test helper: append a single-text user message. `addUserMessage` now
+/// takes a block slice (symmetric with `addAssistantMessage`); this wraps
+/// the common plain-text case the tests below use.
+fn addUserText(conv: *conversation.Conversation, text: []const u8) !void {
+ const tb = try conversation.textualBlockFromSlice(conv.allocator, text);
+ var block: conversation.ContentBlock = .{ .Text = tb };
+ errdefer block.deinit(conv.allocator);
+ try conv.addUserMessage(&.{block});
+}
+
test "streams a text-only turn end-to-end" {
const allocator = testing.allocator;
var conv = conversation.Conversation.init(allocator);
defer conv.deinit();
- try conv.addUserMessage("hello");
+ try addUserText(&conv, "hello");
var rec = EventRecorder.init(allocator);
defer rec.deinit();
@@ -762,7 +772,7 @@ test "anthropic: captures usage from message_start and message_delta on message_
var conv = conversation.Conversation.init(allocator);
defer conv.deinit();
- try conv.addUserMessage("hi");
+ try addUserText(&conv, "hi");
var rec = EventRecorder.init(allocator);
defer rec.deinit();
@@ -805,7 +815,7 @@ test "anthropic: message_complete carries null usage when wire omits it" {
var conv = conversation.Conversation.init(allocator);
defer conv.deinit();
- try conv.addUserMessage("hi");
+ try addUserText(&conv, "hi");
var rec = EventRecorder.init(allocator);
defer rec.deinit();
@@ -842,7 +852,7 @@ test "captures thinking signature for round-trip" {
var conv = conversation.Conversation.init(allocator);
defer conv.deinit();
- try conv.addUserMessage("solve");
+ try addUserText(&conv, "solve");
var rec = EventRecorder.init(allocator);
defer rec.deinit();
@@ -888,7 +898,7 @@ test "signature-only thinking block (display omitted)" {
var conv = conversation.Conversation.init(allocator);
defer conv.deinit();
- try conv.addUserMessage("hi");
+ try addUserText(&conv, "hi");
var rec = EventRecorder.init(allocator);
defer rec.deinit();
@@ -925,7 +935,7 @@ test "ping and unknown events are ignored" {
var conv = conversation.Conversation.init(allocator);
defer conv.deinit();
- try conv.addUserMessage("hi");
+ try addUserText(&conv, "hi");
var rec = EventRecorder.init(allocator);
defer rec.deinit();
@@ -962,7 +972,7 @@ test "tool_use blocks are captured with id, name, and assembled input" {
var conv = conversation.Conversation.init(allocator);
defer conv.deinit();
- try conv.addUserMessage("use a tool");
+ try addUserText(&conv, "use a tool");
var rec = EventRecorder.init(allocator);
defer rec.deinit();
@@ -1009,7 +1019,7 @@ test "inbound wire tool name is decoded to dotted form" {
var conv = conversation.Conversation.init(allocator);
defer conv.deinit();
- try conv.addUserMessage("use a tool");
+ try addUserText(&conv, "use a tool");
var rec = EventRecorder.init(allocator);
defer rec.deinit();
@@ -1036,7 +1046,7 @@ test "error event propagates as Zig error" {
var conv = conversation.Conversation.init(allocator);
defer conv.deinit();
- try conv.addUserMessage("hi");
+ try addUserText(&conv, "hi");
var queue = EventQueue.init(allocator);
defer queue.deinit();
@@ -1069,7 +1079,7 @@ test "two streamed turns persist assistant replies in the conversation" {
var conv = conversation.Conversation.init(allocator);
defer conv.deinit();
try conv.addSystemMessage("Be brief.");
- try conv.addUserMessage("hi");
+ try addUserText(&conv, "hi");
var rec = EventRecorder.init(allocator);
defer rec.deinit();
@@ -1088,7 +1098,7 @@ test "two streamed turns persist assistant replies in the conversation" {
};
try runStreamedTurn(allocator, &conv, &rec, &turn1);
- try conv.addUserMessage("what did you say?");
+ try addUserText(&conv, "what did you say?");
const turn2 = [_][]const u8{
\\{"type":"message_start","message":{"role":"assistant"}}