pi-provider-kimi-code 0.5.0 → 0.6.0
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 +63 -40
- package/index.ts +60 -46
- package/package.json +25 -23
- package/src/config.ts +82 -37
- package/src/constants.ts +3 -4
- package/src/models.ts +23 -4
- package/src/oauth.ts +1 -0
- package/src/payload.ts +22 -6
- package/src/stream.ts +54 -8
- package/src/tools/common.ts +115 -0
- package/src/tools/datasource.ts +191 -0
- package/src/tools/moonshot.ts +43 -112
package/README.md
CHANGED
|
@@ -5,28 +5,32 @@
|
|
|
5
5
|
|
|
6
6
|
**Use Kimi Code in Pi, with the Kimi parts handled.**
|
|
7
7
|
|
|
8
|
-
Pi already has a basic `kimi-coding` provider. This extension is for the parts that start to matter once Kimi Code becomes part of your real Pi workflow: account login reuse, file uploads, measured cache behavior, live model metadata, and optional Moonshot search/fetch tools.
|
|
8
|
+
Pi already has a basic `kimi-coding` provider. This extension is for the parts that start to matter once Kimi Code becomes part of your real Pi workflow: account login reuse, file uploads, measured cache behavior, live model metadata, and optional Moonshot search/fetch/datasource tools.
|
|
9
|
+
|
|
10
|
+
> **Kimi K2.7 supported.** The provider automatically discovers the current model from Kimi's `/v1/models` endpoint at login time, so new rollouts (including K2.7) are picked up immediately without a package update.
|
|
9
11
|
|
|
10
12
|
## Why this exists
|
|
11
13
|
|
|
12
|
-
Pi is a small harness you adapt to your own workflow. Kimi
|
|
14
|
+
Pi is a small harness you adapt to your own workflow. Kimi Code is Moonshot's official coding agent. This package sits between them: Kimi Code as a Pi provider, plus the Kimi-specific details that the basic provider keeps simple.
|
|
15
|
+
|
|
16
|
+
Kimi's API surface goes beyond the LLM itself. It includes file uploads, web search, page fetch, and a growing set of datasource APIs. This extension wires those capabilities into Pi so you can use them alongside the community's existing extensions — MCP servers, custom themes, skills, and any other Pi add-on — without leaving the harness.
|
|
13
17
|
|
|
14
|
-
- **Use your Kimi account.** Log in with `/login kimi-coding`, or reuse an existing `kimi-
|
|
18
|
+
- **Use your Kimi account.** Log in with `/login kimi-coding`, or reuse an existing `kimi-code` session.
|
|
15
19
|
- **Send files the Kimi way.** Large inline images go through Kimi's Files API and become `ms://` references instead of huge base64 payloads.
|
|
16
20
|
- **Know what the cache is doing.** Kimi caches by content prefix. This repo measures that behavior instead of pretending `prompt_cache_key` controls it.
|
|
17
21
|
- **Use the safer protocol by default.** OpenAI-compatible mode is the default because tool results are less ambiguous there. Anthropic-compatible mode is still available.
|
|
18
|
-
- **Turn on Kimi-native tools when you want them.** `moonshot_search` and `
|
|
22
|
+
- **Turn on Kimi-native tools when you want them.** `moonshot_search`, `moonshot_fetch`, and `kimi_datasource` are opt-in, configurable per user or per project.
|
|
19
23
|
|
|
20
24
|
## What this package adds
|
|
21
25
|
|
|
22
26
|
- Kimi account login in Pi, plus `KIMI_API_KEY` for CI or pay-per-token use.
|
|
23
|
-
- `kimi-
|
|
27
|
+
- `kimi-code` credential reuse from `~/.kimi/credentials/kimi-code.json`.
|
|
24
28
|
- Kimi Files API uploads for large inline images.
|
|
25
29
|
- Live model metadata from Kimi at login / refresh time.
|
|
26
30
|
- OpenAI-compatible mode by default, Anthropic-compatible mode on request.
|
|
27
31
|
- Kimi K2.6 reasoning level mapping for Pi's reasoning controls.
|
|
28
32
|
- Stream cleanup for Kimi's thinking-only placeholder text.
|
|
29
|
-
- Optional `moonshot_search` and `
|
|
33
|
+
- Optional `moonshot_search`, `moonshot_fetch`, and unified datasource `kimi_datasource` tools via `/kimi-settings`.
|
|
30
34
|
- No build step; Pi loads the TypeScript extension directly.
|
|
31
35
|
|
|
32
36
|
## Install
|
|
@@ -62,13 +66,13 @@ Inside Pi, run:
|
|
|
62
66
|
|
|
63
67
|
A browser tab opens, you sign into your Kimi account, and Pi stores the credential at `~/.pi/agent/auth.json`. Tokens refresh automatically.
|
|
64
68
|
|
|
65
|
-
If you already use `kimi-
|
|
69
|
+
If you already use `kimi-code`, this extension can reuse its credential file:
|
|
66
70
|
|
|
67
71
|
```text
|
|
68
72
|
~/.kimi/credentials/kimi-code.json
|
|
69
73
|
```
|
|
70
74
|
|
|
71
|
-
The file is read-only from this extension's side. Set `KIMI_SHARE_DIR` if your `kimi-
|
|
75
|
+
The file is read-only from this extension's side. Set `KIMI_SHARE_DIR` if your `kimi-code` share directory lives somewhere else.
|
|
72
76
|
|
|
73
77
|
For CI or pay-per-token use, set `KIMI_API_KEY` instead:
|
|
74
78
|
|
|
@@ -90,32 +94,20 @@ Select it inside Pi:
|
|
|
90
94
|
/model kimi-coding/kimi-for-coding
|
|
91
95
|
```
|
|
92
96
|
|
|
93
|
-
Kimi keeps Coding models behind aliases. Rather than hardcoding a stale model list, this extension asks Kimi for the current model info when you log in or refresh. If your account is on a newer rollout or internal test, Pi can pick up the latest model name and context size without waiting for a package release.
|
|
97
|
+
Kimi keeps Coding models behind aliases. Rather than hardcoding a stale model list, this extension asks Kimi for the current model info when you log in or refresh. If your account is on a newer rollout (e.g., Kimi K2.7) or internal test, Pi can pick up the latest model name and context size without waiting for a package release.
|
|
94
98
|
|
|
95
99
|
Fallback values:
|
|
96
100
|
|
|
97
|
-
- Context window: `
|
|
98
|
-
- Max output: `
|
|
101
|
+
- Context window: `256k` tokens
|
|
102
|
+
- Max output: `32k` tokens
|
|
99
103
|
- Input: text and image
|
|
100
104
|
- Reasoning: enabled
|
|
101
105
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
- `off` / `none` — reasoning disabled
|
|
105
|
-
- `minimal` / `low` — low effort
|
|
106
|
-
- `medium` — medium effort
|
|
107
|
-
- `high` / `xhigh` — high effort
|
|
108
|
-
|
|
109
|
-
If Kimi reports a larger context window, the provider uses that value. You can also override the advertised context or model name with `KIMI_MODEL_MAX_CONTEXT_SIZE` / `KIMI_MODEL_NAME`; see [docs/ENV.md](docs/ENV.md).
|
|
106
|
+
The provider maps Pi's reasoning levels to Kimi's reasoning-effort controls. The exact mapping depends on the model returned by the server at login time, and the provider refreshes it automatically on every credential refresh.
|
|
110
107
|
|
|
111
|
-
## Optional
|
|
108
|
+
## Optional tools
|
|
112
109
|
|
|
113
|
-
Kimi Coding has server-side
|
|
114
|
-
|
|
115
|
-
- `moonshot_search`
|
|
116
|
-
- `moonshot_fetch`
|
|
117
|
-
|
|
118
|
-
They are off by default. Turn them on when you want Kimi's own search/fetch path in the agent loop.
|
|
110
|
+
Kimi Coding has server-side capabilities that this extension can expose as opt-in tools. All tools are off by default. Enable them individually through `/kimi-settings` or JSON config.
|
|
119
111
|
|
|
120
112
|
Inside Pi, run:
|
|
121
113
|
|
|
@@ -130,18 +122,50 @@ Config files are JSON:
|
|
|
130
122
|
- Home: `~/.pi/pi-provider-kimi-code.json`
|
|
131
123
|
- Project override: `<cwd>/.pi/pi-provider-kimi-code.json`
|
|
132
124
|
|
|
133
|
-
Project config overrides home config with a deep merge. Missing files or missing keys mean
|
|
125
|
+
Project config overrides home config with a deep merge. Missing files or missing keys mean all tools stay off.
|
|
126
|
+
|
|
127
|
+
### Available tools
|
|
128
|
+
|
|
129
|
+
| Tool | Description |
|
|
130
|
+
| ----------------- | ---------------------------------------------- |
|
|
131
|
+
| `moonshot_search` | Web search through Kimi's Moonshot service |
|
|
132
|
+
| `moonshot_fetch` | Web page fetch through Kimi's Moonshot service |
|
|
133
|
+
| `kimi_datasource` | Unified Kimi datasource tool |
|
|
134
|
+
|
|
135
|
+
### Example config
|
|
134
136
|
|
|
135
137
|
```json
|
|
136
138
|
{
|
|
137
139
|
"tools": {
|
|
138
140
|
"moonshot_search": { "enabled": true, "default_collapsed": true },
|
|
139
|
-
"moonshot_fetch": { "enabled": true, "default_collapsed": true }
|
|
141
|
+
"moonshot_fetch": { "enabled": true, "default_collapsed": true },
|
|
142
|
+
"kimi_datasource": { "enabled": true, "default_collapsed": true }
|
|
140
143
|
}
|
|
141
144
|
}
|
|
142
145
|
```
|
|
143
146
|
|
|
144
|
-
|
|
147
|
+
### Datasource tool
|
|
148
|
+
|
|
149
|
+
`kimi_datasource` calls Kimi's `/tools` endpoint. It accepts `data_source_name` plus optional `api_name` and `params`:
|
|
150
|
+
|
|
151
|
+
- Without `api_name`: returns the datasource description (available APIs).
|
|
152
|
+
- With `api_name` and `params`: calls the specified API.
|
|
153
|
+
|
|
154
|
+
Supported datasource names:
|
|
155
|
+
|
|
156
|
+
| Datasource | Description |
|
|
157
|
+
| ---------------------- | ------------------------------------- |
|
|
158
|
+
| `stock_finance_data` | Chinese stock and financial data |
|
|
159
|
+
| `yahoo_finance` | Yahoo Finance market data |
|
|
160
|
+
| `world_bank_open_data` | World Bank open statistics |
|
|
161
|
+
| `tianyancha` | Chinese enterprise and corporate data |
|
|
162
|
+
| `arxiv` | Academic paper search and metadata |
|
|
163
|
+
| `scholar` | Academic literature search |
|
|
164
|
+
| `yuandian_law` | Chinese legal database and case law |
|
|
165
|
+
|
|
166
|
+
### Common notes
|
|
167
|
+
|
|
168
|
+
All tools require `/login kimi-coding` OAuth credentials. `KIMI_API_KEY` is not used for these tools. Your account also needs access to Moonshot's server-side services; if not, the upstream service can return subscription or whitelist errors.
|
|
145
169
|
|
|
146
170
|
`default_collapsed` controls only the TUI preview. The full tool result still goes to the model; set it to `false` if you want previews expanded by default.
|
|
147
171
|
|
|
@@ -156,13 +180,13 @@ Most users do not need environment variables. Two are worth knowing:
|
|
|
156
180
|
|
|
157
181
|
Moonshot search/fetch tools are configured through `/kimi-settings` or JSON config files, not env vars.
|
|
158
182
|
|
|
159
|
-
The full env list, including base URL overrides, `kimi-
|
|
183
|
+
The full env list, including base URL overrides, `kimi-code` path overrides, upload tuning, debug logs, and model metadata overrides, lives in [docs/ENV.md](docs/ENV.md).
|
|
160
184
|
|
|
161
185
|
## Notes
|
|
162
186
|
|
|
163
|
-
### Kimi
|
|
187
|
+
### Kimi Code vs Pi
|
|
164
188
|
|
|
165
|
-
`kimi-
|
|
189
|
+
`kimi-code` is Moonshot's official terminal agent. Pi is the harness you adapt to your own workflow: extensions, skills, prompts, themes, custom commands, status bars, and UI pieces. This package lets you keep Kimi Code as the model path while staying inside Pi.
|
|
166
190
|
|
|
167
191
|
### Cache behavior
|
|
168
192
|
|
|
@@ -189,7 +213,7 @@ The OpenAI-compatible protocol uses a dedicated `role: "tool"` message, so the b
|
|
|
189
213
|
|
|
190
214
|
### Is this affiliated with Moonshot AI?
|
|
191
215
|
|
|
192
|
-
No. This is an independent extension. The login flow is derived from the public implementation in the open-source
|
|
216
|
+
No. This is an independent extension. The login flow is derived from the public implementation in the open-source Kimi Code repository.
|
|
193
217
|
|
|
194
218
|
## Troubleshooting
|
|
195
219
|
|
|
@@ -203,17 +227,17 @@ The login flow always prints a verification URL. If your terminal or OS blocks a
|
|
|
203
227
|
|
|
204
228
|
### "Access denied" or subscription errors after a successful login
|
|
205
229
|
|
|
206
|
-
Your Moonshot account needs an active Kimi Code
|
|
230
|
+
Your Moonshot account needs an active Kimi Code Plan for the provider to do anything useful. If the same account works in `kimi-code`, re-run `/login kimi-coding` to refresh credentials.
|
|
207
231
|
|
|
208
|
-
###
|
|
232
|
+
### Tools do not show up
|
|
209
233
|
|
|
210
|
-
Run `/kimi-settings` and check whether
|
|
234
|
+
Run `/kimi-settings` and check whether the tool is enabled in the home or project config. All tools also require `/login kimi-coding`; `KIMI_API_KEY` is not enough.
|
|
211
235
|
|
|
212
236
|
If you changed the JSON config by hand, reload it through `/kimi-settings` or start a new Pi session.
|
|
213
237
|
|
|
214
|
-
###
|
|
238
|
+
### Tools return subscription or whitelist errors
|
|
215
239
|
|
|
216
|
-
The tools call Moonshot's server-side
|
|
240
|
+
The tools call Moonshot's server-side services. Some accounts may not have access even with an active Kimi Code Plan. The error comes from the upstream service.
|
|
217
241
|
|
|
218
242
|
### Large images fail with a payload error
|
|
219
243
|
|
|
@@ -238,7 +262,6 @@ In OpenAI mode this extension maps the `developer` role to `system` (Kimi's Codi
|
|
|
238
262
|
## References
|
|
239
263
|
|
|
240
264
|
- Pi: [earendil-works/pi](https://github.com/earendil-works/pi)
|
|
241
|
-
- Upstream login implementation and feature request: [MoonshotAI/kimi-cli](https://github.com/MoonshotAI/kimi-cli) · [kimi-cli#757](https://github.com/MoonshotAI/kimi-cli/issues/757)
|
|
242
265
|
- Environment variables: [docs/ENV.md](docs/ENV.md)
|
|
243
266
|
- Testing guide: [docs/TESTING.md](docs/TESTING.md)
|
|
244
267
|
- Cache behavior: [docs/caching.md](docs/caching.md)
|
|
@@ -246,7 +269,7 @@ In OpenAI mode this extension maps the `developer` role to `system` (Kimi's Codi
|
|
|
246
269
|
|
|
247
270
|
## Credits
|
|
248
271
|
|
|
249
|
-
Based on the login implementation from
|
|
272
|
+
Based on the login implementation from Kimi Code by Moonshot AI. Built as a Pi extension by [@badlogic](https://github.com/badlogic).
|
|
250
273
|
|
|
251
274
|
## License
|
|
252
275
|
|
package/index.ts
CHANGED
|
@@ -29,13 +29,16 @@ import { relative } from "node:path";
|
|
|
29
29
|
|
|
30
30
|
import {
|
|
31
31
|
type KimiCodeConfig,
|
|
32
|
+
KIMI_TOOL_NAMES,
|
|
32
33
|
getProjectKimiCodeConfigPath,
|
|
33
34
|
getGlobalKimiCodeConfigPath,
|
|
34
35
|
loadHomeKimiCodeConfig,
|
|
35
36
|
loadKimiCodeConfig,
|
|
37
|
+
loadKimiCodeConfigSources,
|
|
36
38
|
loadProjectKimiCodeConfig,
|
|
37
39
|
saveHomeKimiCodeConfig,
|
|
38
40
|
saveProjectKimiCodeConfig,
|
|
41
|
+
type KimiToolName,
|
|
39
42
|
} from "./src/config.ts";
|
|
40
43
|
import {
|
|
41
44
|
DEFAULT_KIMI_MODEL_INPUT,
|
|
@@ -49,12 +52,10 @@ import {
|
|
|
49
52
|
applyKimiEnvOverridesToModel,
|
|
50
53
|
applyKimiOAuthExtrasToModel,
|
|
51
54
|
} from "./src/models.ts";
|
|
52
|
-
import { loginKimiCode, refreshKimiCodeToken } from "./src/oauth.ts";
|
|
55
|
+
import { loginKimiCode, refreshKimiAuthToken, refreshKimiCodeToken } from "./src/oauth.ts";
|
|
53
56
|
import { streamSimpleKimi } from "./src/stream.ts";
|
|
54
57
|
import { buildMoonshotFetchTool, buildMoonshotSearchTool } from "./src/tools/moonshot.ts";
|
|
55
|
-
|
|
56
|
-
const MOONSHOT_TOOL_NAMES = ["moonshot_search", "moonshot_fetch"] as const;
|
|
57
|
-
type MoonshotToolName = (typeof MOONSHOT_TOOL_NAMES)[number];
|
|
58
|
+
import { buildKimiDatasourceTool } from "./src/tools/datasource.ts";
|
|
58
59
|
type KimiConfigScope = "project" | "home";
|
|
59
60
|
const MEMBERSHIP_LEVEL_NAMES: Record<string, string> = {
|
|
60
61
|
LEVEL_FREE: "Free",
|
|
@@ -71,30 +72,30 @@ interface UsageRow {
|
|
|
71
72
|
limit: number;
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
function buildKimiTool(toolName: KimiToolName, config: KimiCodeConfig) {
|
|
76
|
+
const opts = { defaultCollapsed: config.tools[toolName].default_collapsed };
|
|
77
|
+
if (toolName === "moonshot_search") return buildMoonshotSearchTool(opts);
|
|
78
|
+
if (toolName === "moonshot_fetch") return buildMoonshotFetchTool(opts);
|
|
79
|
+
if (toolName === "kimi_datasource") return buildKimiDatasourceTool(opts);
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
74
83
|
function registerConfiguredMoonshotTools(
|
|
75
84
|
pi: ExtensionAPI,
|
|
76
85
|
config: KimiCodeConfig,
|
|
77
86
|
options: { updateActiveTools: boolean },
|
|
78
87
|
): void {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
if (config.tools.moonshot_fetch.enabled) {
|
|
87
|
-
pi.registerTool(
|
|
88
|
-
buildMoonshotFetchTool({
|
|
89
|
-
defaultCollapsed: config.tools.moonshot_fetch.default_collapsed,
|
|
90
|
-
}),
|
|
91
|
-
);
|
|
88
|
+
for (const toolName of KIMI_TOOL_NAMES) {
|
|
89
|
+
if (config.tools[toolName].enabled) {
|
|
90
|
+
const tool = buildKimiTool(toolName, config);
|
|
91
|
+
if (tool) pi.registerTool(tool);
|
|
92
|
+
}
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
if (!options.updateActiveTools) return;
|
|
95
96
|
|
|
96
97
|
const activeTools = new Set(pi.getActiveTools());
|
|
97
|
-
for (const toolName of
|
|
98
|
+
for (const toolName of KIMI_TOOL_NAMES) {
|
|
98
99
|
if (config.tools[toolName].enabled) {
|
|
99
100
|
activeTools.add(toolName);
|
|
100
101
|
} else {
|
|
@@ -186,6 +187,17 @@ function quotaBar(remaining: number, limit: number): string {
|
|
|
186
187
|
return `[${"#".repeat(filled)}${"-".repeat(width - filled)}]`;
|
|
187
188
|
}
|
|
188
189
|
|
|
190
|
+
function fetchKimiUsage(token: string, signal: AbortSignal): Promise<Response> {
|
|
191
|
+
return fetch("https://api.kimi.com/coding/v1/usages", {
|
|
192
|
+
method: "GET",
|
|
193
|
+
headers: {
|
|
194
|
+
...getCommonHeaders(),
|
|
195
|
+
Authorization: `Bearer ${token}`,
|
|
196
|
+
},
|
|
197
|
+
signal,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
189
201
|
async function fetchKimiUsageSummary(): Promise<string> {
|
|
190
202
|
const token = getKimiUsageToken();
|
|
191
203
|
if (!token) return "Usage: missing credentials. Run /login kimi-coding.";
|
|
@@ -193,14 +205,11 @@ async function fetchKimiUsageSummary(): Promise<string> {
|
|
|
193
205
|
const controller = new AbortController();
|
|
194
206
|
const timeout = setTimeout(() => controller.abort(), 15_000);
|
|
195
207
|
try {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
},
|
|
202
|
-
signal: controller.signal,
|
|
203
|
-
});
|
|
208
|
+
let response = await fetchKimiUsage(token, controller.signal);
|
|
209
|
+
if (response.status === 401) {
|
|
210
|
+
const refreshed = await refreshKimiAuthToken(token);
|
|
211
|
+
if (refreshed) response = await fetchKimiUsage(refreshed, controller.signal);
|
|
212
|
+
}
|
|
204
213
|
if (!response.ok) return `Usage: fetch failed (${response.status})`;
|
|
205
214
|
return parseUsageSummary(await response.json());
|
|
206
215
|
} catch (error) {
|
|
@@ -212,7 +221,7 @@ async function fetchKimiUsageSummary(): Promise<string> {
|
|
|
212
221
|
}
|
|
213
222
|
|
|
214
223
|
function moonshotStatus(config: KimiCodeConfig): string {
|
|
215
|
-
return
|
|
224
|
+
return KIMI_TOOL_NAMES.map((toolName) => {
|
|
216
225
|
const tool = config.tools[toolName];
|
|
217
226
|
const enabled = tool.enabled ? "enabled" : "disabled";
|
|
218
227
|
const collapsed = tool.default_collapsed ? "collapsed" : "expanded";
|
|
@@ -220,7 +229,7 @@ function moonshotStatus(config: KimiCodeConfig): string {
|
|
|
220
229
|
}).join("\n");
|
|
221
230
|
}
|
|
222
231
|
|
|
223
|
-
function toggleEnabled(config: KimiCodeConfig, toolName:
|
|
232
|
+
function toggleEnabled(config: KimiCodeConfig, toolName: KimiToolName): KimiCodeConfig {
|
|
224
233
|
return {
|
|
225
234
|
tools: {
|
|
226
235
|
...config.tools,
|
|
@@ -232,7 +241,7 @@ function toggleEnabled(config: KimiCodeConfig, toolName: MoonshotToolName): Kimi
|
|
|
232
241
|
};
|
|
233
242
|
}
|
|
234
243
|
|
|
235
|
-
function toggleCollapsed(config: KimiCodeConfig, toolName:
|
|
244
|
+
function toggleCollapsed(config: KimiCodeConfig, toolName: KimiToolName): KimiCodeConfig {
|
|
236
245
|
return {
|
|
237
246
|
tools: {
|
|
238
247
|
...config.tools,
|
|
@@ -278,18 +287,15 @@ async function editConfigScope(
|
|
|
278
287
|
): Promise<KimiCodeConfig> {
|
|
279
288
|
let current = loadScopeKimiCodeConfig(scope, ctx.cwd);
|
|
280
289
|
while (true) {
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
"Back",
|
|
285
|
-
]);
|
|
290
|
+
const items = KIMI_TOOL_NAMES.map((name) => toolMenuItem(current, name));
|
|
291
|
+
items.push("Back");
|
|
292
|
+
const choice = await ctx.ui.select(buildConfigScopeTitle(scope, current, ctx.cwd), items);
|
|
286
293
|
if (!choice || choice === "Back") {
|
|
287
294
|
return loadKimiCodeConfig({ cwd: ctx.cwd, home: os.homedir() });
|
|
288
295
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
current = await editMoonshotTool(pi, ctx, scope, current, "moonshot_fetch");
|
|
296
|
+
const toolName = KIMI_TOOL_NAMES.find((name) => choice.startsWith(name));
|
|
297
|
+
if (toolName) {
|
|
298
|
+
current = await editMoonshotTool(pi, ctx, scope, current, toolName);
|
|
293
299
|
}
|
|
294
300
|
}
|
|
295
301
|
}
|
|
@@ -299,7 +305,7 @@ async function editMoonshotTool(
|
|
|
299
305
|
ctx: ExtensionCommandContext,
|
|
300
306
|
scope: KimiConfigScope,
|
|
301
307
|
config: KimiCodeConfig,
|
|
302
|
-
toolName:
|
|
308
|
+
toolName: KimiToolName,
|
|
303
309
|
): Promise<KimiCodeConfig> {
|
|
304
310
|
let current = config;
|
|
305
311
|
while (true) {
|
|
@@ -322,6 +328,7 @@ async function editMoonshotTool(
|
|
|
322
328
|
const effective = loadKimiCodeConfig({ cwd: ctx.cwd, home: os.homedir() });
|
|
323
329
|
registerConfiguredMoonshotTools(pi, effective, { updateActiveTools: true });
|
|
324
330
|
ctx.ui.notify(`Saved ${toolName} config`, "info");
|
|
331
|
+
return current;
|
|
325
332
|
}
|
|
326
333
|
}
|
|
327
334
|
|
|
@@ -342,8 +349,17 @@ function saveScopeKimiCodeConfig(
|
|
|
342
349
|
}
|
|
343
350
|
}
|
|
344
351
|
|
|
345
|
-
function buildKimiMainTitle(
|
|
346
|
-
|
|
352
|
+
function buildKimiMainTitle(config: KimiCodeConfig, cwd: string): string {
|
|
353
|
+
const sources = loadKimiCodeConfigSources({ cwd, home: os.homedir() });
|
|
354
|
+
return [
|
|
355
|
+
"Kimi settings",
|
|
356
|
+
"",
|
|
357
|
+
"Effective tools:",
|
|
358
|
+
...KIMI_TOOL_NAMES.map((toolName) => {
|
|
359
|
+
const enabled = config.tools[toolName].enabled ? "enabled" : "disabled";
|
|
360
|
+
return `- ${toolName}: ${enabled} (${sources.tools[toolName].enabled})`;
|
|
361
|
+
}),
|
|
362
|
+
].join("\n");
|
|
347
363
|
}
|
|
348
364
|
|
|
349
365
|
function buildConfigScopeTitle(
|
|
@@ -363,11 +379,11 @@ function homeRelative(filePath: string): string {
|
|
|
363
379
|
return filePath.startsWith(`${home}/`) ? `~/${filePath.slice(home.length + 1)}` : filePath;
|
|
364
380
|
}
|
|
365
381
|
|
|
366
|
-
function toolMenuItem(config: KimiCodeConfig, toolName:
|
|
382
|
+
function toolMenuItem(config: KimiCodeConfig, toolName: KimiToolName): string {
|
|
367
383
|
return `${toolName} -> ${formatToolStatus(config, toolName)}`;
|
|
368
384
|
}
|
|
369
385
|
|
|
370
|
-
function formatToolStatus(config: KimiCodeConfig, toolName:
|
|
386
|
+
function formatToolStatus(config: KimiCodeConfig, toolName: KimiToolName): string {
|
|
371
387
|
const tool = config.tools[toolName];
|
|
372
388
|
const enabled = tool.enabled ? "enabled" : "disabled";
|
|
373
389
|
const collapsed = tool.default_collapsed ? "default collapsed" : "default expanded";
|
|
@@ -379,12 +395,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
379
395
|
|
|
380
396
|
pi.registerProvider(PROVIDER_ID, {
|
|
381
397
|
baseUrl: getBaseUrl(),
|
|
382
|
-
apiKey: "KIMI_API_KEY",
|
|
398
|
+
apiKey: "$KIMI_API_KEY",
|
|
383
399
|
api: KIMI_API_TYPE,
|
|
384
400
|
streamSimple: streamSimpleKimi,
|
|
385
401
|
|
|
386
|
-
headers: getCommonHeaders(),
|
|
387
|
-
|
|
388
402
|
models: [
|
|
389
403
|
applyKimiEnvOverridesToModel({
|
|
390
404
|
id: "kimi-for-coding",
|
package/package.json
CHANGED
|
@@ -1,39 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-provider-kimi-code",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Use Kimi Code in Pi without losing the Kimi-specific bits",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"pi-package",
|
|
7
|
-
"pi-extension",
|
|
8
|
-
"pi-provider",
|
|
9
|
-
"pi",
|
|
10
|
-
"pi-coding-agent",
|
|
11
|
-
"pi-mono",
|
|
12
|
-
"coding-agent",
|
|
13
6
|
"ai-provider",
|
|
14
|
-
"
|
|
15
|
-
"llm-provider",
|
|
7
|
+
"coding-agent",
|
|
16
8
|
"kimi",
|
|
9
|
+
"kimi-code",
|
|
17
10
|
"kimi-for-coding",
|
|
18
|
-
"kimi-coder",
|
|
19
11
|
"kimi-k2",
|
|
20
|
-
"kimi-k2.6",
|
|
21
12
|
"kimi-k2.5",
|
|
13
|
+
"kimi-k2.6",
|
|
14
|
+
"kimi-k2.7",
|
|
15
|
+
"llm",
|
|
16
|
+
"llm-provider",
|
|
22
17
|
"moonshot",
|
|
23
18
|
"moonshotai",
|
|
24
19
|
"oauth",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
20
|
+
"pi",
|
|
21
|
+
"pi-coding-agent",
|
|
22
|
+
"pi-extension",
|
|
23
|
+
"pi-package",
|
|
24
|
+
"pi-provider"
|
|
27
25
|
],
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/Leechael/pi-provider-kimi-code/issues"
|
|
28
|
+
},
|
|
28
29
|
"license": "MIT",
|
|
30
|
+
"author": "Leechael",
|
|
29
31
|
"repository": {
|
|
30
32
|
"type": "git",
|
|
31
33
|
"url": "https://github.com/Leechael/pi-provider-kimi-code"
|
|
32
34
|
},
|
|
33
|
-
"bugs": {
|
|
34
|
-
"url": "https://github.com/Leechael/pi-provider-kimi-code/issues"
|
|
35
|
-
},
|
|
36
|
-
"author": "Leechael",
|
|
37
35
|
"files": [
|
|
38
36
|
"index.ts",
|
|
39
37
|
"src",
|
|
@@ -51,17 +49,21 @@
|
|
|
51
49
|
"format:check": "oxfmt . --check",
|
|
52
50
|
"pre-commit": "prek run"
|
|
53
51
|
},
|
|
54
|
-
"peerDependencies": {
|
|
55
|
-
"@earendil-works/pi-coding-agent": "*",
|
|
56
|
-
"@earendil-works/pi-ai": "*"
|
|
57
|
-
},
|
|
58
52
|
"devDependencies": {
|
|
59
|
-
"@
|
|
53
|
+
"@earendil-works/pi-ai": "^0.78.0",
|
|
54
|
+
"@earendil-works/pi-coding-agent": "^0.78.0",
|
|
55
|
+
"@earendil-works/pi-tui": "^0.78.1",
|
|
56
|
+
"@j178/prek": "^0.4.4",
|
|
60
57
|
"@types/node": "^24.0.0",
|
|
61
58
|
"oxfmt": "^0.44.0",
|
|
62
59
|
"oxlint": "^1.59.0",
|
|
63
60
|
"typescript": "^5.9.0"
|
|
64
61
|
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"@earendil-works/pi-ai": "*",
|
|
64
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
65
|
+
"@earendil-works/pi-tui": "*"
|
|
66
|
+
},
|
|
65
67
|
"pi": {
|
|
66
68
|
"extensions": [
|
|
67
69
|
"./index.ts"
|