mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-06-11 09:35:59 -04:00
tools: add getEnv tool to read environment variables
This commit is contained in:
@@ -55,6 +55,7 @@ const Action = enum {
|
||||
selectOption,
|
||||
setChecked,
|
||||
findElement,
|
||||
getEnv,
|
||||
};
|
||||
|
||||
const action_map = std.StaticStringMap(Action).initComptime(.{
|
||||
@@ -78,6 +79,7 @@ const action_map = std.StaticStringMap(Action).initComptime(.{
|
||||
.{ "selectOption", .selectOption },
|
||||
.{ "setChecked", .setChecked },
|
||||
.{ "findElement", .findElement },
|
||||
.{ "getEnv", .getEnv },
|
||||
});
|
||||
|
||||
/// Execute a tool by name. Returns the result text.
|
||||
@@ -113,6 +115,7 @@ pub fn call(
|
||||
.selectOption => execSelectOption(session, registry, arena, arguments),
|
||||
.setChecked => execSetChecked(session, registry, arena, arguments),
|
||||
.findElement => execFindElement(session, registry, arena, arguments),
|
||||
.getEnv => execGetEnv(arena, arguments),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -497,6 +500,15 @@ fn execFindElement(session: *lp.Session, registry: *CDPNode.Registry, arena: std
|
||||
return aw.written();
|
||||
}
|
||||
|
||||
fn execGetEnv(arena: std.mem.Allocator, arguments: ?std.json.Value) ToolError![]const u8 {
|
||||
const Params = struct { name: []const u8 };
|
||||
const args = parseArgsOrErr(Params, arena, arguments) orelse return ToolError.InvalidParams;
|
||||
const name_z = arena.dupeZ(u8, args.name) catch return ToolError.InternalError;
|
||||
const value = std.posix.getenv(name_z) orelse
|
||||
return std.fmt.allocPrint(arena, "Environment variable '{s}' is not set", .{args.name}) catch ToolError.InternalError;
|
||||
return value;
|
||||
}
|
||||
|
||||
// --- Shared helpers ---
|
||||
|
||||
fn ensurePage(session: *lp.Session, registry: *CDPNode.Registry, url: ?[:0]const u8, timeout: ?u32, waitUntil: ?lp.Config.WaitUntil) ToolError!*lp.Page {
|
||||
|
||||
@@ -241,6 +241,19 @@ pub const tool_list = [_]protocol.Tool{
|
||||
\\}
|
||||
),
|
||||
},
|
||||
.{
|
||||
.name = "getEnv",
|
||||
.description = "Read the value of an environment variable. Useful for retrieving credentials or configuration without hardcoding them.",
|
||||
.inputSchema = protocol.minify(
|
||||
\\{
|
||||
\\ "type": "object",
|
||||
\\ "properties": {
|
||||
\\ "name": { "type": "string", "description": "The environment variable name to read." }
|
||||
\\ },
|
||||
\\ "required": ["name"]
|
||||
\\}
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
pub fn handleList(server: *Server, arena: std.mem.Allocator, req: protocol.Request) !void {
|
||||
|
||||
Reference in New Issue
Block a user