feat(wenxin): unwrap reference redirects and capture web page sources
Decode Wenxin reference redirect targets so citation URLs land on the real source host, and broaden the reference/search field patterns to pick up webPages-style payloads. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,8 +3,10 @@ import { describe, expect, it } from "vitest";
|
||||
import { __wenxinTestUtils } from "./wenxin";
|
||||
|
||||
const {
|
||||
buildSourceItem,
|
||||
htmlTableToMarkdown,
|
||||
isObservationComplete,
|
||||
normalizeUrl,
|
||||
parseWenxinHistoryResponse,
|
||||
parseWenxinSSEBody,
|
||||
} = __wenxinTestUtils;
|
||||
@@ -163,6 +165,62 @@ describe("wenxin adapter helpers", () => {
|
||||
expect(history.citations[0]?.url).toBe("https://fallback.example.com/article");
|
||||
});
|
||||
|
||||
it("unwraps Wenxin reference redirect urls", () => {
|
||||
expect(normalizeUrl("https://yiyan.baidu.com/eb/link?target=https%3A%2F%2Fwww.example.com%2Farticle%23ref")).toBe(
|
||||
"https://www.example.com/article",
|
||||
);
|
||||
|
||||
expect(buildSourceItem({
|
||||
pageUrl: "https://yiyan.baidu.com/eb/link?url=https%3A%2F%2Fsource.example.com%2Fnews%3Fid%3D1",
|
||||
title: "引用来源标题",
|
||||
source: "来源站点",
|
||||
})).toMatchObject({
|
||||
url: "https://source.example.com/news?id=1",
|
||||
title: "引用来源标题",
|
||||
site_name: "来源站点",
|
||||
host: "source.example.com",
|
||||
});
|
||||
});
|
||||
|
||||
it("extracts web page references from Wenxin reference list fields", () => {
|
||||
const history = parseWenxinHistoryResponse({
|
||||
code: 0,
|
||||
msg: "success",
|
||||
data: {
|
||||
state: 1,
|
||||
chats: [
|
||||
{
|
||||
id: "bot-1",
|
||||
role: "robot",
|
||||
stop: 1,
|
||||
modelSign: "EB45T",
|
||||
message: [
|
||||
{
|
||||
contentType: "text",
|
||||
content: "这是答案",
|
||||
},
|
||||
],
|
||||
webPages: [
|
||||
{
|
||||
targetUrl: "https://yiyan.baidu.com/eb/link?target=https%3A%2F%2Fwww.reference-source.com%2Fa%23section",
|
||||
title: "参考网页 A",
|
||||
siteName: "reference-source.com",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
}, "session-3");
|
||||
|
||||
expect(history.citations).toHaveLength(1);
|
||||
expect(history.searchResults).toHaveLength(1);
|
||||
expect(history.citations[0]).toMatchObject({
|
||||
url: "https://www.reference-source.com/a",
|
||||
title: "参考网页 A",
|
||||
site_name: "reference-source.com",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not treat error-only observations as complete", () => {
|
||||
expect(isObservationComplete({
|
||||
sessionId: "session-1",
|
||||
|
||||
Reference in New Issue
Block a user