diff options
Diffstat (limited to 'libpanto/src/provider_anthropic_messages.zig')
| -rw-r--r-- | libpanto/src/provider_anthropic_messages.zig | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/libpanto/src/provider_anthropic_messages.zig b/libpanto/src/provider_anthropic_messages.zig index 7511ce8..03c1d90 100644 --- a/libpanto/src/provider_anthropic_messages.zig +++ b/libpanto/src/provider_anthropic_messages.zig @@ -257,7 +257,8 @@ const StreamState = struct { receiver: *provider_mod.Receiver, wire_index: usize, kind: BlockKind, - tool_meta: ?provider_mod.BlockMeta, + tool_id: ?[]const u8, + tool_name: ?[]const u8, ) !void { // Defensive: if a prior block didn't get an explicit stop, drop it. if (self.active != null) { @@ -267,12 +268,11 @@ const StreamState = struct { .wire_index = wire_index, .kind = kind, }; - // For tool_use blocks, capture the identity fields from the meta. + // For tool_use blocks, capture the identity fields. Anthropic + // delivers both whole on content_block_start. if (kind == .tool_use) { - if (tool_meta) |m| { - if (m.tool_id) |id| ab.tool_id = try self.allocator.dupe(u8, id); - if (m.tool_name) |n| ab.tool_name = try self.allocator.dupe(u8, n); - } + if (tool_id) |id| ab.tool_id = try self.allocator.dupe(u8, id); + if (tool_name) |n| ab.tool_name = try self.allocator.dupe(u8, n); } self.active = ab; const block_type: ?provider_mod.ContentBlockType = switch (kind) { @@ -282,7 +282,7 @@ const StreamState = struct { .unsupported => null, }; if (block_type) |bt| { - try receiver.onBlockStart(bt, wire_index, tool_meta); + try receiver.onBlockStart(bt, wire_index); } } @@ -418,11 +418,7 @@ fn handleEvent( .tool_use => .tool_use, .unknown => .unsupported, }; - const meta: ?provider_mod.BlockMeta = if (s.kind == .tool_use) - .{ .tool_id = s.tool_id, .tool_name = s.tool_name } - else - null; - try state.openBlock(receiver, s.index, kind, meta); + try state.openBlock(receiver, s.index, kind, s.tool_id, s.tool_name); }, .content_block_delta => |d| { if (d.text_delta) |t| try state.appendTextDelta(receiver, t); @@ -524,7 +520,6 @@ const RecordingReceiver = struct { ptr: *anyopaque, bt: provider_mod.ContentBlockType, idx: usize, - _: ?provider_mod.BlockMeta, ) anyerror!void { const self: *RecordingReceiver = @ptrCast(@alignCast(ptr)); try self.events.append(self.allocator, .{ .block_start = .{ .kind = bt, .index = idx } }); |
