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
6 changes: 6 additions & 0 deletions .changeset/voice-media-pending.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@agent-wechat/agent-server": patch
"@agent-wechat/wechat": patch
---

Return "pending" instead of "unsupported" when voice data is not yet available in the database, so the extension retries instead of giving up.
30 changes: 14 additions & 16 deletions packages/agent-server-rust/src/tools/wechat_media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ fn unsupported() -> MediaResult {
}
}

fn pending() -> MediaResult {
MediaResult {
media_type: "pending".into(),
data: None,
url: None,
format: String::new(),
filename: String::new(),
}
}

fn account_base_paths(account_dir: &str) -> [String; 2] {
[
format!("/home/wechat/xwechat_files/{account_dir}"),
Expand Down Expand Up @@ -582,15 +592,9 @@ fn get_video_data(
return thumb;
}

// Video exists but no file found on disk
// Video exists but no file found on disk yet
tracing::warn!("[media:video] no video file found for local_id={}", local_id);
MediaResult {
media_type: "video".into(),
data: None,
url: None,
format: "mp4".into(),
filename: format!("msg_{local_id}.mp4"),
}
pending()
}

/// Extract the 32-char hex file hash from a MessageResourceInfo packed_info blob.
Expand Down Expand Up @@ -855,7 +859,7 @@ fn get_voice_data(
};
}

unsupported()
pending()
}

// ── File attachment ──────────────────────────────────────────────────────────
Expand Down Expand Up @@ -895,13 +899,7 @@ fn get_file_attachment(
}

// File not yet downloaded by WeChat
MediaResult {
media_type: "file".into(),
data: None,
url: None,
format: ext,
filename,
}
pending()
}

// ── Public entry point ───────────────────────────────────────────────────────
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,10 @@ async function cmdMedia(client: WeChatClient, chatId: string, localId: number, o
console.error("No media found for this message (unsupported type or not found).");
process.exit(1);
}
if (result.type === "pending") {
console.error("Media not yet available. WeChat may still be downloading it — try again shortly.");
process.exit(1);
}

const outFile = outputPath ?? result.filename;

Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export interface GetMediaParams {
// Note: MediaResult kept handwritten (Rust uses plain string for type,
// TS has richer string literal union)
export interface MediaResult {
type: "image" | "emoji" | "voice" | "file" | "video" | "unsupported";
type: "image" | "emoji" | "voice" | "file" | "video" | "pending" | "unsupported";
data?: string; // base64 for image/voice/file
url?: string; // CDN URL for emoji
format: string;
Expand Down
Loading