mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-28 23:50:05 +00:00
@@ -172,7 +172,8 @@ pub const tool_list = [_]protocol.Tool{
|
||||
|
||||
pub fn handleList(server: *Server, arena: std.mem.Allocator, req: protocol.Request) !void {
|
||||
_ = arena;
|
||||
try server.sendResult(req.id.?, .{ .tools = &tool_list });
|
||||
const id = req.id orelse return;
|
||||
try server.sendResult(id, .{ .tools = &tool_list });
|
||||
}
|
||||
|
||||
const GotoParams = struct {
|
||||
@@ -205,17 +206,18 @@ const ToolStreamingText = struct {
|
||||
switch (self.action) {
|
||||
.markdown => lp.markdown.dump(self.page.document.asNode(), .{}, w, self.page) catch |err| {
|
||||
log.err(.mcp, "markdown dump failed", .{ .err = err });
|
||||
return error.WriteFailed;
|
||||
},
|
||||
.links => {
|
||||
if (lp.links.collectLinks(self.page.call_arena, self.page.document.asNode(), self.page)) |links| {
|
||||
var first = true;
|
||||
for (links) |href| {
|
||||
if (!first) try w.writeByte('\n');
|
||||
try w.writeAll(href);
|
||||
first = false;
|
||||
}
|
||||
} else |err| {
|
||||
const links = lp.links.collectLinks(self.page.call_arena, self.page.document.asNode(), self.page) catch |err| {
|
||||
log.err(.mcp, "query links failed", .{ .err = err });
|
||||
return error.WriteFailed;
|
||||
};
|
||||
var first = true;
|
||||
for (links) |href| {
|
||||
if (!first) try w.writeByte('\n');
|
||||
try w.writeAll(href);
|
||||
first = false;
|
||||
}
|
||||
},
|
||||
.semantic_tree => {
|
||||
@@ -241,6 +243,7 @@ const ToolStreamingText = struct {
|
||||
|
||||
st.textStringify(w) catch |err| {
|
||||
log.err(.mcp, "semantic tree dump failed", .{ .err = err });
|
||||
return error.WriteFailed;
|
||||
};
|
||||
},
|
||||
}
|
||||
@@ -331,7 +334,9 @@ fn handleMarkdown(server: *Server, arena: std.mem.Allocator, id: std.json.Value,
|
||||
const content = [_]protocol.TextContent(ToolStreamingText){.{
|
||||
.text = .{ .page = page, .action = .markdown },
|
||||
}};
|
||||
try server.sendResult(id, protocol.CallToolResult(ToolStreamingText){ .content = &content });
|
||||
server.sendResult(id, protocol.CallToolResult(ToolStreamingText){ .content = &content }) catch {
|
||||
return server.sendError(id, .InternalError, "Failed to serialize markdown content");
|
||||
};
|
||||
}
|
||||
|
||||
fn handleLinks(server: *Server, arena: std.mem.Allocator, id: std.json.Value, arguments: ?std.json.Value) !void {
|
||||
@@ -341,7 +346,9 @@ fn handleLinks(server: *Server, arena: std.mem.Allocator, id: std.json.Value, ar
|
||||
const content = [_]protocol.TextContent(ToolStreamingText){.{
|
||||
.text = .{ .page = page, .action = .links },
|
||||
}};
|
||||
try server.sendResult(id, protocol.CallToolResult(ToolStreamingText){ .content = &content });
|
||||
server.sendResult(id, protocol.CallToolResult(ToolStreamingText){ .content = &content }) catch {
|
||||
return server.sendError(id, .InternalError, "Failed to serialize links content");
|
||||
};
|
||||
}
|
||||
|
||||
fn handleSemanticTree(server: *Server, arena: std.mem.Allocator, id: std.json.Value, arguments: ?std.json.Value) !void {
|
||||
@@ -363,7 +370,9 @@ fn handleSemanticTree(server: *Server, arena: std.mem.Allocator, id: std.json.Va
|
||||
.maxDepth = args.maxDepth,
|
||||
},
|
||||
}};
|
||||
try server.sendResult(id, protocol.CallToolResult(ToolStreamingText){ .content = &content });
|
||||
server.sendResult(id, protocol.CallToolResult(ToolStreamingText){ .content = &content }) catch {
|
||||
return server.sendError(id, .InternalError, "Failed to serialize semantic tree content");
|
||||
};
|
||||
}
|
||||
|
||||
fn handleInteractiveElements(server: *Server, arena: std.mem.Allocator, id: std.json.Value, arguments: ?std.json.Value) !void {
|
||||
|
||||
Reference in New Issue
Block a user