mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-07-09 17:29:12 +00:00
fix: align datasource plugin environment (#595)
* fix: align datasource plugin environment * refactor: inject managed Kimi env into all stdio plugins Pin the datasource credential-name test to the canonical resolveKimiCodeOAuthKey so a digest drift in the standalone plugin fails CI, and drop the hardcoded plugin-name special case so every stdio plugin receives the active managed Kimi base URL / OAuth host consistently (process.env and KIMI_CODE_HOME are already shared with all plugins).
This commit is contained in:
parent
2ebe38769f
commit
1580f35136
11 changed files with 271 additions and 13 deletions
|
|
@ -5,7 +5,7 @@
|
|||
"id": "kimi-datasource",
|
||||
"tier": "official",
|
||||
"displayName": "Kimi Datasource",
|
||||
"version": "3.1.1",
|
||||
"version": "3.1.2",
|
||||
"description": "Official datasource workflows.",
|
||||
"keywords": ["data", "mcp"],
|
||||
"source": "./official/kimi-datasource"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
# Changelog
|
||||
|
||||
## 3.1.2 - 2026-06-09
|
||||
|
||||
- Use OAuth credentials and datasource endpoints that match the active Kimi Code environment.
|
||||
|
||||
## 3.1.1 - 2026-06-02
|
||||
|
||||
- Refine skill activation wording and answer-language guidance.
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ description: |
|
|||
|
||||
这两个工具由 Kimi Code 托管执行,参数直接按 tool schema 传 JSON。
|
||||
|
||||
工具会读取 `$KIMI_CODE_HOME/credentials/kimi-code.json`。如果没有登录凭据,让用户先在 Kimi Code 里执行 `/login`。
|
||||
工具会读取当前 Kimi Code 环境对应的本地 OAuth 登录凭据;当设置了 `KIMI_CODE_OAUTH_HOST` / `KIMI_CODE_BASE_URL` 时,会使用对应环境的隔离凭据。如果没有登录凭据,让用户先在 Kimi Code 里执行 `/login`。
|
||||
|
||||
## 1. 这个 skill 提供什么能力
|
||||
|
||||
|
|
|
|||
|
|
@ -9,17 +9,19 @@
|
|||
// - tools/call
|
||||
// - ping
|
||||
//
|
||||
// Business logic (API call, credentials, headers) is unchanged from the
|
||||
// previous one-shot CLI; only the transport changed.
|
||||
// Business logic is kept self-contained so the plugin can run from a zipped
|
||||
// marketplace install without workspace package dependencies.
|
||||
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { createHash, randomUUID } from 'node:crypto';
|
||||
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
||||
import { arch, homedir, hostname, release, type } from 'node:os';
|
||||
import path from 'node:path';
|
||||
import readline from 'node:readline';
|
||||
|
||||
const VERSION = '3.1.1';
|
||||
const API_URL = process.env.KIMI_DATASOURCE_API_URL ?? 'https://api.kimi.com/coding/v1/tools';
|
||||
const VERSION = '3.1.2';
|
||||
const DEFAULT_KIMI_CODE_OAUTH_HOST = 'https://auth.kimi.com';
|
||||
const DEFAULT_KIMI_CODE_BASE_URL = 'https://api.kimi.com/coding/v1';
|
||||
const API_URL = datasourceApiUrl();
|
||||
const REQUEST_TIMEOUT_MS = 30_000;
|
||||
const PROTOCOL_VERSION = '2025-06-18';
|
||||
|
||||
|
|
@ -209,9 +211,53 @@ function resolveKimiHome() {
|
|||
return explicit && explicit.length > 0 ? explicit : path.join(homedir(), '.kimi-code');
|
||||
}
|
||||
|
||||
function datasourceApiUrl() {
|
||||
const explicit = process.env.KIMI_DATASOURCE_API_URL?.trim();
|
||||
if (explicit !== undefined && explicit.length > 0) return explicit;
|
||||
return `${kimiCodeBaseUrl()}/tools`;
|
||||
}
|
||||
|
||||
function kimiCodeBaseUrl() {
|
||||
return (process.env.KIMI_CODE_BASE_URL ?? DEFAULT_KIMI_CODE_BASE_URL).replace(/\/+$/, '');
|
||||
}
|
||||
|
||||
function kimiCodeOAuthHost() {
|
||||
return normalizeEndpoint(
|
||||
process.env.KIMI_CODE_OAUTH_HOST ??
|
||||
process.env.KIMI_OAUTH_HOST ??
|
||||
DEFAULT_KIMI_CODE_OAUTH_HOST,
|
||||
);
|
||||
}
|
||||
|
||||
function normalizeEndpoint(value) {
|
||||
return value.trim().replace(/\/+$/, '');
|
||||
}
|
||||
|
||||
function resolveKimiCodeCredentialName() {
|
||||
const oauthHost = kimiCodeOAuthHost();
|
||||
const baseUrl = kimiCodeBaseUrl();
|
||||
if (
|
||||
oauthHost === normalizeEndpoint(DEFAULT_KIMI_CODE_OAUTH_HOST) &&
|
||||
baseUrl === DEFAULT_KIMI_CODE_BASE_URL
|
||||
) {
|
||||
return 'kimi-code';
|
||||
}
|
||||
|
||||
// Keep this in sync with packages/oauth/src/managed-kimi-code.ts.
|
||||
const digest = createHash('sha256')
|
||||
.update(JSON.stringify({ oauthHost, baseUrl }))
|
||||
.digest('hex')
|
||||
.slice(0, 16);
|
||||
return `kimi-code-env-${digest}`;
|
||||
}
|
||||
|
||||
async function loadAccessToken() {
|
||||
const kimiHome = resolveKimiHome();
|
||||
const credentialsFile = path.join(kimiHome, 'credentials', 'kimi-code.json');
|
||||
const credentialsFile = path.join(
|
||||
kimiHome,
|
||||
'credentials',
|
||||
`${resolveKimiCodeCredentialName()}.json`,
|
||||
);
|
||||
let parsed;
|
||||
try {
|
||||
parsed = JSON.parse(await readFile(credentialsFile, 'utf8'));
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "kimi-datasource",
|
||||
"version": "3.1.1",
|
||||
"version": "3.1.2",
|
||||
"description": "Finance, macro, enterprise, and academic data tools for Kimi Code.",
|
||||
"keywords": ["finance", "data-source", "mcp"],
|
||||
"mcpServers": {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue