mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-06-11 09:35:59 -04:00
agent: remove unused code and add recorder guard
This commit is contained in:
@@ -920,15 +920,17 @@ fn processUserMessage(self: *Self, user_input: []const u8, record_comment: ?[]co
|
||||
};
|
||||
defer result.deinit();
|
||||
|
||||
var recorded_any = false;
|
||||
for (result.tool_calls_made) |tc| {
|
||||
if (!tc.is_error) {
|
||||
if (Command.fromToolCall(ma, tc.name, tc.arguments)) |cmd| {
|
||||
if (!recorded_any) {
|
||||
if (record_comment) |c| self.recorder.recordComment(c);
|
||||
recorded_any = true;
|
||||
if (self.recorder.file != null) {
|
||||
var recorded_any = false;
|
||||
for (result.tool_calls_made) |tc| {
|
||||
if (!tc.is_error) {
|
||||
if (Command.fromToolCall(ma, tc.name, tc.arguments)) |cmd| {
|
||||
if (!recorded_any) {
|
||||
if (record_comment) |c| self.recorder.recordComment(c);
|
||||
recorded_any = true;
|
||||
}
|
||||
self.recorder.record(cmd);
|
||||
}
|
||||
self.recorder.record(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ pub const ExecResult = struct {
|
||||
};
|
||||
|
||||
pub fn executeWithResult(self: *Self, arena: std.mem.Allocator, cmd: Command.Command) ExecResult {
|
||||
// EXTRACT has no 1:1 tool mapping — it compiles to a custom `eval` script.
|
||||
if (cmd == .extract) return self.execExtract(arena, cmd.extract);
|
||||
|
||||
const tc = Command.toToolCall(arena, cmd, browser_tools.substituteEnvVars) orelse switch (cmd) {
|
||||
@@ -62,8 +61,6 @@ fn callTool(self: *Self, arena: std.mem.Allocator, tool_name: []const u8, argume
|
||||
fn execExtract(self: *Self, arena: std.mem.Allocator, raw_selector: []const u8) ExecResult {
|
||||
const selector = browser_tools.substituteEnvVars(arena, raw_selector);
|
||||
|
||||
// A JSON-quoted string is also a valid JS string literal, so reuse
|
||||
// `buildJson` to splice the selector into the querySelectorAll call.
|
||||
const script = std.fmt.allocPrint(
|
||||
arena,
|
||||
"JSON.stringify(Array.from(document.querySelectorAll({s})).map(el => el.textContent.trim()))",
|
||||
|
||||
@@ -28,11 +28,6 @@ pub const SchemaInfo = struct {
|
||||
hints: []const HintSlot,
|
||||
};
|
||||
|
||||
pub const Parsed = struct {
|
||||
schema: *const SchemaInfo,
|
||||
args_json: []const u8,
|
||||
};
|
||||
|
||||
pub const ParseError = error{
|
||||
MissingName,
|
||||
UnknownTool,
|
||||
@@ -152,14 +147,6 @@ pub fn splitNameRest(input: []const u8) ?Split {
|
||||
};
|
||||
}
|
||||
|
||||
/// Parse a slash command body (without the leading `/`).
|
||||
/// `arena` is used for the resulting JSON string and any temporary storage.
|
||||
pub fn parse(arena: std.mem.Allocator, schemas: []const SchemaInfo, input: []const u8) ParseError!Parsed {
|
||||
const split = splitNameRest(input) orelse return error.MissingName;
|
||||
const schema = findSchema(schemas, split.name) orelse return error.UnknownTool;
|
||||
return .{ .schema = schema, .args_json = try parseArgs(arena, schema, split.rest) };
|
||||
}
|
||||
|
||||
/// Parse the args portion of a slash command for an already-resolved schema.
|
||||
pub fn parseArgs(arena: std.mem.Allocator, schema: *const SchemaInfo, rest: []const u8) ParseError![]const u8 {
|
||||
if (rest.len == 0) {
|
||||
@@ -315,7 +302,12 @@ fn lookupFieldType(schema: *const SchemaInfo, key: []const u8) FieldType {
|
||||
|
||||
const testing = std.testing;
|
||||
|
||||
fn parseWithCache(arena: std.mem.Allocator, input: []const u8) !Parsed {
|
||||
const ParsedTest = struct {
|
||||
schema: *const SchemaInfo,
|
||||
args_json: []const u8,
|
||||
};
|
||||
|
||||
fn parseWithCache(arena: std.mem.Allocator, input: []const u8) !ParsedTest {
|
||||
const tools = try arena.alloc(zenai.provider.Tool, browser_tools.tool_defs.len);
|
||||
for (browser_tools.tool_defs, 0..) |td, i| {
|
||||
tools[i] = .{
|
||||
@@ -325,7 +317,9 @@ fn parseWithCache(arena: std.mem.Allocator, input: []const u8) !Parsed {
|
||||
};
|
||||
}
|
||||
const schemas = try buildSchemas(arena, tools);
|
||||
return parse(arena, schemas, input);
|
||||
const split = splitNameRest(input) orelse return error.MissingName;
|
||||
const schema = findSchema(schemas, split.name) orelse return error.UnknownTool;
|
||||
return .{ .schema = schema, .args_json = try parseArgs(arena, schema, split.rest) };
|
||||
}
|
||||
|
||||
fn expectParse(input: []const u8, expected_tool: []const u8, expected_json: []const u8) !void {
|
||||
|
||||
Reference in New Issue
Block a user