felo-ai 0.2.6 → 0.2.9

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.
Files changed (39) hide show
  1. package/.github/workflows/publish-npm.yml +39 -0
  2. package/CHANGELOG.md +30 -0
  3. package/CONTRIBUTING.md +346 -346
  4. package/README.en.md +129 -129
  5. package/README.md +435 -408
  6. package/docs/EXAMPLES.md +632 -632
  7. package/docs/FAQ.md +479 -479
  8. package/felo-search/LICENSE +21 -21
  9. package/felo-search/README.md +440 -440
  10. package/felo-search/SKILL.md +291 -291
  11. package/felo-slides/LICENSE +21 -21
  12. package/felo-slides/README.md +87 -87
  13. package/felo-slides/SKILL.md +166 -166
  14. package/felo-slides/scripts/run_ppt_task.mjs +251 -251
  15. package/felo-superAgent/LICENSE +21 -0
  16. package/felo-superAgent/README.md +125 -0
  17. package/felo-superAgent/SKILL.md +165 -0
  18. package/felo-web-fetch/README.md +127 -0
  19. package/felo-web-fetch/SKILL.md +204 -0
  20. package/felo-web-fetch/scripts/run_web_fetch.mjs +316 -0
  21. package/felo-x-search/SKILL.md +204 -0
  22. package/felo-x-search/scripts/run_x_search.mjs +385 -0
  23. package/felo-youtube-subtitling/README.md +59 -59
  24. package/felo-youtube-subtitling/SKILL.md +161 -161
  25. package/felo-youtube-subtitling/scripts/run_youtube_subtitling.mjs +239 -239
  26. package/package.json +37 -35
  27. package/src/cli.js +370 -252
  28. package/src/config.js +66 -66
  29. package/src/search.js +142 -142
  30. package/src/slides.js +332 -332
  31. package/src/superAgent.js +609 -0
  32. package/src/{webExtract.js → webFetch.js} +148 -148
  33. package/src/xSearch.js +366 -0
  34. package/src/youtubeSubtitling.js +179 -179
  35. package/tests/config.test.js +78 -78
  36. package/tests/search.test.js +100 -100
  37. package/felo-web-extract/README.md +0 -78
  38. package/felo-web-extract/SKILL.md +0 -200
  39. package/felo-web-extract/scripts/run_web_extract.mjs +0 -232
@@ -1,100 +1,100 @@
1
- import { describe, it, before, after } from 'node:test';
2
- import assert from 'node:assert';
3
- import path from 'path';
4
- import os from 'os';
5
- import fs from 'fs/promises';
6
-
7
- const tmpDir = path.join(os.tmpdir(), `felo-test-search-${Date.now()}`);
8
- const testConfigFile = path.join(tmpDir, 'config.json');
9
- process.env.FELO_CONFIG_FILE = testConfigFile;
10
-
11
- import { getApiKey, fetchWithTimeoutAndRetry } from '../src/search.js';
12
- import * as config from '../src/config.js';
13
-
14
- after(async () => {
15
- delete process.env.FELO_API_KEY;
16
- delete process.env.FELO_CONFIG_FILE;
17
- await fs.rm(tmpDir, { recursive: true, force: true }).catch(() => {});
18
- });
19
-
20
- before(async () => {
21
- await fs.mkdir(path.dirname(testConfigFile), { recursive: true });
22
- });
23
-
24
- describe('getApiKey', () => {
25
- it('returns env FELO_API_KEY when set', async () => {
26
- process.env.FELO_API_KEY = 'env-key';
27
- const key = await getApiKey();
28
- assert.strictEqual(key, 'env-key');
29
- });
30
-
31
- it('returns key from config when env not set', async () => {
32
- delete process.env.FELO_API_KEY;
33
- await config.setConfig('FELO_API_KEY', 'config-key');
34
- const key = await getApiKey();
35
- assert.strictEqual(key, 'config-key');
36
- });
37
-
38
- it('returns empty string when neither set', async () => {
39
- delete process.env.FELO_API_KEY;
40
- await config.unsetConfig('FELO_API_KEY');
41
- const key = await getApiKey();
42
- assert.strictEqual(key, '');
43
- });
44
-
45
- it('env wins over config', async () => {
46
- process.env.FELO_API_KEY = 'env-wins';
47
- await config.setConfig('FELO_API_KEY', 'config-key');
48
- const key = await getApiKey();
49
- assert.strictEqual(key, 'env-wins');
50
- });
51
- });
52
-
53
- describe('fetchWithTimeoutAndRetry', () => {
54
- it('returns response on 200', async () => {
55
- const res = { ok: true, status: 200 };
56
- let callCount = 0;
57
- const origFetch = globalThis.fetch;
58
- globalThis.fetch = () => { callCount++; return Promise.resolve(res); };
59
- try {
60
- const out = await fetchWithTimeoutAndRetry('https://example.com', {}, 10_000);
61
- assert.strictEqual(out, res);
62
- assert.strictEqual(callCount, 1);
63
- } finally {
64
- globalThis.fetch = origFetch;
65
- }
66
- });
67
-
68
- it('retries on 500 then succeeds', async () => {
69
- const res200 = { ok: true, status: 200 };
70
- const res500 = { ok: false, status: 502 };
71
- let callCount = 0;
72
- const origFetch = globalThis.fetch;
73
- globalThis.fetch = () => {
74
- callCount++;
75
- return Promise.resolve(callCount === 1 ? res500 : res200);
76
- };
77
- try {
78
- const out = await fetchWithTimeoutAndRetry('https://example.com', {}, 10_000);
79
- assert.strictEqual(out, res200);
80
- assert.strictEqual(callCount, 2);
81
- } finally {
82
- globalThis.fetch = origFetch;
83
- }
84
- });
85
-
86
- it('throws on timeout (AbortError)', async () => {
87
- const origFetch = globalThis.fetch;
88
- const abortErr = new Error('The operation was aborted');
89
- abortErr.name = 'AbortError';
90
- globalThis.fetch = () => Promise.reject(abortErr);
91
- try {
92
- await assert.rejects(
93
- async () => fetchWithTimeoutAndRetry('https://example.com', {}, 5000),
94
- (err) => err.message && err.message.includes('timed out')
95
- );
96
- } finally {
97
- globalThis.fetch = origFetch;
98
- }
99
- });
100
- });
1
+ import { describe, it, before, after } from 'node:test';
2
+ import assert from 'node:assert';
3
+ import path from 'path';
4
+ import os from 'os';
5
+ import fs from 'fs/promises';
6
+
7
+ const tmpDir = path.join(os.tmpdir(), `felo-test-search-${Date.now()}`);
8
+ const testConfigFile = path.join(tmpDir, 'config.json');
9
+ process.env.FELO_CONFIG_FILE = testConfigFile;
10
+
11
+ import { getApiKey, fetchWithTimeoutAndRetry } from '../src/search.js';
12
+ import * as config from '../src/config.js';
13
+
14
+ after(async () => {
15
+ delete process.env.FELO_API_KEY;
16
+ delete process.env.FELO_CONFIG_FILE;
17
+ await fs.rm(tmpDir, { recursive: true, force: true }).catch(() => {});
18
+ });
19
+
20
+ before(async () => {
21
+ await fs.mkdir(path.dirname(testConfigFile), { recursive: true });
22
+ });
23
+
24
+ describe('getApiKey', () => {
25
+ it('returns env FELO_API_KEY when set', async () => {
26
+ process.env.FELO_API_KEY = 'env-key';
27
+ const key = await getApiKey();
28
+ assert.strictEqual(key, 'env-key');
29
+ });
30
+
31
+ it('returns key from config when env not set', async () => {
32
+ delete process.env.FELO_API_KEY;
33
+ await config.setConfig('FELO_API_KEY', 'config-key');
34
+ const key = await getApiKey();
35
+ assert.strictEqual(key, 'config-key');
36
+ });
37
+
38
+ it('returns empty string when neither set', async () => {
39
+ delete process.env.FELO_API_KEY;
40
+ await config.unsetConfig('FELO_API_KEY');
41
+ const key = await getApiKey();
42
+ assert.strictEqual(key, '');
43
+ });
44
+
45
+ it('env wins over config', async () => {
46
+ process.env.FELO_API_KEY = 'env-wins';
47
+ await config.setConfig('FELO_API_KEY', 'config-key');
48
+ const key = await getApiKey();
49
+ assert.strictEqual(key, 'env-wins');
50
+ });
51
+ });
52
+
53
+ describe('fetchWithTimeoutAndRetry', () => {
54
+ it('returns response on 200', async () => {
55
+ const res = { ok: true, status: 200 };
56
+ let callCount = 0;
57
+ const origFetch = globalThis.fetch;
58
+ globalThis.fetch = () => { callCount++; return Promise.resolve(res); };
59
+ try {
60
+ const out = await fetchWithTimeoutAndRetry('https://example.com', {}, 10_000);
61
+ assert.strictEqual(out, res);
62
+ assert.strictEqual(callCount, 1);
63
+ } finally {
64
+ globalThis.fetch = origFetch;
65
+ }
66
+ });
67
+
68
+ it('retries on 500 then succeeds', async () => {
69
+ const res200 = { ok: true, status: 200 };
70
+ const res500 = { ok: false, status: 502 };
71
+ let callCount = 0;
72
+ const origFetch = globalThis.fetch;
73
+ globalThis.fetch = () => {
74
+ callCount++;
75
+ return Promise.resolve(callCount === 1 ? res500 : res200);
76
+ };
77
+ try {
78
+ const out = await fetchWithTimeoutAndRetry('https://example.com', {}, 10_000);
79
+ assert.strictEqual(out, res200);
80
+ assert.strictEqual(callCount, 2);
81
+ } finally {
82
+ globalThis.fetch = origFetch;
83
+ }
84
+ });
85
+
86
+ it('throws on timeout (AbortError)', async () => {
87
+ const origFetch = globalThis.fetch;
88
+ const abortErr = new Error('The operation was aborted');
89
+ abortErr.name = 'AbortError';
90
+ globalThis.fetch = () => Promise.reject(abortErr);
91
+ try {
92
+ await assert.rejects(
93
+ async () => fetchWithTimeoutAndRetry('https://example.com', {}, 5000),
94
+ (err) => err.message && err.message.includes('timed out')
95
+ );
96
+ } finally {
97
+ globalThis.fetch = origFetch;
98
+ }
99
+ });
100
+ });
@@ -1,78 +0,0 @@
1
- # Felo Web Extract Skill
2
-
3
- Extract webpage content from a URL using the [Felo Web Extract API](https://openapi.felo.ai/docs/api-reference/v2/web-extract.html).
4
-
5
- ## Features
6
-
7
- - Extract content from any URL as **html**, **text**, or **markdown** (`--format`)
8
- - **Target one element** with a CSS selector (`--target-selector`, e.g. `article.main`, `#content`)
9
- - Optional **readability** mode for main article content only
10
- - Crawl modes: `fast` (default) or `fine`
11
- - Same `FELO_API_KEY` as other Felo skills
12
-
13
- ## Quick Start
14
-
15
- ### 1) Configure API key
16
-
17
- At [felo.ai](https://felo.ai) -> Settings -> API Keys, create a key, then:
18
-
19
- ```bash
20
- # Linux/macOS
21
- export FELO_API_KEY="your-api-key-here"
22
- ```
23
-
24
- ```powershell
25
- # Windows PowerShell
26
- $env:FELO_API_KEY="your-api-key-here"
27
- ```
28
-
29
- ### 2) Run extraction
30
-
31
- ```bash
32
- # Extract as Markdown (default)
33
- node felo-web-extract/scripts/run_web_extract.mjs --url "https://example.com/article"
34
-
35
- # With readability for clean article text
36
- node felo-web-extract/scripts/run_web_extract.mjs --url "https://example.com" --readability --format markdown
37
-
38
- # Full JSON response
39
- node felo-web-extract/scripts/run_web_extract.mjs --url "https://example.com" --json
40
-
41
- # Only a specific element (CSS selector) and output format
42
- node felo-web-extract/scripts/run_web_extract.mjs --url "https://example.com" --target-selector "article.main" --format markdown
43
- ```
44
-
45
- ## Using the packaged CLI (`felo web-extract`)
46
-
47
- After `npm install -g felo-ai`, you can run:
48
-
49
- ```bash
50
- felo web-extract --url "https://example.com"
51
- ```
52
-
53
- **All parameters (how to pass)**
54
-
55
- | Parameter | Option | Example |
56
- |-----------|--------|---------|
57
- | URL (required) | `-u`, `--url` | `--url "https://example.com"` |
58
- | Output format | `-f`, `--format` | `--format text`, `-f markdown`, `-f html` |
59
- | Target element (CSS selector) | `--target-selector` | `--target-selector "article.main"` |
60
- | Wait for selector | `--wait-for-selector` | `--wait-for-selector ".content"` |
61
- | Readability (main content only) | `--readability` | `--readability` |
62
- | Crawl mode | `--crawl-mode` | `--crawl-mode fine` (default: `fast`) |
63
- | Timeout (seconds) | `-t`, `--timeout` | `--timeout 120`, `-t 90` |
64
- | Full JSON response | `-j`, `--json` | `-j` or `--json` |
65
-
66
- **Examples with multiple options**
67
-
68
- ```bash
69
- felo web-extract -u "https://example.com" -f text --readability
70
- felo web-extract --url "https://example.com" --target-selector "#content" --format markdown --timeout 90
71
- felo web-extract --url "https://example.com" --wait-for-selector "main" --readability -j
72
- ```
73
-
74
- ## When to use (Agent)
75
-
76
- Trigger keywords: extract webpage, scrape URL, fetch page content, url to markdown, `/felo-web-extract`.
77
-
78
- See [SKILL.md](SKILL.md) for full agent instructions and API parameters.
@@ -1,200 +0,0 @@
1
- ---
2
- name: felo-web-extract
3
- description: "Extract web page content from a URL using Felo Web Extract API. Use when users ask to scrape/capture/fetch webpage content, extract article text from URL, convert page to markdown/text, or when explicit commands like /felo-web-extract are used. Supports html, text, markdown output and readability mode."
4
- ---
5
-
6
- # Felo Web Extract Skill
7
-
8
- ## When to Use
9
-
10
- Trigger this skill when the user wants to:
11
-
12
- - Extract or scrape content from a webpage URL
13
- - Get article/main text from a link
14
- - Convert a webpage to Markdown or plain text
15
- - Capture readable content from a URL for summarization or processing
16
-
17
- Trigger keywords (examples):
18
-
19
- - extract webpage, scrape URL, fetch page content, web extract, url to markdown
20
- - Explicit: `/felo-web-extract`, "use felo web extract"
21
- - Same intent in other languages (e.g. 网页抓取, 提取网页内容) also triggers this skill
22
-
23
- Do NOT use for:
24
-
25
- - Real-time search or Q&A (use `felo-search`)
26
- - Generating slides (use `felo-slides`)
27
- - Local file content (read files directly)
28
-
29
- ## Setup
30
-
31
- ### 1. Get API key
32
-
33
- 1. Visit [felo.ai](https://felo.ai)
34
- 2. Open Settings -> API Keys
35
- 3. Create and copy your API key
36
-
37
- ### 2. Configure environment variable
38
-
39
- Linux/macOS:
40
-
41
- ```bash
42
- export FELO_API_KEY="your-api-key-here"
43
- ```
44
-
45
- Windows PowerShell:
46
-
47
- ```powershell
48
- $env:FELO_API_KEY="your-api-key-here"
49
- ```
50
-
51
- ## How to Execute
52
-
53
- ### Option A: Use the bundled script or packaged CLI
54
-
55
- **Script** (from repo):
56
-
57
- ```bash
58
- node felo-web-extract/scripts/run_web_extract.mjs --url "https://example.com/article" [options]
59
- ```
60
-
61
- **Packaged CLI** (after `npm install -g felo-ai`): same options, with short forms allowed:
62
-
63
- ```bash
64
- felo web-extract -u "https://example.com" [options]
65
- # Short forms: -u (url), -f (format), -t (timeout, seconds), -j (json)
66
- ```
67
-
68
- Options:
69
-
70
- | Option | Default | Description |
71
- |--------|---------|-------------|
72
- | `--url` | (required) | Webpage URL to extract |
73
- | `--format` | markdown | Output format: `html`, `text`, `markdown` |
74
- | `--target-selector` | - | CSS selector: extract only this element (e.g. `article.main`, `#content`) |
75
- | `--wait-for-selector` | - | Wait for this selector before extracting (e.g. dynamic content) |
76
- | `--readability` | false | Enable readability processing (main content only) |
77
- | `--crawl-mode` | fast | `fast` or `fine` |
78
- | `--timeout` | 60000 (script) / 60 (CLI) | Request timeout: script uses **milliseconds**, CLI uses **seconds** (e.g. `-t 90`) |
79
- | `--json` / `-j` | false | Print full API response as JSON |
80
-
81
- ### How to write instructions (target_selector + output_format)
82
-
83
- When the user wants a **specific part** of the page or a **specific output format**, phrase the command like this:
84
-
85
- - **Output format**: "Extract as **text**" / "Get **markdown**" / "Return **html**" → use `--format text`, `--format markdown`, or `--format html`.
86
- - **Target one element**: "Only the **main article**" / "Just the **content inside** `#main`" / "Extract only **article.main-content**" → use `--target-selector "article.main"` or the selector they give (e.g. `#main`, `.main-content`, `article .post`).
87
-
88
- Examples of user intents and equivalent commands:
89
-
90
- | User intent | Command |
91
- |-------------|---------|
92
- | "Extract this page as plain text" | `--url "..." --format text` |
93
- | "Get only the main content area" | `--url "..." --target-selector "main"` or `article` |
94
- | "Extract the div with id=content as markdown" | `--url "..." --target-selector "#content" --format markdown` |
95
- | "Just the article body, as HTML" | `--url "..." --target-selector "article .body" --format html` |
96
-
97
- Examples:
98
-
99
- ```bash
100
- # Basic: extract as Markdown
101
- node felo-web-extract/scripts/run_web_extract.mjs --url "https://example.com"
102
-
103
- # Article-style with readability
104
- node felo-web-extract/scripts/run_web_extract.mjs --url "https://example.com/article" --readability --format markdown
105
-
106
- # Raw HTML
107
- node felo-web-extract/scripts/run_web_extract.mjs --url "https://example.com" --format html --json
108
-
109
- # Only the element matching a CSS selector (e.g. main article)
110
- node felo-web-extract/scripts/run_web_extract.mjs --url "https://example.com" --target-selector "article.main" --format markdown
111
-
112
- # Specific output format + target selector
113
- node felo-web-extract/scripts/run_web_extract.mjs --url "https://example.com" --target-selector "#content" --format text
114
- ```
115
-
116
- ### Option B: Call API with curl
117
-
118
- ```bash
119
- curl -X POST "https://openapi.felo.ai/v2/web/extract" \
120
- -H "Authorization: Bearer $FELO_API_KEY" \
121
- -H "Content-Type: application/json" \
122
- -d '{"url": "https://example.com", "output_format": "markdown", "with_readability": true}'
123
- ```
124
-
125
- ## API Reference (summary)
126
-
127
- - **Endpoint**: `POST /v2/web/extract`
128
- - **Base URL**: `https://openapi.felo.ai`. Override with `FELO_API_BASE` env if needed.
129
- - **Auth**: `Authorization: Bearer YOUR_API_KEY`
130
-
131
- ### Request body (JSON)
132
-
133
- | Parameter | Type | Required | Default | Description |
134
- |-----------|------|----------|---------|-------------|
135
- | url | string | Yes | - | Webpage URL to extract |
136
- | crawl_mode | string | No | fast | `fast` or `fine` |
137
- | output_format | string | No | html | `html`, `text`, `markdown` |
138
- | with_readability | boolean | No | - | Use readability (main content) |
139
- | with_links_summary | boolean | No | - | Include links summary |
140
- | with_images_summary | boolean | No | - | Include images summary |
141
- | target_selector | string | No | - | CSS selector for target element |
142
- | wait_for_selector | string | No | - | Wait for selector before extract |
143
- | timeout | integer | No | - | Timeout in milliseconds |
144
- | with_cache | boolean | No | true | Use cache |
145
-
146
- ### Response
147
-
148
- Success (200):
149
-
150
- ```json
151
- {
152
- "code": 0,
153
- "message": "success",
154
- "data": {
155
- "content": { ... }
156
- }
157
- }
158
- ```
159
-
160
- Extracted content is in `data.content`; structure depends on `output_format`.
161
-
162
- ### Error codes
163
-
164
- | HTTP | Code | Description |
165
- |------|------|-------------|
166
- | 400 | - | Parameter validation failed |
167
- | 401 | INVALID_API_KEY | API key invalid or revoked |
168
- | 500/502 | WEB_EXTRACT_FAILED | Extract failed (server or page error) |
169
-
170
- ## Output Format
171
-
172
- On success (script without `--json`):
173
-
174
- - Print the extracted content only (for direct use or piping).
175
-
176
- With `--json`:
177
-
178
- - Print full API response including `code`, `message`, `data`.
179
-
180
- Error response to user:
181
-
182
- ```markdown
183
- ## Web Extract Failed
184
-
185
- - Error: <code or message>
186
- - URL: <requested url>
187
- - Suggestion: <e.g. check URL, retry, or use --timeout>
188
- ```
189
-
190
- ## Important Notes
191
-
192
- - Always check `FELO_API_KEY` before calling; if missing, return setup instructions.
193
- - For long articles or slow sites, consider `--timeout` or `timeout` in request body.
194
- - Use `output_format: "markdown"` and `with_readability: true` for clean article text.
195
- - API may cache results; use `with_cache: false` in body only when fresh content is required (script does not expose this by default).
196
-
197
- ## References
198
-
199
- - [Felo Web Extract API](https://openapi.felo.ai/docs/api-reference/v2/web-extract.html)
200
- - [Felo Open Platform](https://openapi.felo.ai/docs/)