@haoyiyin/9router 0.1.0 → 0.1.1
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/README.md +1 -1
- package/package.json +1 -1
- package/src/command.ts +7 -7
- package/src/config.ts +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ pi install npm:@haoyiyin/9router
|
|
|
12
12
|
|
|
13
13
|
## 配置
|
|
14
14
|
|
|
15
|
-
默认无内置地址。运行 `/9router` → 输入 9Router 地址和 API Key → 存入 `~/.pi/agent/9router
|
|
15
|
+
默认无内置地址。运行 `/9router` → 输入 9Router 地址和 API Key → 存入 `~/.pi/agent/haoyiyin/9router.json`(权限 `0600`)。Key 已配置时 `/9router` 可留空保持原值。
|
|
16
16
|
|
|
17
17
|
也可以设置环境变量兜底:`ROUTER_API_BASE` / `ROUTER_API_KEY`(配置文件优先)。
|
|
18
18
|
|
package/package.json
CHANGED
package/src/command.ts
CHANGED
|
@@ -4,22 +4,22 @@ import { registerProvider } from "./provider.ts";
|
|
|
4
4
|
|
|
5
5
|
// Never contains a real key. If a dialog pre-fills this placeholder as an
|
|
6
6
|
// editable default, an exact match is treated as "keep the current key".
|
|
7
|
-
const API_KEY_PLACEHOLDER = "sk
|
|
7
|
+
const API_KEY_PLACEHOLDER = "sk-... (leave empty to keep the current key)";
|
|
8
8
|
|
|
9
9
|
export function registerCommand(pi: ExtensionAPI): void {
|
|
10
10
|
pi.registerCommand("9router", {
|
|
11
|
-
description: "
|
|
11
|
+
description: "Configure 9Router base URL and API key (saved to ~/.pi/agent/haoyiyin/9router.json)",
|
|
12
12
|
handler: async (args: string, ctx: ExtensionCommandContext) => {
|
|
13
13
|
const current = loadConfig();
|
|
14
14
|
|
|
15
|
-
const baseUrl = await ctx.ui.input("9Router
|
|
15
|
+
const baseUrl = await ctx.ui.input("9Router base URL", current.baseUrl || DEFAULT_BASE);
|
|
16
16
|
if (baseUrl === undefined) return;
|
|
17
17
|
const trimmedBase = baseUrl.trim();
|
|
18
18
|
const normalizedBase = trimmedBase.endsWith("/")
|
|
19
19
|
? trimmedBase.slice(0, -1)
|
|
20
20
|
: trimmedBase;
|
|
21
21
|
|
|
22
|
-
const apiKey = await ctx.ui.input("9Router API
|
|
22
|
+
const apiKey = await ctx.ui.input("9Router API key", API_KEY_PLACEHOLDER);
|
|
23
23
|
if (apiKey === undefined) return;
|
|
24
24
|
const trimmedKey = apiKey.trim();
|
|
25
25
|
|
|
@@ -27,7 +27,7 @@ export function registerCommand(pi: ExtensionAPI): void {
|
|
|
27
27
|
if (trimmedKey === "" || trimmedKey === API_KEY_PLACEHOLDER) {
|
|
28
28
|
// Keep the existing key; never treat the placeholder as a submitted value.
|
|
29
29
|
if (!current.apiKey) {
|
|
30
|
-
ctx.ui.notify("
|
|
30
|
+
ctx.ui.notify("No API key configured", "error");
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
33
|
finalKey = current.apiKey;
|
|
@@ -41,12 +41,12 @@ export function registerCommand(pi: ExtensionAPI): void {
|
|
|
41
41
|
await registerProvider(pi);
|
|
42
42
|
} catch (err) {
|
|
43
43
|
ctx.ui.notify(
|
|
44
|
-
`9Router
|
|
44
|
+
`9Router saved, but provider re-registration failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
45
45
|
"warning",
|
|
46
46
|
);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
ctx.ui.notify(`9Router
|
|
49
|
+
ctx.ui.notify(`9Router saved: ${normalizedBase}`, "info");
|
|
50
50
|
},
|
|
51
51
|
});
|
|
52
52
|
}
|
package/src/config.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface RouterConfig {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function configPath(): string {
|
|
13
|
-
return join(homedir(), ".pi", "agent", "9router
|
|
13
|
+
return join(homedir(), ".pi", "agent", "haoyiyin", "9router.json");
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function loadConfig(): RouterConfig {
|