pi-all-search 1.0.10 → 1.0.12
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/package.json +1 -1
- package/src/config.ts +20 -9
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
import { PROVIDERS } from "./providers/index.js";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
|
|
6
|
+
const CONFIG_PATH = join(homedir(), ".pi", "pi-all-search.json");
|
|
2
7
|
|
|
3
8
|
export interface SearchConfig {
|
|
4
9
|
apiKeys: Record<string, string>;
|
|
5
|
-
routing?: {
|
|
6
|
-
finance?: string;
|
|
7
|
-
academic?: string;
|
|
8
|
-
general?: string;
|
|
9
|
-
};
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function loadConfig(): SearchConfig {
|
|
13
|
-
const env = process.env;
|
|
14
13
|
const apiKeys: Record<string, string> = {};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const config = JSON.parse(readFileSync(CONFIG_PATH, "utf8"));
|
|
17
|
+
for (const meta of PROVIDERS) {
|
|
18
|
+
const key = config[meta.name + "ApiKey"];
|
|
19
|
+
if (key) apiKeys[meta.name] = key;
|
|
20
|
+
}
|
|
21
|
+
} catch {
|
|
22
|
+
// fallback to env vars
|
|
23
|
+
const env = process.env;
|
|
24
|
+
for (const meta of PROVIDERS) {
|
|
25
|
+
const key = env[meta.envVar];
|
|
26
|
+
if (key) apiKeys[meta.name] = key;
|
|
27
|
+
}
|
|
18
28
|
}
|
|
29
|
+
|
|
19
30
|
return { apiKeys };
|
|
20
31
|
}
|
|
21
32
|
|