fix: add Jina X-Timeout header + ensure webRead always throws Error instances
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
51bf279ac6
commit
bd7f227b11
@@ -143,6 +143,7 @@ export async function webSearch(query: string): Promise<{
|
||||
Authorization: `Bearer ${config.jina.apiKey}`,
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"X-Timeout": "15",
|
||||
};
|
||||
|
||||
// Step 1: Search
|
||||
@@ -231,16 +232,24 @@ export async function googleSearch(query: string): Promise<{
|
||||
|
||||
// --- Jina Web Read (single URL full-text) ---
|
||||
export async function webRead(url: string): Promise<{ content: string; title: string }> {
|
||||
const resp = await fetch(`https://r.jina.ai/${url}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${config.jina.apiKey}`,
|
||||
Accept: "application/json",
|
||||
},
|
||||
signal: AbortSignal.timeout(getToolConfig("web_read").timeoutMs),
|
||||
});
|
||||
if (!resp.ok) throw new Error(`Jina read failed: ${resp.status}`);
|
||||
const data = await resp.json();
|
||||
return { content: data.data?.content ?? "", title: data.data?.title ?? "" };
|
||||
try {
|
||||
const resp = await fetch(`https://r.jina.ai/${url}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${config.jina.apiKey}`,
|
||||
Accept: "application/json",
|
||||
"X-Timeout": "15",
|
||||
"X-Return-Format": "markdown",
|
||||
},
|
||||
signal: AbortSignal.timeout(getToolConfig("web_read").timeoutMs),
|
||||
});
|
||||
if (!resp.ok) throw new Error(`Jina read failed: ${resp.status}`);
|
||||
const data = await resp.json();
|
||||
return { content: data.data?.content ?? "", title: data.data?.title ?? "" };
|
||||
} catch (e) {
|
||||
// 确保抛出的是 Error 实例,不是其他类型
|
||||
if (e instanceof Error) throw e;
|
||||
throw new Error(String(e));
|
||||
}
|
||||
}
|
||||
|
||||
// --- Jina Rerank ---
|
||||
|
||||
Reference in New Issue
Block a user