Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Attachments: read_attachment returns a PDF's text, page by page

Lin (kwant bot)70bfc0f04d8f
diff --git a/Cargo.lock b/Cargo.lock
index 9b3418d0..d51eeb39 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2,6 +2,32 @@
# It is not intended for manual editing.
version = 4
+[[package]]
+name = "adler2"
+version = "2.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
+
+[[package]]
+name = "adobe-cmap-parser"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ae8abfa9a4688de8fc9f42b3f013b6fffec18ed8a554f5f113577e0b9b3212a3"
+dependencies = [
+ "pom",
+]
+
+[[package]]
+name = "aes"
+version = "0.8.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0"
+dependencies = [
+ "cfg-if",
+ "cipher",
+ "cpufeatures 0.2.17",
+]
+
[[package]]
name = "aho-corasick"
version = "1.1.5"
@@ -223,6 +249,15 @@ dependencies = [
"hybrid-array",
]
+[[package]]
+name = "block-padding"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93"
+dependencies = [
+ "generic-array",
+]
+
[[package]]
name = "bumpalo"
version = "3.20.3"
@@ -241,6 +276,15 @@ version = "1.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"
+[[package]]
+name = "cbc"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6"
+dependencies = [
+ "cipher",
+]
+
[[package]]
name = "cc"
version = "1.8.0"
@@ -251,6 +295,12 @@ dependencies = [
"shlex",
]
+[[package]]
+name = "cff-parser"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c5810ca1a2b5870df2aab1c03e11c40c361ba51d6e3e361e56310f1cb3b4e087"
+
[[package]]
name = "cfg-if"
version = "1.0.5"
@@ -263,6 +313,17 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527"
+[[package]]
+name = "chacha20"
+version = "0.10.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06"
+dependencies = [
+ "cfg-if",
+ "cpufeatures 0.3.1",
+ "rand_core 0.10.1",
+]
+
[[package]]
name = "chrono"
version = "0.4.45"
@@ -277,6 +338,16 @@ dependencies = [
"windows-link",
]
+[[package]]
+name = "cipher"
+version = "0.4.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
+dependencies = [
+ "crypto-common 0.1.7",
+ "inout",
+]
+
[[package]]
name = "clap"
version = "4.6.7"
@@ -521,6 +592,15 @@ version = "0.15.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
+[[package]]
+name = "ecb"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1a8bfa975b1aec2145850fcaa1c6fe269a16578c44705a532ae3edc92b8881c7"
+dependencies = [
+ "cipher",
+]
+
[[package]]
name = "either"
version = "1.19.0"
@@ -571,6 +651,15 @@ dependencies = [
"windows-sys 0.48.0",
]
+[[package]]
+name = "euclid"
+version = "0.20.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2bb7ef65b3777a325d1eeefefab5b6d4959da54747e33bd6258e789640f307ad"
+dependencies = [
+ "num-traits",
+]
+
[[package]]
name = "event-listener"
version = "5.4.2"
@@ -599,6 +688,8 @@ version = "1.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e634e2e0ebac1ee034020da1ca582e17ffe4e0f5e985823721e168928136dcb"
dependencies = [
+ "crc32fast",
+ "miniz_oxide",
"zlib-rs",
]
@@ -776,8 +867,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
dependencies = [
"cfg-if",
+ "js-sys",
"libc",
"r-efi",
+ "rand_core 0.10.1",
+ "wasm-bindgen",
]
[[package]]
@@ -1141,6 +1235,16 @@ dependencies = [
"hashbrown 0.17.1",
]
+[[package]]
+name = "inout"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"
+dependencies = [
+ "block-padding",
+ "generic-array",
+]
+
[[package]]
name = "ipnet"
version = "2.12.2"
@@ -1183,6 +1287,7 @@ dependencies = [
"futures",
"libc",
"mime_guess",
+ "pdf-extract",
"percent-encoding",
"reqwest",
"rust-embed",
@@ -1279,6 +1384,33 @@ version = "0.4.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6"
+[[package]]
+name = "lopdf"
+version = "0.42.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "25aab26d99567469098e64a02f42679f8965c6401263eefa31d8f2dcc37a221c"
+dependencies = [
+ "aes",
+ "bitflags",
+ "cbc",
+ "ecb",
+ "encoding_rs",
+ "flate2",
+ "getrandom 0.4.3",
+ "indexmap",
+ "itoa",
+ "log",
+ "md-5",
+ "nom",
+ "rand 0.10.3",
+ "rangemap",
+ "sha2 0.10.9",
+ "stringprep",
+ "thiserror 2.0.21",
+ "ttf-parser",
+ "weezl",
+]
+
[[package]]
name = "matchers"
version = "0.2.0"
@@ -1326,6 +1458,16 @@ dependencies = [
"unicase",
]
+[[package]]
+name = "miniz_oxide"
+version = "0.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c"
+dependencies = [
+ "adler2",
+ "simd-adler32",
+]
+
[[package]]
name = "mio"
version = "1.2.4"
@@ -1372,6 +1514,15 @@ dependencies = [
"libc",
]
+[[package]]
+name = "nom"
+version = "8.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405"
+dependencies = [
+ "memchr",
+]
+
[[package]]
name = "nu-ansi-term"
version = "0.50.3"
@@ -1392,7 +1543,7 @@ dependencies = [
"num-integer",
"num-iter",
"num-traits",
- "rand",
+ "rand 0.8.8",
"smallvec",
"zeroize",
]
@@ -1516,6 +1667,23 @@ dependencies = [
"windows-link",
]
+[[package]]
+name = "pdf-extract"
+version = "0.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e5c4820f5811e424ce037d08493ac87752ecc54339e0f1e40c3d17da93278861"
+dependencies = [
+ "adobe-cmap-parser",
+ "cff-parser",
+ "encoding_rs",
+ "euclid",
+ "log",
+ "lopdf",
+ "postscript",
+ "type1-encoding-parser",
+ "unicode-normalization",
+]
+
[[package]]
name = "pem-rfc7468"
version = "0.7.0"
@@ -1590,6 +1758,18 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
+[[package]]
+name = "pom"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "60f6ce597ecdcc9a098e7fddacb1065093a3d66446fa16c675e7e71d1b5c28e6"
+
+[[package]]
+name = "postscript"
+version = "0.14.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "78451badbdaebaf17f053fd9152b3ffb33b516104eacb45e7864aaa9c712f306"
+
[[package]]
name = "potential_utf"
version = "0.1.6"
@@ -1640,7 +1820,18 @@ checksum = "e058c7de0b26af77780c769414d6257830bb240f3c38477dbc2c16e5f54d6d4c"
dependencies = [
"libc",
"rand_chacha",
- "rand_core",
+ "rand_core 0.6.4",
+]
+
+[[package]]
+name = "rand"
+version = "0.10.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af"
+dependencies = [
+ "chacha20",
+ "getrandom 0.4.3",
+ "rand_core 0.10.1",
]
[[package]]
@@ -1650,7 +1841,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
- "rand_core",
+ "rand_core 0.6.4",
]
[[package]]
@@ -1662,6 +1853,18 @@ dependencies = [
"getrandom 0.2.17",
]
+[[package]]
+name = "rand_core"
+version = "0.10.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
+
+[[package]]
+name = "rangemap"
+version = "1.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a611d15b50743feb4c76b7d03edcb0e64f399c26961e4efe6975bc398be6aa3d"
+
[[package]]
name = "redox_syscall"
version = "0.5.18"
@@ -1778,7 +1981,7 @@ dependencies = [
"num-traits",
"pkcs1",
"pkcs8",
- "rand_core",
+ "rand_core 0.6.4",
"signature",
"spki",
"subtle",
@@ -2079,7 +2282,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de"
dependencies = [
"digest 0.10.7",
- "rand_core",
+ "rand_core 0.6.4",
]
[[package]]
@@ -2256,7 +2459,7 @@ dependencies = [
"memchr",
"once_cell",
"percent-encoding",
- "rand",
+ "rand 0.8.8",
"rsa",
"serde",
"sha1",
@@ -2295,7 +2498,7 @@ dependencies = [
"md-5",
"memchr",
"once_cell",
- "rand",
+ "rand 0.8.8",
"serde",
"serde_json",
"sha2 0.10.9",
@@ -2783,6 +2986,12 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
+[[package]]
+name = "ttf-parser"
+version = "0.25.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d2df906b07856748fa3f6e0ad0cbaa047052d4a7dd609e231c4f72cee8c36f31"
+
[[package]]
name = "tungstenite"
version = "0.24.0"
@@ -2795,12 +3004,21 @@ dependencies = [
"http",
"httparse",
"log",
- "rand",
+ "rand 0.8.8",
"sha1",
"thiserror 1.0.69",
"utf-8",
]
+[[package]]
+name = "type1-encoding-parser"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fa10c302f5a53b7ad27fd42a3996e23d096ba39b5b8dd6d9e683a05b01bee749"
+dependencies = [
+ "pom",
+]
+
[[package]]
name = "typed-path"
version = "0.12.3"
@@ -3052,6 +3270,12 @@ dependencies = [
"rustls-pki-types",
]
+[[package]]
+name = "weezl"
+version = "0.1.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a28ac98ddc8b9274cb41bb4d9d4d5c425b6020c50c46f25559911905610b4a88"
+
[[package]]
name = "whoami"
version = "1.6.1"
diff --git a/Cargo.toml b/Cargo.toml
index 8e369aa7..1ea9e220 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -43,6 +43,7 @@ tz-rs = "0.7"
percent-encoding = "2"
zip = { version = "9", default-features = false, features = ["deflate"] }
serde_norway = "0.9"
+pdf-extract = "0.12"
[target.'cfg(unix)'.dependencies]
libc = "0.2"
diff --git a/src/server/attachments.rs b/src/server/attachments.rs
index 4c1f2993..d1e7d0ce 100644
--- a/src/server/attachments.rs
+++ b/src/server/attachments.rs
@@ -35,6 +35,10 @@ pub const MAX_ATTACHMENTS_PER_MESSAGE: usize = 10;
const INLINE_TEXT_BYTES: usize = 32 * 1024;
/// Most text `read_attachment` returns.
const READ_TEXT_BYTES: usize = 100_000;
+/// Longest a PDF's text extraction may take before `read_attachment` gives up on it.
+const PDF_EXTRACT_SECS: u64 = 20;
+/// PDFs read at once: extraction is CPU- and memory-heavy, and the server is small.
+static PDF_SLOTS: tokio::sync::Semaphore = tokio::sync::Semaphore::const_new(2);
/// Largest image `read_attachment` returns as an image.
const READ_IMAGE_BYTES: i64 = 5 * 1024 * 1024;
/// Longest text an agent can share as `content`.
@@ -480,7 +484,7 @@ pub fn tools() -> Vec<Value> {
json!({
"name": "read_attachment",
"description": "Read a file attached in this chat, by id. Text comes back as text, images as images; \
- for a PDF you get a local path to open with your own file tools.",
+ a PDF comes back as its text, page by page.",
"inputSchema": {"type": "object", "properties": {"id": {"type": "string"}}, "required": ["id"]},
}),
json!({
@@ -556,6 +560,33 @@ pub async fn tool_read(state: &AppState, scope: &SelfScope, args: &Value) -> (Va
let data = base64::engine::general_purpose::STANDARD.encode(bytes);
return (json!([{"type": "text", "text": a.name}, {"type": "image", "data": data, "mimeType": a.mime}]), false);
}
+ if a.mime == "application/pdf" {
+ let Ok(bytes) = tokio::fs::read(&path).await else {
+ return (text("Could not open the file.".into()), true);
+ };
+ return match pdf_pages(bytes).await {
+ Ok(pages) if pages.iter().any(|p| !p.trim().is_empty()) => (text(pdf_body(&a.name, &pages)), false),
+ Ok(pages) => (
+ text(format!(
+ "{} is a PDF with {} page(s) but no text layer (probably scanned images). A read-only copy is at {} — \
+ open it with your own file tools if they can read PDFs, or ask the user for a text version.",
+ a.name,
+ pages.len(),
+ path.display()
+ )),
+ false,
+ ),
+ Err(why) => (
+ text(format!(
+ "Couldn't read the text of {}: {why}. A read-only copy is at {} — open it with your own file tools \
+ if they can read PDFs, or ask the user for a text version.",
+ a.name,
+ path.display()
+ )),
+ true,
+ ),
+ };
+ }
(
text(format!(
"{} is a {} file ({}). A read-only copy is at {} — open it with your own file tools.",
@@ -568,6 +599,44 @@ pub async fn tool_read(state: &AppState, scope: &SelfScope, args: &Value) -> (Va
)
}
+/// A PDF's text, one string per page, extracted off the async runtime. A malformed PDF can make
+/// the extractor panic or spin, so a panic and a timeout both become an error message.
+async fn pdf_pages(bytes: Vec<u8>) -> Result<Vec<String>, String> {
+ let _slot = PDF_SLOTS.acquire().await.map_err(|_| "the server is shutting down".to_string())?;
+ let job = tokio::task::spawn_blocking(move || pdf_extract::extract_text_from_mem_by_pages(&bytes));
+ match tokio::time::timeout(std::time::Duration::from_secs(PDF_EXTRACT_SECS), job).await {
+ Ok(Ok(Ok(pages))) => Ok(pages),
+ Ok(Ok(Err(e))) => Err(match e.to_string() {
+ m if m.to_lowercase().contains("encrypt") || m.to_lowercase().contains("password") => {
+ "it is password-protected".to_string()
+ }
+ _ => "it isn't a PDF we can parse".to_string(),
+ }),
+ Ok(Err(_)) => Err("it isn't a PDF we can parse".to_string()),
+ Err(_) => Err(format!("reading it took longer than {PDF_EXTRACT_SECS} seconds")),
+ }
+}
+
+/// The text `read_attachment` returns for a PDF: each page under its number, cut at
+/// `READ_TEXT_BYTES` with a note on how many pages were left out.
+fn pdf_body(name: &str, pages: &[String]) -> String {
+ let mut body = format!("--- {name} ({} pages) ---", pages.len());
+ for (i, page) in pages.iter().enumerate() {
+ let chunk = format!("\n\n[page {}]\n{}", i + 1, page.trim());
+ if body.len() + chunk.len() > READ_TEXT_BYTES {
+ let mut room = READ_TEXT_BYTES.saturating_sub(body.len());
+ while room > 0 && !chunk.is_char_boundary(room) {
+ room -= 1;
+ }
+ body.push_str(&chunk[..room]);
+ body.push_str(&format!("\n[… cut: page {} onwards is left out of {} pages]", i + 1, pages.len()));
+ return body;
+ }
+ body.push_str(&chunk);
+ }
+ body
+}
+
/// `share_file`: stores the file and posts a download card in the turn's chat.
pub async fn tool_share(state: &AppState, scope: &SelfScope, args: &Value) -> (String, bool) {
let Some(origin) = &scope.origin else {
@@ -746,4 +815,36 @@ mod tests {
assert!(inside_workspace(&ws, "link.txt").is_none(), "symlinks out are refused");
}
}
+
+ const TWO_PAGES: &[u8] = include_bytes!("../../tests/fixtures/two-pages.pdf");
+
+ #[tokio::test]
+ async fn pdf_text_comes_back_page_by_page() {
+ let pages = pdf_pages(TWO_PAGES.to_vec()).await.unwrap();
+ assert_eq!(pages.len(), 2);
+ let body = pdf_body("plan.pdf", &pages);
+ assert!(body.starts_with("--- plan.pdf (2 pages) ---"), "{body}");
+ let (one, two) = (body.find("[page 1]").unwrap(), body.find("[page 2]").unwrap());
+ assert!(one < body.find("PAGE_ONE_MARKER").unwrap() && body.find("PAGE_ONE_MARKER").unwrap() < two, "{body}");
+ assert!(body[two..].contains("PAGE_TWO_MARKER Budget is 42 euros"), "{body}");
+ }
+
+ #[tokio::test]
+ async fn broken_pdfs_give_an_error_not_a_panic() {
+ for bad in [b"%PDF-1.7\nnot really".to_vec(), TWO_PAGES[..TWO_PAGES.len() / 2].to_vec(), Vec::new()] {
+ if let Ok(pages) = pdf_pages(bad).await {
+ // A lenient parse may recover nothing; it must not claim text it doesn't have
+ assert!(pages.iter().all(|p| !p.contains("PAGE_TWO_MARKER")));
+ }
+ }
+ }
+
+ #[test]
+ fn long_pdf_text_is_cut_with_a_note() {
+ let pages: Vec<String> = (0..40).map(|i| format!("{i} {}", "é".repeat(2_000))).collect();
+ let body = pdf_body("big.pdf", &pages);
+ assert!(body.len() <= READ_TEXT_BYTES + 100, "{}", body.len());
+ assert!(body.contains("[page 1]") && !body.contains("[page 40]"));
+ assert!(body.contains("onwards is left out of 40 pages]"), "{}", &body[body.len() - 80..]);
+ }
}
diff --git a/tests/attachments_test.rs b/tests/attachments_test.rs
index f9fd832e..76a81bbf 100644
--- a/tests/attachments_test.rs
+++ b/tests/attachments_test.rs
@@ -241,6 +241,44 @@ async fn sent_files_reach_the_agent_and_only_its_chat() {
assert!(reply.text.contains("STEP_ONE_SECRET_PLAN"), "{}", reply.text);
}
+#[tokio::test]
+async fn a_sent_pdf_reads_as_text_page_by_page() {
+ let env = setup().await;
+ let pdf = include_bytes!("fixtures/two-pages.pdf").to_vec();
+ let (s, up) = upload(&env, "plan.pdf", pdf.clone()).await;
+ assert_eq!(s, StatusCode::CREATED, "{up}");
+ assert_eq!(up["mime"], "application/pdf");
+ let (_, broken) = upload(&env, "broken.pdf", pdf[..pdf.len() / 2].to_vec()).await;
+ let ids = [up["id"].as_str().unwrap(), broken["id"].as_str().unwrap()];
+ send_direct(&env, &env.a, "what is in this file? REPLYTAG:p1", json!({"attachment_ids": ids})).await;
+ wait_reply(&env, &env.a, "answer p1").await;
+
+ direct_turn(&env, "tok-a", &env.a, None).await;
+ let r = self_call(&env, "tok-a", "read_attachment", json!({"id": ids[0]})).await;
+ assert_eq!(r["isError"], false, "{r}");
+ let t = text_of(&r);
+ assert!(t.contains("plan.pdf (2 pages)"), "{t}");
+ let page_two = t.find("[page 2]").expect("page markers");
+ assert!(t[page_two..].contains("Budget is 42 euros"), "{t}");
+ assert!(!t.contains("open it with your own file tools"), "text, not just a path: {t}");
+
+ // A PDF that can't be parsed says so, without crashing the server, and the next read still works
+ let r = self_call(&env, "tok-a", "read_attachment", json!({"id": ids[1]})).await;
+ let t = text_of(&r);
+ assert!(!t.contains("PAGE_TWO_MARKER"), "{t}");
+ if r["isError"] == true {
+ assert!(t.contains("Couldn't read the text of broken.pdf") && t.contains("ask the user"), "{t}");
+ }
+ let r = self_call(&env, "tok-a", "read_attachment", json!({"id": ids[0]})).await;
+ assert_eq!(r["isError"], false);
+
+ // Through a real turn of the fake CLI
+ let marker = call_tool_marker("read_attachment", json!({"id": ids[0]}));
+ send_direct(&env, &env.a, &format!("{marker} REPLYTAG:p2"), json!({})).await;
+ let reply = wait_reply(&env, &env.a, "answer p2").await;
+ assert!(reply.text.contains("PAGE_ONE_MARKER"), "{}", reply.text);
+}
+
#[tokio::test]
async fn agents_share_files_as_download_cards_from_inside_their_workspace_only() {
let env = setup().await;
diff --git a/tests/fixtures/two-pages.pdf b/tests/fixtures/two-pages.pdf
new file mode 100644
index 00000000..16f58b75
--- /dev/null
+++ b/tests/fixtures/two-pages.pdf
@@ -0,0 +1,43 @@
+%PDF-1.4
+1 0 obj
+<< /Type /Catalog /Pages 2 0 R >>
+endobj
+2 0 obj
+<< /Type /Pages /Kids [5 0 R 7 0 R] /Count 2 >>
+endobj
+3 0 obj
+<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>
+endobj
+4 0 obj
+<< /Length 61 >>
+stream
+BT /F1 18 Tf 72 720 Td (PAGE_ONE_MARKER Quarterly plan) Tj ET
+endstream
+endobj
+5 0 obj
+<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Resources << /Font << /F1 3 0 R >> >> /Contents 4 0 R >>
+endobj
+6 0 obj
+<< /Length 65 >>
+stream
+BT /F1 18 Tf 72 720 Td (PAGE_TWO_MARKER Budget is 42 euros) Tj ET
+endstream
+endobj
+7 0 obj
+<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Resources << /Font << /F1 3 0 R >> >> /Contents 6 0 R >>
+endobj
+xref
+0 8
+0000000000 65535 f
+0000000009 00000 n
+0000000058 00000 n
+0000000121 00000 n
+0000000191 00000 n
+0000000302 00000 n
+0000000428 00000 n
+0000000543 00000 n
+trailer
+<< /Size 8 /Root 1 0 R >>
+startxref
+669
+%%EOF