Lightpanda: the headless browser designed for AI and automation
Agent: support HF_BILL_TO for Hugging Face
Adrià Arrufat7a9924ab2283
diff --git a/build.zig.zon b/build.zig.zonindex ea05d96f2..9b9ec5429 100644--- a/build.zig.zon+++ b/build.zig.zon@@ -35,8 +35,8 @@.hash = "sqlite3-3.51.0-DMxLWssOAABZ8cAvU_LfBIbp0kZjm824PU8sSLXpEDdr",},.zenai = .{- .url = "git+https://github.com/lightpanda-io/zenai.git#12c776cff7f1244b6c147e6d4733f76e8dcc3a38",- .hash = "zenai-0.0.0-iOY_VAB7BACkAx4N1aMsFlqN5z4G2Qdqrh3u1DIIkaO1",+ .url = "git+https://github.com/lightpanda-io/zenai.git#3f9315fdf390b37ee8bda55f7e454327b0c1d931",+ .hash = "zenai-0.0.0-iOY_VJSBBADUifICag2s31rv-XZZ924Be_MVXXxFx22S",},.isocline = .{.url = "git+https://github.com/arrufat/isocline?ref=lightpanda#832a9fe25f5f4458fcc47b5acc7c21db669c2f47",diff --git a/src/agent/Agent.zig b/src/agent/Agent.zigindex 5f0ac1b90..b36073bc6 100644--- a/src/agent/Agent.zig+++ b/src/agent/Agent.zig@@ -381,7 +381,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 }) else null;+ 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;errdefer if (self.ai_client) |c| c.deinit(allocator);if (self.ai_client) |c| c.setInterrupt(&self.http_interrupt);@@ -885,8 +885,15 @@ fn disableProvider(self: *Agent) void {self.reportSaved("provider", provider_off_keyword);}+/// `HF_BILL_TO` org for routed requests; null for non-HF providers. Without it,+/// requests bill the token owner's personal account instead of the org.+fn hfBillTo(provider: Config.AiProvider) ?[]const u8 {+ if (provider != .huggingface) return null;+ return std.posix.getenv("HF_BILL_TO");+}+fn setProvider(self: *Agent, credentials: Credentials) !void {- const new_client = try zenai.provider.Client.init(self.allocator, credentials, .{ .base_url = self.model_base_url, .retry_policy = .long_running });+ 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) });errdefer new_client.deinit(self.allocator);const new_model = try self.allocator.dupe(u8, zenai.provider.defaultModel(credentials.provider));