felo-ai 0.2.7 → 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.
- package/.github/workflows/publish-npm.yml +39 -0
- package/CHANGELOG.md +30 -30
- package/CONTRIBUTING.md +346 -346
- package/README.en.md +129 -129
- package/README.md +435 -414
- package/docs/EXAMPLES.md +632 -632
- package/docs/FAQ.md +479 -479
- package/felo-search/LICENSE +21 -21
- package/felo-search/README.md +440 -440
- package/felo-search/SKILL.md +291 -291
- package/felo-slides/LICENSE +21 -21
- package/felo-slides/README.md +87 -87
- package/felo-slides/SKILL.md +166 -166
- package/felo-slides/scripts/run_ppt_task.mjs +251 -251
- package/felo-superAgent/LICENSE +21 -0
- package/felo-superAgent/README.md +125 -0
- package/felo-superAgent/SKILL.md +165 -0
- package/felo-web-fetch/README.md +127 -78
- package/felo-web-fetch/SKILL.md +204 -200
- package/felo-web-fetch/scripts/run_web_fetch.mjs +316 -232
- package/felo-x-search/SKILL.md +204 -0
- package/felo-x-search/scripts/run_x_search.mjs +385 -0
- package/felo-youtube-subtitling/README.md +59 -59
- package/felo-youtube-subtitling/SKILL.md +161 -161
- package/felo-youtube-subtitling/scripts/run_youtube_subtitling.mjs +239 -239
- package/package.json +37 -35
- package/src/cli.js +370 -252
- package/src/config.js +66 -66
- package/src/search.js +142 -142
- package/src/slides.js +332 -332
- package/src/superAgent.js +609 -0
- package/src/webFetch.js +148 -148
- package/src/xSearch.js +366 -0
- package/src/youtubeSubtitling.js +179 -179
- package/tests/config.test.js +78 -78
- package/tests/search.test.js +100 -100
package/tests/search.test.js
CHANGED
|
@@ -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
|
+
});
|