@core-ai/kimi 0.16.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/LICENSE +21 -0
- package/README.md +70 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +76 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Omnifact (https://omnifact.ai)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# @core-ai/kimi
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@core-ai/kimi)
|
|
4
|
+
|
|
5
|
+
Kimi (Moonshot AI) provider package for `@core-ai/core-ai`.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @core-ai/core-ai @core-ai/kimi zod
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { generate } from '@core-ai/core-ai';
|
|
17
|
+
import { createKimi } from '@core-ai/kimi';
|
|
18
|
+
|
|
19
|
+
const kimi = createKimi({
|
|
20
|
+
apiKey: process.env.KIMI_API_KEY,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const model = kimi.chatModel('kimi-k2.7-code');
|
|
24
|
+
|
|
25
|
+
const result = await generate({
|
|
26
|
+
model,
|
|
27
|
+
messages: [{ role: 'user', content: 'Implement quicksort in TypeScript.' }],
|
|
28
|
+
maxTokens: 32768,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
console.log(result.content);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
By default, requests go to `https://api.moonshot.ai/v1`. Set `baseURL` to use a custom endpoint.
|
|
35
|
+
|
|
36
|
+
## Supported models
|
|
37
|
+
|
|
38
|
+
- `kimi-k2.7-code` — coding-focused agentic model with always-on thinking
|
|
39
|
+
- `kimi-k2.7-code-highspeed` — same model with higher output speed
|
|
40
|
+
|
|
41
|
+
## Reasoning and preserved thinking
|
|
42
|
+
|
|
43
|
+
Kimi K2.7 Code always runs in thinking mode. The provider maps Moonshot's `reasoning_content` field to core-ai reasoning parts and preserves it across multi-turn conversations via `resultToMessage()`.
|
|
44
|
+
|
|
45
|
+
## Fixed sampling constraints
|
|
46
|
+
|
|
47
|
+
For `kimi-k2.7-code` and `kimi-k2.7-code-highspeed`, Moonshot fixes sampling parameters server-side. Do not pass custom `temperature` or `topP` values — the provider validates these locally and omits fixed parameters from requests.
|
|
48
|
+
|
|
49
|
+
## Structured output
|
|
50
|
+
|
|
51
|
+
`generateObject()` and `streamObject()` use Moonshot JSON Mode (`response_format: { type: 'json_object' }`) and validate the returned JSON with your Zod schema.
|
|
52
|
+
|
|
53
|
+
Forced tool choice via `toolChoice: { type: 'tool', toolName }` is rejected on K2.7 Code models because Moonshot does not allow forced tool selection while thinking is always enabled.
|
|
54
|
+
|
|
55
|
+
## Provider options
|
|
56
|
+
|
|
57
|
+
Pass Kimi-specific options via `providerOptions.kimi`:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
await generate({
|
|
61
|
+
model,
|
|
62
|
+
messages: [{ role: 'user', content: 'Hello' }],
|
|
63
|
+
providerOptions: {
|
|
64
|
+
kimi: {
|
|
65
|
+
parallelToolCalls: true,
|
|
66
|
+
stopSequences: ['END'],
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ChatModel } from '@core-ai/core-ai';
|
|
2
|
+
import { OpenAIProviderBaseOptions } from '@core-ai/openai';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
type KimiProviderOptions = OpenAIProviderBaseOptions;
|
|
6
|
+
type KimiProvider = {
|
|
7
|
+
chatModel(modelId: string): ChatModel;
|
|
8
|
+
};
|
|
9
|
+
declare function createKimi(options?: KimiProviderOptions): KimiProvider;
|
|
10
|
+
|
|
11
|
+
declare const DEFAULT_BASE_URL = "https://api.moonshot.ai/v1";
|
|
12
|
+
|
|
13
|
+
declare const kimiGenerateProviderOptionsSchema: z.ZodObject<{
|
|
14
|
+
user: z.ZodOptional<z.ZodString>;
|
|
15
|
+
parallelToolCalls: z.ZodOptional<z.ZodBoolean>;
|
|
16
|
+
stopSequences: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
17
|
+
seed: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
}, z.core.$strict>;
|
|
19
|
+
type KimiGenerateProviderOptions = z.infer<typeof kimiGenerateProviderOptionsSchema>;
|
|
20
|
+
declare module '@core-ai/core-ai' {
|
|
21
|
+
interface GenerateProviderOptions {
|
|
22
|
+
kimi?: KimiGenerateProviderOptions;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
type KimiReasoningMetadata = Record<string, never>;
|
|
26
|
+
|
|
27
|
+
export { DEFAULT_BASE_URL, type KimiGenerateProviderOptions, type KimiProvider, type KimiProviderOptions, type KimiReasoningMetadata, createKimi, kimiGenerateProviderOptionsSchema };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// src/provider.ts
|
|
2
|
+
import {
|
|
3
|
+
createOpenAIProvider
|
|
4
|
+
} from "@core-ai/openai";
|
|
5
|
+
|
|
6
|
+
// src/constants.ts
|
|
7
|
+
var DEFAULT_BASE_URL = "https://api.moonshot.ai/v1";
|
|
8
|
+
|
|
9
|
+
// src/model-capabilities.ts
|
|
10
|
+
import {
|
|
11
|
+
UNKNOWN_MODEL
|
|
12
|
+
} from "@core-ai/core-ai";
|
|
13
|
+
var UNKNOWN_MODEL_CAPABILITIES = {
|
|
14
|
+
reasoning: {
|
|
15
|
+
mode: "unsupported",
|
|
16
|
+
supportedEfforts: [],
|
|
17
|
+
restrictsSamplingParams: false,
|
|
18
|
+
supportedToolChoices: ["auto", "none", "required", "tool"]
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var K2_7_CODE_CAPABILITIES = {
|
|
22
|
+
reasoning: {
|
|
23
|
+
mode: "always-on",
|
|
24
|
+
supportedEfforts: [],
|
|
25
|
+
restrictsSamplingParams: true,
|
|
26
|
+
supportedToolChoices: ["auto", "none"]
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var KIMI_MODEL_CAPABILITIES = {
|
|
30
|
+
[UNKNOWN_MODEL]: UNKNOWN_MODEL_CAPABILITIES,
|
|
31
|
+
"kimi-k2.7-code": K2_7_CODE_CAPABILITIES,
|
|
32
|
+
"kimi-k2.7-code-highspeed": K2_7_CODE_CAPABILITIES
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// src/provider-options.ts
|
|
36
|
+
import { openaiChatGenerateProviderOptionsSchema } from "@core-ai/openai";
|
|
37
|
+
var kimiGenerateProviderOptionsSchema = openaiChatGenerateProviderOptionsSchema.pick({
|
|
38
|
+
parallelToolCalls: true,
|
|
39
|
+
stopSequences: true,
|
|
40
|
+
seed: true,
|
|
41
|
+
user: true
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// src/provider.ts
|
|
45
|
+
function createKimi(options = {}) {
|
|
46
|
+
if (!options.apiKey && !options.client) {
|
|
47
|
+
throw new Error("createKimi: apiKey is required.");
|
|
48
|
+
}
|
|
49
|
+
const provider = createOpenAIProvider(
|
|
50
|
+
{
|
|
51
|
+
...options,
|
|
52
|
+
baseURL: options.baseURL ?? DEFAULT_BASE_URL
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
modelCapabilities: KIMI_MODEL_CAPABILITIES,
|
|
56
|
+
providerId: "kimi",
|
|
57
|
+
providerOptionsSchema: kimiGenerateProviderOptionsSchema,
|
|
58
|
+
defaultApi: "chat-completions",
|
|
59
|
+
compatibility: {
|
|
60
|
+
reasoning: {
|
|
61
|
+
requestField: "reasoning_content"
|
|
62
|
+
},
|
|
63
|
+
structuredOutputMode: "json-object",
|
|
64
|
+
maxTokensParameter: "max_tokens"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
return {
|
|
69
|
+
chatModel: provider.chatModel
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
DEFAULT_BASE_URL,
|
|
74
|
+
createKimi,
|
|
75
|
+
kimiGenerateProviderOptionsSchema
|
|
76
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@core-ai/kimi",
|
|
3
|
+
"version": "0.16.0",
|
|
4
|
+
"description": "Kimi (Moonshot AI) provider package for @core-ai/core-ai",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Omnifact (https://omnifact.ai)",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/agdevhq/core-ai.git",
|
|
10
|
+
"directory": "packages/kimi"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"llm",
|
|
14
|
+
"ai",
|
|
15
|
+
"kimi",
|
|
16
|
+
"moonshot",
|
|
17
|
+
"provider",
|
|
18
|
+
"sdk"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"main": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"require": "./dist/index.js",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE"
|
|
35
|
+
],
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public",
|
|
38
|
+
"provenance": true
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsup",
|
|
42
|
+
"lint": "eslint src/ --max-warnings 0",
|
|
43
|
+
"check-types": "tsc --noEmit",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"test:watch": "vitest"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@core-ai/core-ai": "^0.16.0",
|
|
49
|
+
"@core-ai/openai": "^0.16.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"zod": "^4.0.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@core-ai/eslint-config": "*",
|
|
56
|
+
"@core-ai/testing": "*",
|
|
57
|
+
"@core-ai/typescript-config": "*",
|
|
58
|
+
"openai": "^6.47.0",
|
|
59
|
+
"typescript": "^5.7.3",
|
|
60
|
+
"vitest": "^3.2.4"
|
|
61
|
+
}
|
|
62
|
+
}
|