@lobehub/chat 0.27.1 → 0.27.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/package.json +1 -1
- package/src/plugins/webCrawler/runner.ts +22 -29
- package/src/plugins/webCrawler/type.ts +0 -27
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.27.2](https://github.com/lobehub/lobe-chat/compare/v0.27.1...v0.27.2)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2023-07-29**</sup>
|
|
8
|
+
|
|
9
|
+
#### ♻ Code Refactoring
|
|
10
|
+
|
|
11
|
+
- **misc**: 重构并优化文档抓取插件能力.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### Code refactoring
|
|
19
|
+
|
|
20
|
+
- **misc**: 重构并优化文档抓取插件能力 ([ff56348](https://github.com/lobehub/lobe-chat/commit/ff56348))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
5
30
|
### [Version 0.27.1](https://github.com/lobehub/lobe-chat/compare/v0.27.0...v0.27.1)
|
|
6
31
|
|
|
7
32
|
<sup>Released on **2023-07-29**</sup>
|
package/package.json
CHANGED
|
@@ -1,47 +1,40 @@
|
|
|
1
1
|
import { PluginRunner } from '@/plugins/type';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { Result } from './type';
|
|
4
4
|
|
|
5
|
-
const BASE_URL =
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const BASE_URL = process.env.BROWSERLESS_URL ?? 'https://chrome.browserless.io';
|
|
6
|
+
const BROWSERLESS_TOKEN = process.env.BROWSERLESS_TOKEN;
|
|
7
|
+
|
|
8
|
+
// service from: https://github.com/lobehub/html-parser/tree/master
|
|
9
|
+
const HTML_PARSER_URL = process.env.HTML_PARSER_URL;
|
|
8
10
|
|
|
9
11
|
const runner: PluginRunner<{ url: string }, Result> = async ({ url }) => {
|
|
10
|
-
// Prepare Actor input
|
|
11
12
|
const input = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
debugMode: false,
|
|
15
|
-
dynamicContentWaitSecs: 3,
|
|
16
|
-
proxyConfiguration: {
|
|
17
|
-
useApifyProxy: true,
|
|
18
|
-
},
|
|
19
|
-
removeCookieWarnings: true,
|
|
20
|
-
removeElementsCssSelector:
|
|
21
|
-
'nav, footer, script, style, noscript, svg,\n[role="alert"],\n[role="banner"],\n[role="dialog"],\n[role="alertdialog"],\n[role="region"][aria-label*="skip" i],\n[aria-modal="true"]',
|
|
22
|
-
saveFiles: false,
|
|
23
|
-
saveHtml: false,
|
|
24
|
-
saveMarkdown: true,
|
|
25
|
-
saveScreenshots: false,
|
|
26
|
-
startUrls: [{ url }],
|
|
13
|
+
gotoOptions: { waitUntil: 'networkidle2' },
|
|
14
|
+
url,
|
|
27
15
|
};
|
|
28
16
|
|
|
29
17
|
try {
|
|
30
|
-
const
|
|
18
|
+
const res = await fetch(`${BASE_URL}/content?token=${BROWSERLESS_TOKEN}`, {
|
|
31
19
|
body: JSON.stringify(input),
|
|
32
20
|
headers: {
|
|
33
21
|
'Content-Type': 'application/json',
|
|
34
22
|
},
|
|
35
23
|
method: 'POST',
|
|
36
24
|
});
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
25
|
+
const html = await res.text();
|
|
26
|
+
|
|
27
|
+
const parserBody = { html, url };
|
|
28
|
+
|
|
29
|
+
const parseRes = await fetch(`${HTML_PARSER_URL}`, {
|
|
30
|
+
body: JSON.stringify(parserBody),
|
|
31
|
+
headers: {
|
|
32
|
+
'Content-Type': 'application/json',
|
|
33
|
+
},
|
|
34
|
+
method: 'POST',
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return await parseRes.json();
|
|
45
38
|
} catch (error) {
|
|
46
39
|
console.error(error);
|
|
47
40
|
return { content: '抓取失败', errorMessage: (error as any).message };
|
|
@@ -1,32 +1,5 @@
|
|
|
1
|
-
export type DataResults = DataItem[];
|
|
2
|
-
|
|
3
1
|
export type Result = {
|
|
4
2
|
content?: string;
|
|
5
3
|
title?: string;
|
|
6
4
|
url?: string;
|
|
7
5
|
};
|
|
8
|
-
export interface DataItem {
|
|
9
|
-
crawl: Crawl;
|
|
10
|
-
markdown: string;
|
|
11
|
-
metadata: Metadata;
|
|
12
|
-
screenshotUrl: any;
|
|
13
|
-
text: string;
|
|
14
|
-
url: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface Crawl {
|
|
18
|
-
depth: number;
|
|
19
|
-
httpStatusCode: number;
|
|
20
|
-
loadedTime: string;
|
|
21
|
-
loadedUrl: string;
|
|
22
|
-
referrerUrl: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface Metadata {
|
|
26
|
-
author: any;
|
|
27
|
-
canonicalUrl: string;
|
|
28
|
-
description: string;
|
|
29
|
-
keywords: string;
|
|
30
|
-
languageCode: string;
|
|
31
|
-
title: string;
|
|
32
|
-
}
|