pi-all-search 1.0.10 → 1.0.11

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/config.ts +20 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-all-search",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "All-in-one web search extension for Pi — exa, tavily, anysearch, firecrawl, context7",
5
5
  "license": "MIT",
6
6
  "type": "module",
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", "web-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
- for (const meta of PROVIDERS) {
16
- const key = env[meta.envVar];
17
- if (key) apiKeys[meta.name] = key;
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