From dfbd06f2ffe3cd66a02228fcd08c827adf33cfd7 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Fri, 19 Dec 2025 06:06:40 -0500 Subject: [PATCH] refresh bearer --- .../worldlabs/handle_worldlabs_marble.rs | 19 +++++++++++++++++++ .../state/worldlabs_credential_manager.rs | 10 ++++++++++ 2 files changed, 29 insertions(+) diff --git a/crates/desktop/artcraft/src/core/commands/enqueue/image_to_gaussian/worldlabs/handle_worldlabs_marble.rs b/crates/desktop/artcraft/src/core/commands/enqueue/image_to_gaussian/worldlabs/handle_worldlabs_marble.rs index 977036ac15..9a6e5c4e8d 100644 --- a/crates/desktop/artcraft/src/core/commands/enqueue/image_to_gaussian/worldlabs/handle_worldlabs_marble.rs +++ b/crates/desktop/artcraft/src/core/commands/enqueue/image_to_gaussian/worldlabs/handle_worldlabs_marble.rs @@ -47,6 +47,14 @@ pub async fn handle_worldlabs_marble( } }; + let world_labs_refresh = match worldlabs_creds_manager.maybe_copy_refresh_token()? { + Some(bearer) => bearer, + None => { + error!("No WorldLabs refresh token!"); + return Err(GenerateError::MissingCredentials(MissingCredentialsReason::NeedsWorldLabsCredentials)); + } + }; + let job_id = generate_random_uuid(); let maybe_prompt = request.prompt @@ -66,6 +74,7 @@ pub async fn handle_worldlabs_marble( let response = upload_image_and_create_world_with_retry(UploadImageAndCreateWorldWithRetryArgs { cookies: &world_labs_cookies, bearer_token: &world_labs_bearer, + refresh_token: &world_labs_refresh, individual_request_timeout: None, file: FileBytesOrPath::Path(file_path), }).await?; @@ -75,6 +84,16 @@ pub async fn handle_worldlabs_marble( info!("Run ID: {:?}", run_id); info!("World ID: {:?}", world_id); + + if let Some(new_access) = response.maybe_new_access_tokens { + info!("New access tokens were generated; saving."); + worldlabs_creds_manager.replace_bearer_and_refresh_token( + new_access.bearer_token, + new_access.refresh_token + )?; + + worldlabs_creds_manager.persist_to_disk()?; + } Ok(TaskEnqueueSuccess { provider: GenerationProvider::WorldLabs, diff --git a/crates/desktop/artcraft/src/services/worldlabs/state/worldlabs_credential_manager.rs b/crates/desktop/artcraft/src/services/worldlabs/state/worldlabs_credential_manager.rs index 8f23128774..a1ba67c277 100644 --- a/crates/desktop/artcraft/src/services/worldlabs/state/worldlabs_credential_manager.rs +++ b/crates/desktop/artcraft/src/services/worldlabs/state/worldlabs_credential_manager.rs @@ -137,6 +137,16 @@ impl WorldlabsCredentialManager { } } + pub fn replace_bearer_and_refresh_token(&self, bearer_token: WorldLabsBearerToken, refresh_token: WorldLabsRefreshToken) -> anyhow::Result<()> { + match self.credential_data.write() { + Err(err) => Err(anyhow::anyhow!("Failed to acquire write lock: {:?}", err)), + Ok(mut holder) => { + holder.world_labs_bearer_token = Some(bearer_token); + holder.world_labs_refresh_token = Some(refresh_token); + Ok(()) + } + } + } // NB: This is just a heuristic. We'll add better checks later. pub fn do_task_polling(&self) -> anyhow::Result {