Lightpanda: the headless browser designed for AI and automation
Merge branch 'main' into tool-session
Adrià Arrufatf1bdd0019f30
diff --cc src/agent/Agent.zigindex e68f770e9,82b2f4034..dd43f3c2a--- a/src/agent/Agent.zig+++ b/src/agent/Agent.zig@@@ -1473,7 -1488,8 +1473,8 @@@ fn runCommand(self: *Agent, arena: std..tool_call => |t| t,else => return .{ .text = "internal: command has no tool mapping", .is_error = true },};- return browser_tools.call(arena, self.ts.session, &self.ts.registry, tc.name(), tc.args) catch |err| .{+ // The terminal can't show an image, but the conversation can.- return browser_tools.call(arena, self.session, &self.node_registry, tc.name(), tc.args, .{ .inline_image = self.ai_client != null }) catch |err| .{++ return browser_tools.call(arena, self.ts.session, &self.ts.registry, tc.name(), tc.args, .{ .inline_image = self.ai_client != null }) catch |err| .{.text = switch (err) {error.OutOfMemory => "out of memory",error.FrameNotLoaded => "no page loaded — run /goto <url> first",@@@ -1917,6 -1934,22 +1919,22 @@@ fn handleToolCall(ctx: *anyopaque, alloreturn outcome;}+ /// The text plus the rendered PNG, for backends that can show the model an image.+ fn toolOutcome(self: *Agent, allocator: std.mem.Allocator, tool_name: []const u8, arguments: ?std.json.Value) browser_tools.ToolError!zenai.provider.Client.ToolHandler.Result {- const result = try browser_tools.call(allocator, self.session, &self.node_registry, tool_name, arguments, .{ .inline_image = true });++ const result = try browser_tools.call(allocator, self.ts.session, &self.ts.registry, tool_name, arguments, .{ .inline_image = true });+ const content = capToolOutput(allocator, tool_name, result.text);+ return .{+ .content = content,+ .is_error = result.is_error,+ .parts = if (result.image) |image| try imageParts(allocator, content, &image) else null,+ };+ }++ fn imageParts(arena: std.mem.Allocator, text: []const u8, image: *const lp.screenshot.Prepared) browser_tools.ToolError![]const zenai.provider.ContentPart {+ const data = image.base64Alloc(arena) catch return error.InternalError;+ return try arena.dupe(zenai.provider.ContentPart, &.{ .{ .text = text }, .{ .image = .{ .data = data, .mime_type = "image/png" } } });+ }+/// One-shot for `--list-models`: resolve provider+key, fetch chat-capable model/// IDs, print to stdout one per line.pub fn listModels(allocator: std.mem.Allocator, opts: Config.Agent) !void {diff --cc src/mcp/tools.zigindex 31444d7f7,2f6602143..3e928e124--- a/src/mcp/tools.zig+++ b/src/mcp/tools.zig@@@ -154,7 -156,7 +156,7 @@@ fn dispatchBrowserTool};const active = server.active_session;- const result = browser_tools.call(arena, active.session, &active.registry, name, arguments) catch |err| {- const result = browser_tools.call(arena, active.session, &active.node_registry, name, arguments, .{ .inline_image = true }) catch |err| {++ const result = browser_tools.call(arena, active.session, &active.registry, name, arguments, .{ .inline_image = true }) catch |err| {// evaluate/extract surface failures in-band so the LLM can self-correct;// other tools' operational failures are protocol-level.if (surfacesErrorInBand(tool)) {