Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(tools): cluster mode restore and token expiry

haowenzhong1d1e3d316afc3
diff --git a/jiuwenswarm/agents/harness/common/tools/send_file_to_user.py b/jiuwenswarm/agents/harness/common/tools/send_file_to_user.py
index cab6369026..3f9c3aebe0 100644
--- a/jiuwenswarm/agents/harness/common/tools/send_file_to_user.py
+++ b/jiuwenswarm/agents/harness/common/tools/send_file_to_user.py
@@ -148,7 +148,6 @@ class SendFileToolkit:
"mime_type": download_info["mime_type"],
"download_url": download_info["download_url"],
"download_token": download_info["download_token"],
- "expires_at": download_info.get("expires_at"),
})
except Exception as download_err:
logger.warning(
diff --git a/jiuwenswarm/agents/harness/common/tools/web_file_download.py b/jiuwenswarm/agents/harness/common/tools/web_file_download.py
index 3c42c6b43f..47a3c3a51c 100644
--- a/jiuwenswarm/agents/harness/common/tools/web_file_download.py
+++ b/jiuwenswarm/agents/harness/common/tools/web_file_download.py
@@ -125,9 +125,6 @@ class WebFileDownloadManager:
payload = json.loads(payload_json)
if not isinstance(payload, dict):
return None
- if payload.get("exp", 0) < time.time():
- logger.info("[WebFileDownload] 令牌已过期: path=%s", payload.get("path"))
- return None
return payload
except Exception:
logger.debug("[WebFileDownload] 令牌解析异常", exc_info=True)
@@ -174,13 +171,10 @@ def build_file_download_info(
if guessed_type:
mime_type = guessed_type
- expires_at = int(time.time()) + expires_in
-
return {
"name": file_name,
"size": file_size,
"mime_type": mime_type,
"download_url": download_url,
"download_token": token,
- "expires_at": expires_at,
}
diff --git a/jiuwenswarm/channels/web/app_web.py b/jiuwenswarm/channels/web/app_web.py
index 49d18d8d7b..dbf804dd4f 100644
--- a/jiuwenswarm/channels/web/app_web.py
+++ b/jiuwenswarm/channels/web/app_web.py
@@ -842,6 +842,10 @@ class _SpaStaticHandler(SimpleHTTPRequestHandler):
self.send_error(405, "method not allowed")
def do_HEAD(self) -> None: # noqa: N802
+ parsed = urlparse(self.path)
+ if self._is_file_api_route():
+ self._handle_file_api_get(parsed)
+ return
if self._dispatch_proxy():
return
super().do_HEAD()
diff --git a/jiuwenswarm/channels/web/frontend/src/components/ChatPanel/MessageItem.tsx b/jiuwenswarm/channels/web/frontend/src/components/ChatPanel/MessageItem.tsx
index 9dfc40cfa4..7737ef76e7 100644
--- a/jiuwenswarm/channels/web/frontend/src/components/ChatPanel/MessageItem.tsx
+++ b/jiuwenswarm/channels/web/frontend/src/components/ChatPanel/MessageItem.tsx
@@ -655,14 +655,28 @@ function FileDownloadList({
className?: string;
}) {
const { t } = useTranslation();
+ const [expiredSet, setExpiredSet] = useState<Set<number>>(new Set());
- const isExpired = (file: FileDownloadItem): boolean => {
- if (!file.expires_at) return false;
- return Date.now() / 1000 > file.expires_at;
- };
+ useEffect(() => {
+ let cancelled = false;
+ files.forEach((file, index) => {
+ fetch(file.download_url, { method: 'HEAD' })
+ .then((res) => {
+ if (!cancelled && !res.ok) {
+ setExpiredSet((prev) => new Set(prev).add(index));
+ }
+ })
+ .catch(() => {
+ if (!cancelled) {
+ setExpiredSet((prev) => new Set(prev).add(index));
+ }
+ });
+ });
+ return () => { cancelled = true; };
+ }, [files]);
- const handleDownload = async (file: FileDownloadItem) => {
- if (isExpired(file)) return;
+ const handleDownload = async (file: FileDownloadItem, index: number) => {
+ if (expiredSet.has(index)) return;
// 检查是否在 PyWebView 环境中(exe 模式)
const pywebviewApi = (window as Window & { pywebview?: { api?: { download_file?: (url: string, filename: string) => Promise<boolean> | boolean } } }).pywebview?.api;
@@ -688,7 +702,7 @@ function FileDownloadList({
{files.map((file, index) => {
const typeConfig = getFileTypeConfig(file.mime_type, file.name);
const ext = getFileExtension(file.name);
- const expired = isExpired(file);
+ const expired = expiredSet.has(index);
return (
<div
key={`${file.name}-${index}`}
@@ -698,7 +712,7 @@ function FileDownloadList({
? 'border-border/50 bg-card/50 cursor-not-allowed opacity-60'
: 'border-border bg-card hover:shadow-md hover:border-border-hover cursor-pointer group'
)}
- onClick={() => handleDownload(file)}
+ onClick={() => handleDownload(file, index)}
>
<div className={`flex-shrink-0 w-10 h-10 rounded-lg ${typeConfig.bg} flex items-center justify-center`}>
{typeof typeConfig.icon === 'string' ? (
diff --git a/jiuwenswarm/channels/web/frontend/src/features/historyRestore.ts b/jiuwenswarm/channels/web/frontend/src/features/historyRestore.ts
index 2c34cec014..d99e6d36c2 100644
--- a/jiuwenswarm/channels/web/frontend/src/features/historyRestore.ts
+++ b/jiuwenswarm/channels/web/frontend/src/features/historyRestore.ts
@@ -566,7 +566,10 @@ export function beginHistoryRestore(options: BeginHistoryRestoreOptions): Histor
let pendingFileItems: FileDownloadItem[] | null = null;
for (const e of entries) {
if (e.kind === 'message') {
- if (e.message.role === 'assistant' && pendingFileItems) {
+ if (pendingFileItems && (
+ e.message.role === 'assistant' ||
+ (e.message.role === 'system' && e.message.id?.startsWith('team-leader-'))
+ )) {
e.message = { ...e.message, fileItems: pendingFileItems };
pendingFileItems = null;
}
@@ -748,7 +751,10 @@ export function fetchHistoryPage(options: FetchHistoryPageOptions): HistoryResto
let pendingFileItems: FileDownloadItem[] | null = null;
for (const e of entries) {
if (e.kind === 'message') {
- if (e.message.role === 'assistant' && pendingFileItems) {
+ if (pendingFileItems && (
+ e.message.role === 'assistant' ||
+ (e.message.role === 'system' && e.message.id?.startsWith('team-leader-'))
+ )) {
e.message = { ...e.message, fileItems: pendingFileItems };
pendingFileItems = null;
}
diff --git a/jiuwenswarm/channels/web/frontend/src/types/message.ts b/jiuwenswarm/channels/web/frontend/src/types/message.ts
index 0cb6eca056..16caa06168 100644
--- a/jiuwenswarm/channels/web/frontend/src/types/message.ts
+++ b/jiuwenswarm/channels/web/frontend/src/types/message.ts
@@ -27,7 +27,6 @@ export interface FileDownloadItem {
mime_type: string;
download_url: string;
download_token: string;
- expires_at?: number;
}
export interface ContextCompressionRuntime {