summaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authorT <t@tjp.lol>2026-05-27 06:25:52 -0600
committerT <t@tjp.lol>2026-05-27 07:02:47 -0600
commiteddebe4e8131b7d2112b067fed07e7493d8b1984 (patch)
tree21cc58822aa4e99d55d082444c2347c15101bfe1 /src/main.zig
parent1f0915edbe0213e8bc134922f10933468d35a172 (diff)
Stream OpenAI tool_use as discrete blocks; drop BlockMeta
Close each tool_use on next-index delta (and at finalize) so receivers see one start/delta/complete trio per tool, matching Anthropic. Log+drop fragments for already-closed indices. Remove BlockMeta from the Receiver interface: tool id/name can't be reliably known at onBlockStart under OpenAI's streaming model. Receivers get identity from the assembled ContentBlock at onBlockComplete. CLI renders 'tool: {args} : (name)' accordingly.
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/main.zig b/src/main.zig
index a752a12..c1212e8 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -19,7 +19,6 @@ test {
const Receiver = panto.provider.Receiver;
const ReceiverVTable = panto.provider.ReceiverVTable;
const ContentBlockType = panto.provider.ContentBlockType;
-const BlockMeta = panto.provider.BlockMeta;
const MessageRole = panto.conversation.MessageRole;
/// Receiver that prints streaming deltas to stdout. Thinking blocks are
@@ -50,16 +49,16 @@ const CLIReceiver = struct {
ptr: *anyopaque,
block_type: ContentBlockType,
index: usize,
- meta: ?BlockMeta,
) anyerror!void {
_ = index;
const self: *CLIReceiver = @ptrCast(@alignCast(ptr));
switch (block_type) {
.Thinking => try self.stdout.writeAll("\x1b[2m[thinking] "),
- .ToolUse => {
- const name = if (meta) |m| (m.tool_name orelse "?") else "?";
- try self.stdout.print("\n\x1b[36m[tool: {s}]\x1b[0m ", .{name});
- },
+ // Tool name is not known reliably at start time (OpenAI may
+ // stream id/name across fragments). Open with a bare prefix;
+ // the tool name lands at onBlockComplete from the assembled
+ // ContentBlock.
+ .ToolUse => try self.stdout.writeAll("\n\x1b[36mtool: \x1b[0m"),
else => {},
}
try self.file.flush();
@@ -81,7 +80,8 @@ const CLIReceiver = struct {
const self: *CLIReceiver = @ptrCast(@alignCast(ptr));
switch (block) {
.Thinking => try self.stdout.writeAll("\x1b[0m\n"),
- .ToolUse => try self.stdout.writeAll("\n"),
+ // Append the tool name now that we know it for certain.
+ .ToolUse => |tu| try self.stdout.print("\x1b[36m : ({s})\x1b[0m\n", .{tu.name}),
else => {},
}
try self.file.flush();