Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/crates/aw-ai/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ chrono-tz.workspace = true
tracing.workspace = true
reqwest.workspace = true
regex = "1"
sha2 = "0.10"
sha2 = "0.11"
tokio = { version = "1", features = ["rt-multi-thread", "time"] }
13 changes: 10 additions & 3 deletions rust/crates/aw-ai/src/explainer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ use crate::provider::{
use crate::pyfmt::{self, truthy};
use crate::transport::{self, CancelToken, StreamLimits};

fn sha256_hex(bytes: &[u8]) -> String {
Sha256::digest(bytes)
.iter()
.map(|b| format!("{b:02x}"))
.collect()
}

/// How long an explanation stays cached. Python's `Cache` is created with
/// `ai_cache_ttl`, but the explainer always stores with `ttl=300`.
pub const EXPLANATION_CACHE_TTL: Duration = Duration::from_secs(300);
Expand Down Expand Up @@ -529,7 +536,7 @@ impl AiExplainer {
string(&self.effective_system_prompt(style)),
string(&self.build_prompt(weather, location_name)),
);
format!("ai_explanation:v2:{:x}", Sha256::digest(dumped.as_bytes()))
format!("ai_explanation:v2:{}", sha256_hex(dumped.as_bytes()))
}

/// `_text_product_cache_key`.
Expand All @@ -541,10 +548,10 @@ impl AiExplainer {
style: ExplanationStyle,
) -> String {
format!(
"ai_text_product:{}:{}:{product_type}:{location_name}:{:x}:{}",
"ai_text_product:{}:{}:{product_type}:{location_name}:{}:{}",
self.provider.as_str(),
self.effective_model(),
Sha256::digest(product_text.as_bytes()),
sha256_hex(product_text.as_bytes()),
style.as_str()
)
}
Expand Down
2 changes: 1 addition & 1 deletion rust/crates/aw-notify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ chrono.workspace = true
tracing.workspace = true
tempfile.workspace = true
regex = "1"
sha2 = "0.10"
sha2 = "0.11"

[target.'cfg(windows)'.dependencies]
windows = { version = "0.62", features = [
Expand Down
2 changes: 1 addition & 1 deletion rust/crates/aw-services/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ reqwest.workspace = true
tempfile.workspace = true
url.workspace = true
regex = "1"
sha2 = "0.10"
sha2 = "0.11"
md5 = "0.8"

[target.'cfg(windows)'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion rust/xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ flate2 = "1"
icns = "0.5"
image = { version = "0.25", default-features = false, features = ["png", "ico"] }
regex = "1"
sha2 = "0.10"
sha2 = "0.11"
tar = "0.4"
zip = { version = "9.0.5", default-features = false, features = ["deflate"] }

Expand Down
19 changes: 16 additions & 3 deletions rust/xtask/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! Each artifact gets a `<name>.sha256` beside it.

use std::fs;
use std::io::Write;
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use std::process::Command;

Expand Down Expand Up @@ -682,12 +682,25 @@ fn remove_file_if_exists(path: &Path) -> Result<()> {
/// `<name>.sha256` in `sha256sum` format.
fn write_sha256(path: &Path) -> Result<()> {
let mut hasher = Sha256::new();
std::io::copy(&mut fs::File::open(path)?, &mut hasher)?;
let mut file = fs::File::open(path)?;
let mut buf = [0u8; 8192];
loop {
let n = file.read(&mut buf)?;
if n == 0 {
break;
}
hasher.update(&buf[..n]);
}
let name = path
.file_name()
.expect("artifact has a name")
.to_string_lossy();
let digest = hasher
.finalize()
.iter()
.map(|b| format!("{b:02x}"))
.collect::<String>();
let mut sum = fs::File::create(format!("{}.sha256", path.display()))?;
writeln!(sum, "{:x} {name}", hasher.finalize())?;
writeln!(sum, "{digest} {name}")?;
Ok(())
}
Loading