mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-06-11 09:35:59 -04:00
agent: reorder heal arguments and use leaky json parsing
This commit is contained in:
@@ -390,7 +390,7 @@ fn runScript(self: *Self, path: []const u8) bool {
|
||||
"Command succeeded but verification failed, attempting self-healing...";
|
||||
self.terminal.printInfo(msg);
|
||||
|
||||
if (self.attemptSelfHeal(entry.raw_line, verification.reason, last_comment, sa)) |healed_cmds| {
|
||||
if (self.attemptSelfHeal(sa, entry.raw_line, verification.reason, last_comment)) |healed_cmds| {
|
||||
if (formatReplacement(sa, entry.raw_span, entry.raw_line, healed_cmds)) |replacement| {
|
||||
replacements.append(sa, replacement) catch {};
|
||||
}
|
||||
@@ -597,7 +597,7 @@ fn dupeParts(alloc: std.mem.Allocator, parts: []const zenai.provider.ContentPart
|
||||
/// Runs a single LLM turn and returns the commands it executed, without
|
||||
/// recording them to the Recorder. Used by attemptSelfHeal so that the
|
||||
/// caller can capture healed commands for script rewriting.
|
||||
fn runHealTurn(self: *Self, prompt: []const u8, arena: std.mem.Allocator) ![]Command.Command {
|
||||
fn runHealTurn(self: *Self, arena: std.mem.Allocator, prompt: []const u8) ![]Command.Command {
|
||||
const ma = self.message_arena.allocator();
|
||||
|
||||
try self.ensureSystemPrompt();
|
||||
@@ -643,7 +643,7 @@ fn runHealTurn(self: *Self, prompt: []const u8, arena: std.mem.Allocator) ![]Com
|
||||
return cmds.toOwnedSlice(arena) catch &.{};
|
||||
}
|
||||
|
||||
fn attemptSelfHeal(self: *Self, failed_command: []const u8, verify_context: ?[]const u8, context_comment: ?[]const u8, arena: std.mem.Allocator) ?[]Command.Command {
|
||||
fn attemptSelfHeal(self: *Self, arena: std.mem.Allocator, failed_command: []const u8, verify_context: ?[]const u8, context_comment: ?[]const u8) ?[]Command.Command {
|
||||
const ha = self.message_arena.allocator();
|
||||
|
||||
const verify_section = if (verify_context) |ctx|
|
||||
@@ -672,7 +672,7 @@ fn attemptSelfHeal(self: *Self, failed_command: []const u8, verify_context: ?[]c
|
||||
|
||||
var attempt: u8 = 0;
|
||||
while (attempt < self_heal_max_attempts) : (attempt += 1) {
|
||||
const cmds = self.runHealTurn(prompt, arena) catch |err| {
|
||||
const cmds = self.runHealTurn(arena, prompt) catch |err| {
|
||||
self.terminal.printErrorFmt("self-heal attempt {d}/{d} failed: {s}", .{
|
||||
attempt + 1,
|
||||
self_heal_max_attempts,
|
||||
|
||||
@@ -55,7 +55,7 @@ pub fn deinit(self: *Self) void {
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
|
||||
pub const CallError = browser_tools.ToolError || error{ InvalidJsonArguments, OutOfMemory };
|
||||
pub const CallError = browser_tools.ToolError || error{InvalidJsonArguments};
|
||||
|
||||
pub fn getTools(self: *Self) ![]const zenai.provider.Tool {
|
||||
const arena = self.tool_schema_arena.allocator();
|
||||
@@ -89,11 +89,11 @@ pub fn callEval(self: *Self, arena: std.mem.Allocator, script: []const u8) ?[]co
|
||||
}
|
||||
|
||||
pub fn call(self: *Self, arena: std.mem.Allocator, tool_name: []const u8, arguments_json: []const u8) CallError![]const u8 {
|
||||
const arguments = if (arguments_json.len > 0) blk: {
|
||||
const parsed = std.json.parseFromSlice(std.json.Value, arena, arguments_json, .{}) catch
|
||||
return error.InvalidJsonArguments;
|
||||
break :blk parsed.value;
|
||||
} else null;
|
||||
const arguments: ?std.json.Value = if (arguments_json.len > 0)
|
||||
std.json.parseFromSliceLeaky(std.json.Value, arena, arguments_json, .{}) catch
|
||||
return error.InvalidJsonArguments
|
||||
else
|
||||
null;
|
||||
|
||||
return browser_tools.call(self.session, &self.node_registry, arena, tool_name, arguments);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user