Lightpanda: the headless browser designed for AI and automation
update zenai dep (zig 0.16)
Karl Seguin802862120f7a
diff --git a/build.zig.zon b/build.zig.zonindex 0d9b0f1fa..725fbed4d 100644--- a/build.zig.zon+++ b/build.zig.zon@@ -36,8 +36,8 @@.hash = "sqlite3-3.53.2-DMxLWuAOAAA_Px0arJOIOaP4AKEu5prbsQgPMA35W1zz",},.zenai = .{- .url = "git+https://github.com/lightpanda-io/zenai.git#1df180de89ef72535d973af7854bf24dc8ab94a7",- .hash = "zenai-0.0.0-iOY_VPyeBQDnDr5NOUWDK7HWpFTJR8JXZ5UYcwNGEMOu",+ .url = "git+https://github.com/lightpanda-io/zenai.git#00c793fdd2797ae5fc9700c189d8617f167ae0dc",+ .hash = "zenai-0.0.0-iOY_VGOnBQDaWE_Gn8cwhh0XXE8RZ8ESE7QtcITF-P73",},.isocline = .{.url = "git+https://github.com/arrufat/isocline?ref=lightpanda#832a9fe25f5f4458fcc47b5acc7c21db669c2f47",diff --git a/src/agent/Agent.zig b/src/agent/Agent.zigindex fd84923b7..c2481a919 100644--- a/src/agent/Agent.zig+++ b/src/agent/Agent.zig@@ -353,7 +353,7 @@ pub fn init(allocator: std.mem.Allocator, app: *App, opts: Config.Agent) !*Agenttry self.startSession();- self.ai_client = if (llm) |l| try zenai.provider.Client.init(allocator, l, .{ .base_url = opts.base_url, .retry_policy = .long_running, .bill_to = hfBillTo(l.provider) }) else null;+ self.ai_client = if (llm) |l| try zenai.provider.Client.init(allocator, lp.io, l, .{ .base_url = opts.base_url, .retry_policy = .long_running, .bill_to = hfBillTo(l.provider), .environ = lp.environ() }) else null;errdefer if (self.ai_client) |c| c.deinit(allocator);if (self.ai_client) |c| c.setInterrupt(&self.http_interrupt);@@ -922,7 +922,7 @@ fn handleProvider(self: *Agent, _: std.mem.Allocator, rest: []const u8) void {};return;}- const key = zenai.provider.envApiKey(provider) orelse {+ const key = zenai.provider.envApiKey(lp.environ(), provider) orelse {if (provider == .vertex) {self.terminal.printError("vertex needs VERTEX_API_KEY (express mode) or GOOGLE_CLOUD_PROJECT (project mode, token via gcloud)", .{});return;@@ -968,7 +968,7 @@ fn hfBillTo(provider: Config.AiProvider) ?[]const u8 {/// `owned_key` transfers ownership of an allocated `credentials.key` (Vertex/// gcloud token) on success; on error the caller still owns it.fn setProvider(self: *Agent, credentials: Credentials, owned_key: ?[:0]const u8) !void {- const new_client = try zenai.provider.Client.init(self.allocator, credentials, .{ .base_url = self.model_base_url, .retry_policy = .long_running, .bill_to = hfBillTo(credentials.provider) });+ const new_client = try zenai.provider.Client.init(self.allocator, lp.io, credentials, .{ .base_url = self.model_base_url, .retry_policy = .long_running, .bill_to = hfBillTo(credentials.provider), .environ = lp.environ() });errdefer new_client.deinit(self.allocator);// A same-provider re-select (vertex token refresh) must not reset the model.@@ -1845,7 +1845,7 @@ pub fn listModels(allocator: std.mem.Allocator, opts: Config.Agent) !void {var arena: std.heap.ArenaAllocator = .init(allocator);defer arena.deinit();- const ids = zenai.provider.listChatModelIds(allocator, arena.allocator(), llm.provider, llm.key, opts.base_url) catch |err| {+ const ids = zenai.provider.listChatModelIds(allocator, lp.io, arena.allocator(), llm.provider, llm.key, opts.base_url, lp.environ()) catch |err| {if (llm.provider == .vertex and !settings.vertexProjectMode()) {std.debug.print("Vertex express mode cannot list models (the endpoint requires OAuth); set GOOGLE_CLOUD_PROJECT for project mode.\n", .{});}@@ -1903,10 +1903,12 @@ fn completionModels(context: *anyopaque, _: std.mem.Allocator) []const []const u_ = self.model_completion_arena.reset(.retain_capacity);const ids = zenai.provider.listChatModelIds(self.allocator,+ lp.io,self.model_completion_arena.allocator(),llm.provider,llm.key,self.model_base_url,+ lp.environ(),) catch &.{};self.model_completions = .{ .provider = llm.provider, .ids = ids };return ids;diff --git a/src/agent/settings.zig b/src/agent/settings.zigindex b78544fc2..f819758dd 100644--- a/src/agent/settings.zig+++ b/src/agent/settings.zig@@ -47,10 +47,10 @@ pub const ResolvedProvider = struct {/// placeholder, so the only honest availability signal is the server answering/// `/v1/models` with a loaded model. Null means no server responded.pub fn detectLocalProvider(allocator: std.mem.Allocator, tag: Config.AiProvider, base_url: ?[:0]const u8) ?Credentials {- const key = zenai.provider.envApiKey(tag) orelse return null;+ const key = zenai.provider.envApiKey(lp.environ(), tag) orelse return null;var arena: std.heap.ArenaAllocator = .init(allocator);defer arena.deinit();- const ids = zenai.provider.listChatModelIds(allocator, arena.allocator(), tag, key, base_url) catch return null;+ const ids = zenai.provider.listChatModelIds(allocator, lp.io, arena.allocator(), tag, key, base_url, lp.environ()) catch return null;if (ids.len == 0) return null;return .{ .provider = tag, .key = key };}@@ -97,9 +97,9 @@ pub fn gcloudAccessToken(allocator: std.mem.Allocator) ![:0]const u8 {/// env-detected). Skips the Ollama probe so it isn't run twice at startup; the/// interactive picker only fires on detected keys, which this still catches.pub fn hasDetectableKey(opts: Config.Agent, remembered: ?Remembered) bool {- if (opts.provider) |p| return zenai.provider.envApiKey(p) != null or (p == .vertex and vertexProjectMode());+ if (opts.provider) |p| return zenai.provider.envApiKey(lp.environ(), p) != null or (p == .vertex and vertexProjectMode());if (remembered) |r| if (r.provider) |p| {- if (zenai.provider.envApiKey(p) != null) return true;+ if (zenai.provider.envApiKey(lp.environ(), p) != null) return true;if (p == .vertex and vertexProjectMode()) return true;};var buf: [zenai.provider.default_candidates.len]Credentials = undefined;@@ -114,7 +114,7 @@ pub fn resolveCredentials(allocator: std.mem.Allocator, opts: Config.Agent, remeconst token = try gcloudAccessToken(allocator);return .{ .credentials = .{ .provider = p, .key = token }, .source = .flag, .key_owned = true };}- const key = zenai.provider.envApiKey(p) orelse {+ const key = zenai.provider.envApiKey(lp.environ(), p) orelse {if (p == .vertex) {std.debug.print("Vertex needs VERTEX_API_KEY (express mode) or GOOGLE_CLOUD_PROJECT (project mode, token via gcloud) — or pass --no-llm for the basic REPL.\n",@@ -137,7 +137,7 @@ pub fn resolveCredentials(allocator: std.mem.Allocator, opts: Config.Agent, remeif (gcloudAccessToken(allocator)) |token| {return .{ .credentials = .{ .provider = p, .key = token }, .source = .remembered, .key_owned = true };} else |_| {}- } else if (zenai.provider.envApiKey(p)) |key| {+ } else if (zenai.provider.envApiKey(lp.environ(), p)) |key| {return .{ .credentials = .{ .provider = p, .key = key }, .source = .remembered };}};@@ -234,8 +234,8 @@ pub fn saveRemembered(remembered: Remembered) !void {/// Vertex project mode joins with a placeholder key — no subprocess during a/// scan; the gcloud token is fetched on selection (`finishResolved`).pub fn availableProviders(buf: []Credentials) []Credentials {- const found = zenai.provider.detectKeys(buf, zenai.provider.default_candidates);- if (zenai.provider.useVertex() and vertexProjectMode() and found.len < buf.len) {+ const found = zenai.provider.detectKeys(lp.environ(), buf, zenai.provider.default_candidates);+ if (zenai.provider.useVertex(lp.environ()) and vertexProjectMode() and found.len < buf.len) {buf[found.len] = .{ .provider = .vertex, .key = "" };return buf[0 .. found.len + 1];}@@ -302,7 +302,7 @@ pub fn reconcileModel() !ReconciledModel {var arena: std.heap.ArenaAllocator = .init(allocator);defer arena.deinit();- const ids: []const []const u8 = zenai.provider.listChatModelIds(allocator, arena.allocator(), llm.provider, llm.key, base_url) catch &.{};+ const ids: []const []const u8 = zenai.provider.listChatModelIds(allocator, lp.io, arena.allocator(), llm.provider, llm.key, base_url, lp.environ()) catch &.{};if (ids.len == 0 or string.isOneOf(desired, ids)) return .{ .use = try allocator.dupe(u8, desired) };if (!explicit) {diff --git a/src/browser/tools.zig b/src/browser/tools.zigindex eb0af630b..6e295d8a1 100644--- a/src/browser/tools.zig+++ b/src/browser/tools.zig@@ -982,7 +982,7 @@ fn tavilySearch(api_key: []const u8,query: []const u8,) ![]const u8 {- var client: tavily.Client = .init(arena, api_key, .{});+ var client: tavily.Client = .init(arena, lp.io, api_key, .{});defer client.deinit();var response = client.search(query, .{ .max_results = 10 }) catch |err| {diff --git a/src/lightpanda.zig b/src/lightpanda.zigindex d1d514b2f..06ceb23d7 100644--- a/src/lightpanda.zig+++ b/src/lightpanda.zig@@ -68,12 +68,18 @@ pub var metrics = @import("Metrics.zig"){};var io_threaded: std.Io.Threaded = .init_single_threaded;pub const io: std.Io = io_threaded.io();-/// The single-threaded Io instance carries an empty environ, so spawned-/// children that should inherit the process environment must pass this map-/// (argv[0] PATH resolution always uses the parent environment regardless).+/// The single-threaded Io instance carries an empty environ; consumers that+/// need the real process environment (env-var lookups, spawned children) use+/// this instead.+pub fn environ() std.process.Environ {+ return .{ .block = .{ .slice = std.mem.span(std.c.environ) } };+}++/// Environ.Map view of `environ` for spawned children that should inherit the+/// process environment (argv[0] PATH resolution always uses the parent+/// environment regardless).pub fn environMap(allocator: std.mem.Allocator) !std.process.Environ.Map {- const environ: std.process.Environ = .{ .block = .{ .slice = std.mem.span(std.c.environ) } };- return environ.createMap(allocator);+ return environ().createMap(allocator);}/// Io.Condition has no timed wait (@ZIG16: delete when std grows one).