Lightpanda: the headless browser designed for AI and automation
auth: consider refreshable tokens in subscription check
Adrià Arrufat939feeb9a37c
diff --git a/src/agent/auth/auth.zig b/src/agent/auth/auth.zigindex 5d18ecfa0..502f582c4 100644--- a/src/agent/auth/auth.zig+++ b/src/agent/auth/auth.zig@@ -133,8 +133,8 @@ fn storeSaveAt(arena: std.mem.Allocator, dir: []const u8, id: []const u8, tokens.account_id = tokens.account_id,});- // Secrets file: owner read/write only, from the moment it exists. Written- // to a temp file and renamed so a failed write can't corrupt the store.+ // Secrets file: owner-only perms; temp+rename so a failed write can't+ // corrupt the store.var af = try std.Io.Dir.cwd().createFileAtomic(lp.io, path, .{ .permissions = .fromMode(0o600), .replace = true });defer af.deinit(lp.io);var buf: [1024]u8 = undefined;@@ -228,13 +228,14 @@ pub fn login(allocator: std.mem.Allocator, desc: *const Descriptor, interrupt: ?return .{ .allocator = allocator, .descriptor = desc, .tokens = tokens };}-/// Is a usable (present, not hard-expired) stored token available for `provider`?-/// Lets the picker offer the subscription without an API-key env var.+/// Is a stored credential available for `provider` — unexpired, or refreshable+/// (`ensureFresh` runs before the first request)? Lets the picker offer the+/// subscription without an API-key env var.pub fn subscriptionAvailable(provider: Config.AiProvider) bool {const desc = descriptorFor(provider) orelse return false;const tokens = (storeLoad(std.heap.page_allocator, desc.storeKey()) catch return false) orelse return false;defer tokens.deinit(std.heap.page_allocator);- return tokens.expires_at_ms > nowMs();+ return tokens.refresh_token.len > 0 or tokens.expires_at_ms > nowMs();}test "TokenSet dup/deinit round-trips and is leak-free" {diff --git a/src/agent/auth/models_dev.zig b/src/agent/auth/models_dev.zigindex ac4890d10..fc52c022a 100644--- a/src/agent/auth/models_dev.zig+++ b/src/agent/auth/models_dev.zig@@ -77,8 +77,8 @@ fn writeCache(arena: std.mem.Allocator, app_dir: []const u8, provider_id: []cons/// Model-id keys of `catalog[provider_id].models`, filtered to tool-call-capable/// models (the agent needs tools; this also drops embedding/image entries)./// `ignore_unknown_fields` skips the rest of the metadata, so no Value tree is-/// built for the multi-MB payload, but the parsed id map accumulates in `arena`-/// until the caller deinits it. The ids may alias `catalog`.+/// built for the multi-MB payload, but the parsed id map accumulates in+/// `arena`. The ids may alias `catalog`.fn parseProviderModels(arena: std.mem.Allocator, catalog: []const u8, provider_id: []const u8) ![]const []const u8 {const Model = struct { tool_call: bool = false };const Provider = struct { models: std.json.ArrayHashMap(Model) = .{} };