@jaybon24/plugin-moonshot 0.0.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 ADDED
@@ -0,0 +1,66 @@
1
+ # Xpert Plugin: Moonshot AI
2
+
3
+ ## Overview
4
+
5
+ `@xpert-ai/plugin-moonshot` connects [Moonshot AI (Kimi)](https://platform.moonshot.cn/) models to the [XpertAI](https://github.com/xpert-ai/xpert) platform. The plugin integrates Moonshot's OpenAI-compatible API so XpertAI agents can leverage Kimi's powerful long-context language models with context windows up to 262K tokens, including the latest K2 series with advanced reasoning capabilities.
6
+
7
+ ## Core Features
8
+
9
+ - Ships `MoonshotModule`, which registers the NestJS provider strategy, lifecycle hooks, and configuration schema required by the plugin runtime.
10
+ - Implements `MoonshotLargeLanguageModel`, a LangChain-powered adapter built on `ChatOpenAI` that supports streaming chat completions, function calling, and token accounting callbacks for agent telemetry.
11
+ - Shares a console-ready `moonshot.yaml` that drives the XpertAI UI forms (icons, help links, credential prompts) for quick operator onboarding.
12
+ - Supports multiple Moonshot model variants including:
13
+ - **Moonshot V1 Series**: `moonshot-v1-8k`, `moonshot-v1-32k`, `moonshot-v1-128k` for various context length requirements
14
+ - **Kimi K2 Series**: `kimi-k2-0711-preview`, `kimi-k2-0905-preview`, `kimi-k2-turbo-preview` for enhanced performance
15
+ - **Kimi K2.5**: `kimi-k2.5` with 262K context window, vision support, and deep thinking mode for complex reasoning tasks
16
+ - **Kimi K2 Thinking Series**: `kimi-k2-thinking`, `kimi-k2-thinking-turbo` for advanced reasoning tasks
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install @xpert-ai/plugin-moonshot
22
+ ```
23
+
24
+ > **Peer Dependencies**: Ensure your host service also provides `@xpert-ai/plugin-sdk`, `@nestjs/common`, `@nestjs/config`, `@metad/contracts`, `@langchain/openai`, `chalk`, and `zod`. Refer to `package.json` for exact versions.
25
+
26
+ ## Enabling in XpertAI
27
+
28
+ 1. Declare the plugin before bootstrapping the XpertAI server:
29
+ ```bash
30
+ PLUGINS=@xpert-ai/plugin-moonshot
31
+ ```
32
+ 2. In the XpertAI admin console (or config file), create a model provider pointing to `moonshot`, then add individual models that map to the specific Moonshot/Kimi versions you want to use.
33
+
34
+ ## Credentials & Model Configuration
35
+
36
+ The `moonshot.yaml` schema backs the form fields you see in the console:
37
+
38
+ | Field | Description |
39
+ | ---------- | -------------------------------------------------------------------------------------------------------------- |
40
+ | `api_key` | Required. Your Moonshot API Key from [platform.moonshot.cn/console/api-keys](https://platform.moonshot.cn/console/api-keys). |
41
+ | `base_url` | Optional. Base URL for API requests (defaults to `https://api.moonshot.cn/v1`). Useful for proxy configurations. |
42
+
43
+ During validation, the plugin instantiates a ChatOpenAI client with your credentials and sends a test message ("你好") to ensure connectivity and permissions.
44
+
45
+ ## Model Capabilities
46
+
47
+ - **Long Context Support**: All Moonshot models excel at handling long-context scenarios, with the V1-128K variant supporting up to 128,000 tokens and the latest K2.5 supporting up to 262,000 tokens of context.
48
+ - **Conversational Models**: `MoonshotLargeLanguageModel` merges provider credentials with per-model overrides, enables streaming, and registers token usage callbacks so agent telemetry stays accurate.
49
+ - **Advanced Reasoning**: The K2 Thinking series models provide enhanced reasoning capabilities for complex problem-solving tasks.
50
+ - **OpenAI Compatibility**: Built on LangChain's `ChatOpenAI`, ensuring seamless integration with existing OpenAI-compatible workflows.
51
+
52
+ ## Development & Debugging
53
+
54
+ From the repo root, run Nx commands for this package:
55
+
56
+ ```bash
57
+ cd xpertai
58
+ npx nx build @xpert-ai/plugin-moonshot
59
+ npx nx test @xpert-ai/plugin-moonshot
60
+ ```
61
+
62
+ Artifacts land in `xpertai/models/moonshot/dist`. Jest settings live in `jest.config.ts`, and the asset copier runs via `npm run prepack` before publishing.
63
+
64
+ ## License
65
+
66
+ This plugin is distributed under the [AGPL-3.0 License](../../../LICENSE) located at the repository root.
Binary file
Binary file
Binary file
@@ -0,0 +1,8 @@
1
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <rect width="24" height="24" rx="6" fill="#1E1E1E"/>
3
+ <path d="M12 4C11.4477 4 11 4.44772 11 5V7C11 7.55228 11.4477 8 12 8C12.5523 8 13 7.55228 13 7V5C13 4.44772 12.5523 4 12 4Z" fill="white"/>
4
+ <path d="M12 16C11.4477 16 11 16.4477 11 17V19C11 19.5523 11.4477 20 12 20C12.5523 20 13 19.5523 13 19V17C13 16.4477 12.5523 16 12 16Z" fill="white"/>
5
+ <path d="M7 12C7 11.4477 6.55228 11 6 11H4C3.44772 11 3 11.4477 3 12C3 12.5523 3.44772 13 4 13H6C6.55228 13 7 12.5523 7 12Z" fill="white"/>
6
+ <path d="M20 11C20.5523 11 21 11.4477 21 12C21 12.5523 20.5523 13 20 13H18C17.4477 13 17 12.5523 17 12C17 11.4477 17.4477 11 18 11H20Z" fill="white"/>
7
+ <circle cx="12" cy="12" r="3" fill="white"/>
8
+ </svg>
@@ -0,0 +1,4 @@
1
+ import type { XpertPlugin } from '@xpert-ai/plugin-sdk';
2
+ declare const plugin: XpertPlugin<any>;
3
+ export default plugin;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAoBxD,QAAA,MAAM,MAAM,EAAE,WAAW,CAAC,GAAG,CA2B5B,CAAC;AAEF,eAAe,MAAM,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,39 @@
1
+ import { readFileSync } from 'fs';
2
+ import { fileURLToPath } from 'url';
3
+ import { dirname, join } from 'path';
4
+ import { z } from 'zod';
5
+ import { SvgIcon } from './types.js';
6
+ import { MoonshotModule } from './moonshot.module.js';
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = dirname(__filename);
9
+ const packageJson = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf8'));
10
+ const ConfigSchema = z.object({});
11
+ const plugin = {
12
+ meta: {
13
+ name: packageJson.name,
14
+ version: packageJson.version,
15
+ category: 'model',
16
+ icon: {
17
+ type: 'svg',
18
+ value: SvgIcon,
19
+ },
20
+ displayName: 'Moonshot AI (Kimi)',
21
+ description: 'Provide Moonshot AI (Kimi) Models with Long Context Support',
22
+ keywords: ['Moonshot', 'Kimi', 'model', 'llm', 'long-context'],
23
+ author: 'XpertAI Team',
24
+ },
25
+ config: {
26
+ schema: ConfigSchema,
27
+ },
28
+ register(ctx) {
29
+ ctx.logger.log('register Moonshot plugin');
30
+ return { module: MoonshotModule, global: true };
31
+ },
32
+ async onStart(ctx) {
33
+ ctx.logger.log('Moonshot plugin started');
34
+ },
35
+ async onStop(ctx) {
36
+ ctx.logger.log('Moonshot plugin stopped');
37
+ },
38
+ };
39
+ export default plugin;
@@ -0,0 +1,9 @@
1
+ - moonshot-v1-8k
2
+ - moonshot-v1-32k
3
+ - moonshot-v1-128k
4
+ - kimi-k2-0711-preview
5
+ - kimi-k2-0905-preview
6
+ - kimi-k2-turbo-preview
7
+ - kimi-k2-thinking
8
+ - kimi-k2-thinking-turbo
9
+ - kimi-k2.5
@@ -0,0 +1,40 @@
1
+ model: kimi-k2-0711-preview
2
+ label:
3
+ zh_Hans: kimi-k2-0711-preview
4
+ en_US: kimi-k2-0711-preview
5
+ model_type: llm
6
+ features:
7
+ - agent-thought
8
+ - tool-call
9
+ - multi-tool-call
10
+ - stream-tool-call
11
+ model_properties:
12
+ mode: chat
13
+ context_size: 128000
14
+ parameter_rules:
15
+ - name: temperature
16
+ use_template: temperature
17
+ - name: top_p
18
+ use_template: top_p
19
+ - name: max_tokens
20
+ use_template: max_tokens
21
+ default: 1024
22
+ min: 1
23
+ max: 128000
24
+ - name: response_format
25
+ label:
26
+ zh_Hans: 回复格式
27
+ en_US: Response Format
28
+ type: string
29
+ help:
30
+ zh_Hans: 指定模型必须输出的格式
31
+ en_US: specifying the format that the model must output
32
+ required: false
33
+ options:
34
+ - text
35
+ - json_object
36
+ pricing:
37
+ input: '0.2'
38
+ output: '0.2'
39
+ unit: '0.001'
40
+ currency: RMB
@@ -0,0 +1,40 @@
1
+ model: kimi-k2-0905-preview
2
+ label:
3
+ zh_Hans: kimi-k2-0905-preview
4
+ en_US: kimi-k2-0905-preview
5
+ model_type: llm
6
+ features:
7
+ - agent-thought
8
+ - tool-call
9
+ - multi-tool-call
10
+ - stream-tool-call
11
+ model_properties:
12
+ mode: chat
13
+ context_size: 256000
14
+ parameter_rules:
15
+ - name: temperature
16
+ use_template: temperature
17
+ - name: top_p
18
+ use_template: top_p
19
+ - name: max_tokens
20
+ use_template: max_tokens
21
+ default: 1024
22
+ min: 1
23
+ max: 256000
24
+ - name: response_format
25
+ label:
26
+ zh_Hans: 回复格式
27
+ en_US: Response Format
28
+ type: string
29
+ help:
30
+ zh_Hans: 指定模型必须输出的格式
31
+ en_US: specifying the format that the model must output
32
+ required: false
33
+ options:
34
+ - text
35
+ - json_object
36
+ pricing:
37
+ input: '0.2'
38
+ output: '0.2'
39
+ unit: '0.001'
40
+ currency: RMB
@@ -0,0 +1,40 @@
1
+ model: kimi-k2-thinking-turbo
2
+ label:
3
+ zh_Hans: kimi-k2-thinking-turbo
4
+ en_US: kimi-k2-thinking-turbo
5
+ model_type: llm
6
+ features:
7
+ - agent-thought
8
+ - tool-call
9
+ - multi-tool-call
10
+ - stream-tool-call
11
+ model_properties:
12
+ mode: chat
13
+ context_size: 262144
14
+ parameter_rules:
15
+ - name: temperature
16
+ use_template: temperature
17
+ - name: top_p
18
+ use_template: top_p
19
+ - name: max_tokens
20
+ use_template: max_tokens
21
+ default: 1024
22
+ min: 1
23
+ max: 262144
24
+ - name: response_format
25
+ label:
26
+ zh_Hans: 回复格式
27
+ en_US: Response Format
28
+ type: string
29
+ help:
30
+ zh_Hans: 指定模型必须输出的格式
31
+ en_US: specifying the format that the model must output
32
+ required: false
33
+ options:
34
+ - text
35
+ - json_object
36
+ pricing:
37
+ input: '8'
38
+ output: '58'
39
+ unit: '0.000001'
40
+ currency: RMB
@@ -0,0 +1,40 @@
1
+ model: kimi-k2-thinking
2
+ label:
3
+ zh_Hans: kimi-k2-thinking
4
+ en_US: kimi-k2-thinking
5
+ model_type: llm
6
+ features:
7
+ - agent-thought
8
+ - tool-call
9
+ - multi-tool-call
10
+ - stream-tool-call
11
+ model_properties:
12
+ mode: chat
13
+ context_size: 262144
14
+ parameter_rules:
15
+ - name: temperature
16
+ use_template: temperature
17
+ - name: top_p
18
+ use_template: top_p
19
+ - name: max_tokens
20
+ use_template: max_tokens
21
+ default: 1024
22
+ min: 1
23
+ max: 262144
24
+ - name: response_format
25
+ label:
26
+ zh_Hans: 回复格式
27
+ en_US: Response Format
28
+ type: string
29
+ help:
30
+ zh_Hans: 指定模型必须输出的格式
31
+ en_US: specifying the format that the model must output
32
+ required: false
33
+ options:
34
+ - text
35
+ - json_object
36
+ pricing:
37
+ input: '4'
38
+ output: '16'
39
+ unit: '0.000001'
40
+ currency: RMB
@@ -0,0 +1,40 @@
1
+ model: kimi-k2-turbo-preview
2
+ label:
3
+ zh_Hans: kimi-k2-turbo-preview
4
+ en_US: kimi-k2-turbo-preview
5
+ model_type: llm
6
+ features:
7
+ - agent-thought
8
+ - tool-call
9
+ - multi-tool-call
10
+ - stream-tool-call
11
+ model_properties:
12
+ mode: chat
13
+ context_size: 256000
14
+ parameter_rules:
15
+ - name: temperature
16
+ use_template: temperature
17
+ - name: top_p
18
+ use_template: top_p
19
+ - name: max_tokens
20
+ use_template: max_tokens
21
+ default: 1024
22
+ min: 1
23
+ max: 256000
24
+ - name: response_format
25
+ label:
26
+ zh_Hans: 回复格式
27
+ en_US: Response Format
28
+ type: string
29
+ help:
30
+ zh_Hans: 指定模型必须输出的格式
31
+ en_US: specifying the format that the model must output
32
+ required: false
33
+ options:
34
+ - text
35
+ - json_object
36
+ pricing:
37
+ input: '0.2'
38
+ output: '0.2'
39
+ unit: '0.001'
40
+ currency: RMB
@@ -0,0 +1,61 @@
1
+ model: kimi-k2.5
2
+ label:
3
+ zh_Hans: kimi-k2.5
4
+ en_US: kimi-k2.5
5
+ model_type: llm
6
+ features:
7
+ - vision
8
+ - agent-thought
9
+ - tool-call
10
+ - multi-tool-call
11
+ - stream-tool-call
12
+ model_properties:
13
+ mode: chat
14
+ context_size: 262144
15
+ parameter_rules:
16
+ - name: temperature
17
+ use_template: temperature
18
+ default: 1.0
19
+ help:
20
+ zh_Hans: 采样温度。思考模式下建议使用 1.0,非思考模式下建议使用 0.6。
21
+ en_US: Sampling temperature. Recommended 1.0 for thinking mode, 0.6 for instant mode.
22
+ - name: top_p
23
+ use_template: top_p
24
+ default: 0.95
25
+ help:
26
+ zh_Hans: 核采样参数。思考模式下建议使用 0.95。
27
+ en_US: Nucleus sampling parameter. Recommended 0.95 for thinking mode.
28
+ - name: max_tokens
29
+ use_template: max_tokens
30
+ default: 1024
31
+ min: 1
32
+ max: 262144
33
+ - name: thinking
34
+ label:
35
+ zh_Hans: 深度思考
36
+ en_US: Thinking Mode
37
+ type: boolean
38
+ default: true
39
+ required: false
40
+ help:
41
+ zh_Hans: 启用深度思考模式,使模型具备强大的推理能力,适合解决复杂的逻辑推理、数学问题和代码编写等任务。
42
+ en_US: Enable thinking mode for enhanced reasoning capabilities, suitable for complex logical reasoning, math problems, and coding tasks.
43
+ - name: response_format
44
+ label:
45
+ zh_Hans: 回复格式
46
+ en_US: Response Format
47
+ type: string
48
+ help:
49
+ zh_Hans: 指定模型必须输出的格式
50
+ en_US: specifying the format that the model must output
51
+ required: false
52
+ options:
53
+ - text
54
+ - json_object
55
+ pricing:
56
+ input: '4'
57
+ output: '21'
58
+ unit: '0.000001'
59
+ currency: RMB
60
+
61
+
@@ -0,0 +1,12 @@
1
+ import { ChatOpenAI } from '@langchain/openai';
2
+ import { ICopilotModel } from '@metad/contracts';
3
+ import { LargeLanguageModel, TChatModelOptions } from '@xpert-ai/plugin-sdk';
4
+ import { MoonshotProviderStrategy } from '../provider.strategy.js';
5
+ import { MoonshotModelCredentials } from '../types.js';
6
+ export declare class MoonshotLargeLanguageModel extends LargeLanguageModel {
7
+ #private;
8
+ constructor(modelProvider: MoonshotProviderStrategy);
9
+ validateCredentials(model: string, credentials: MoonshotModelCredentials): Promise<void>;
10
+ getChatModel(copilotModel: ICopilotModel, options?: TChatModelOptions): ChatOpenAI<import("@langchain/openai").ChatOpenAICallOptions>;
11
+ }
12
+ //# sourceMappingURL=llm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../../src/llm/llm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAmB,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAElE,OAAO,EAGL,kBAAkB,EAElB,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,wBAAwB,EAAsB,MAAM,aAAa,CAAC;AAE3E,qBACa,0BAA2B,SAAQ,kBAAkB;;gBAGpD,aAAa,EAAE,wBAAwB;IAI7C,mBAAmB,CACvB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,wBAAwB,GACpC,OAAO,CAAC,IAAI,CAAC;IAoBP,YAAY,CACnB,YAAY,EAAE,aAAa,EAC3B,OAAO,CAAC,EAAE,iBAAiB;CAgC9B"}
@@ -0,0 +1,60 @@
1
+ var _a;
2
+ var MoonshotLargeLanguageModel_1;
3
+ import { __decorate, __metadata } from "tslib";
4
+ import { ChatOpenAI } from '@langchain/openai';
5
+ import { AiModelTypeEnum } from '@metad/contracts';
6
+ import { Injectable, Logger } from '@nestjs/common';
7
+ import { CredentialsValidateFailedError, getErrorMessage, LargeLanguageModel, mergeCredentials, } from '@xpert-ai/plugin-sdk';
8
+ import { MoonshotProviderStrategy } from '../provider.strategy.js';
9
+ import { toCredentialKwargs } from '../types.js';
10
+ let MoonshotLargeLanguageModel = MoonshotLargeLanguageModel_1 = class MoonshotLargeLanguageModel extends LargeLanguageModel {
11
+ #logger = new Logger(MoonshotLargeLanguageModel_1.name);
12
+ constructor(modelProvider) {
13
+ super(modelProvider, AiModelTypeEnum.LLM);
14
+ }
15
+ async validateCredentials(model, credentials) {
16
+ try {
17
+ const params = toCredentialKwargs(credentials, model);
18
+ const chatModel = new ChatOpenAI({
19
+ ...params,
20
+ temperature: 0,
21
+ maxTokens: 10,
22
+ });
23
+ await chatModel.invoke([
24
+ {
25
+ role: 'human',
26
+ content: '你好',
27
+ },
28
+ ]);
29
+ }
30
+ catch (err) {
31
+ this.#logger.error('Moonshot credentials validation failed', err);
32
+ throw new CredentialsValidateFailedError(getErrorMessage(err));
33
+ }
34
+ }
35
+ getChatModel(copilotModel, options) {
36
+ const { handleLLMTokens } = options ?? {};
37
+ const { copilot } = copilotModel;
38
+ const { modelProvider } = copilot;
39
+ const modelCredentials = mergeCredentials(modelProvider.credentials, options?.modelProperties);
40
+ const params = toCredentialKwargs(modelCredentials, copilotModel.model);
41
+ const fields = {
42
+ ...params,
43
+ streaming: copilotModel.options?.['streaming'] ?? true,
44
+ streamUsage: false,
45
+ verbose: options?.verbose,
46
+ };
47
+ return new ChatOpenAI({
48
+ ...fields,
49
+ callbacks: [
50
+ ...this.createHandleUsageCallbacks(copilot, params.model, modelCredentials, handleLLMTokens),
51
+ this.createHandleLLMErrorCallbacks(fields, this.#logger),
52
+ ],
53
+ });
54
+ }
55
+ };
56
+ MoonshotLargeLanguageModel = MoonshotLargeLanguageModel_1 = __decorate([
57
+ Injectable(),
58
+ __metadata("design:paramtypes", [MoonshotProviderStrategy])
59
+ ], MoonshotLargeLanguageModel);
60
+ export { MoonshotLargeLanguageModel };
@@ -0,0 +1,58 @@
1
+ model: moonshot-v1-128k
2
+ label:
3
+ en_US: Moonshot v1 128K
4
+ zh_Hans: 月之暗面 v1 128K
5
+ model_type: llm
6
+ features:
7
+ - tool-call
8
+ - multi-tool-call
9
+ - stream-tool-call
10
+ model_properties:
11
+ mode: chat
12
+ context_size: 131072
13
+ parameter_rules:
14
+ - name: temperature
15
+ use_template: temperature
16
+ default: 0.3
17
+ min: 0
18
+ max: 1
19
+ - name: top_p
20
+ use_template: top_p
21
+ default: 1
22
+ min: 0
23
+ max: 1
24
+ - name: max_tokens
25
+ use_template: max_tokens
26
+ default: 4096
27
+ min: 1
28
+ max: 16384
29
+ - name: frequency_penalty
30
+ type: float
31
+ default: 0
32
+ min: 0
33
+ max: 2
34
+ label:
35
+ en_US: Frequency Penalty
36
+ zh_Hans: 频率惩罚
37
+ help:
38
+ en_US: Penalize new tokens based on their frequency in the text so far
39
+ zh_Hans: 根据新 token 在文本中的现有频率对其进行惩罚
40
+ required: false
41
+ - name: presence_penalty
42
+ type: float
43
+ default: 0
44
+ min: 0
45
+ max: 2
46
+ label:
47
+ en_US: Presence Penalty
48
+ zh_Hans: 存在惩罚
49
+ help:
50
+ en_US: Penalize new tokens based on whether they appear in the text so far
51
+ zh_Hans: 根据新 token 是否出现在文本中来对其进行惩罚
52
+ required: false
53
+ pricing:
54
+ input: '5.06'
55
+ output: '5.06'
56
+ unit: '0.000001'
57
+ currency: CNY
58
+
@@ -0,0 +1,58 @@
1
+ model: moonshot-v1-32k
2
+ label:
3
+ en_US: Moonshot v1 32K
4
+ zh_Hans: 月之暗面 v1 32K
5
+ model_type: llm
6
+ features:
7
+ - tool-call
8
+ - multi-tool-call
9
+ - stream-tool-call
10
+ model_properties:
11
+ mode: chat
12
+ context_size: 32768
13
+ parameter_rules:
14
+ - name: temperature
15
+ use_template: temperature
16
+ default: 0.3
17
+ min: 0
18
+ max: 1
19
+ - name: top_p
20
+ use_template: top_p
21
+ default: 1
22
+ min: 0
23
+ max: 1
24
+ - name: max_tokens
25
+ use_template: max_tokens
26
+ default: 2048
27
+ min: 1
28
+ max: 32768
29
+ - name: frequency_penalty
30
+ type: float
31
+ default: 0
32
+ min: 0
33
+ max: 2
34
+ label:
35
+ en_US: Frequency Penalty
36
+ zh_Hans: 频率惩罚
37
+ help:
38
+ en_US: Penalize new tokens based on their frequency in the text so far
39
+ zh_Hans: 根据新 token 在文本中的现有频率对其进行惩罚
40
+ required: false
41
+ - name: presence_penalty
42
+ type: float
43
+ default: 0
44
+ min: 0
45
+ max: 2
46
+ label:
47
+ en_US: Presence Penalty
48
+ zh_Hans: 存在惩罚
49
+ help:
50
+ en_US: Penalize new tokens based on whether they appear in the text so far
51
+ zh_Hans: 根据新 token 是否出现在文本中来对其进行惩罚
52
+ required: false
53
+ pricing:
54
+ input: '24.00'
55
+ output: '24.00'
56
+ unit: '0.000001'
57
+ currency: CNY
58
+
@@ -0,0 +1,58 @@
1
+ model: moonshot-v1-8k
2
+ label:
3
+ en_US: Moonshot v1 8K
4
+ zh_Hans: 月之暗面 v1 8K
5
+ model_type: llm
6
+ features:
7
+ - tool-call
8
+ - multi-tool-call
9
+ - stream-tool-call
10
+ model_properties:
11
+ mode: chat
12
+ context_size: 8192
13
+ parameter_rules:
14
+ - name: temperature
15
+ use_template: temperature
16
+ default: 0.3
17
+ min: 0
18
+ max: 1
19
+ - name: top_p
20
+ use_template: top_p
21
+ default: 1
22
+ min: 0
23
+ max: 1
24
+ - name: max_tokens
25
+ use_template: max_tokens
26
+ default: 1024
27
+ min: 1
28
+ max: 8192
29
+ - name: frequency_penalty
30
+ type: float
31
+ default: 0
32
+ min: 0
33
+ max: 2
34
+ label:
35
+ en_US: Frequency Penalty
36
+ zh_Hans: 频率惩罚
37
+ help:
38
+ en_US: Penalize new tokens based on their frequency in the text so far
39
+ zh_Hans: 根据新 token 在文本中的现有频率对其进行惩罚
40
+ required: false
41
+ - name: presence_penalty
42
+ type: float
43
+ default: 0
44
+ min: 0
45
+ max: 2
46
+ label:
47
+ en_US: Presence Penalty
48
+ zh_Hans: 存在惩罚
49
+ help:
50
+ en_US: Penalize new tokens based on whether they appear in the text so far
51
+ zh_Hans: 根据新 token 是否出现在文本中来对其进行惩罚
52
+ required: false
53
+ pricing:
54
+ input: '12.00'
55
+ output: '12.00'
56
+ unit: '0.000001'
57
+ currency: CNY
58
+
@@ -0,0 +1,13 @@
1
+ import { IOnPluginBootstrap, IOnPluginDestroy } from '@xpert-ai/plugin-sdk';
2
+ export declare class MoonshotModule implements IOnPluginBootstrap, IOnPluginDestroy {
3
+ private logEnabled;
4
+ /**
5
+ * Called when the plugin is being initialized.
6
+ */
7
+ onPluginBootstrap(): void | Promise<void>;
8
+ /**
9
+ * Called when the plugin is being destroyed.
10
+ */
11
+ onPluginDestroy(): void | Promise<void>;
12
+ }
13
+ //# sourceMappingURL=moonshot.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"moonshot.module.d.ts","sourceRoot":"","sources":["../src/moonshot.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,sBAAsB,CAAC;AAM9B,qBAQa,cAAe,YAAW,kBAAkB,EAAE,gBAAgB;IAEzE,OAAO,CAAC,UAAU,CAAQ;IAE1B;;OAEG;IACH,iBAAiB,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAMzC;;OAEG;IACH,eAAe,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CAKxC"}
@@ -0,0 +1,39 @@
1
+ var MoonshotModule_1;
2
+ import { __decorate } from "tslib";
3
+ import { XpertServerPlugin, } from '@xpert-ai/plugin-sdk';
4
+ import { ConfigModule } from '@nestjs/config';
5
+ import chalk from 'chalk';
6
+ import { MoonshotProviderStrategy } from './provider.strategy.js';
7
+ import { MoonshotLargeLanguageModel } from './llm/llm.js';
8
+ let MoonshotModule = MoonshotModule_1 = class MoonshotModule {
9
+ constructor() {
10
+ // We disable by default additional logging for each event to avoid cluttering the logs
11
+ this.logEnabled = true;
12
+ }
13
+ /**
14
+ * Called when the plugin is being initialized.
15
+ */
16
+ onPluginBootstrap() {
17
+ if (this.logEnabled) {
18
+ console.log(chalk.green(`${MoonshotModule_1.name} is being bootstrapped...`));
19
+ }
20
+ }
21
+ /**
22
+ * Called when the plugin is being destroyed.
23
+ */
24
+ onPluginDestroy() {
25
+ if (this.logEnabled) {
26
+ console.log(chalk.green(`${MoonshotModule_1.name} is being destroyed...`));
27
+ }
28
+ }
29
+ };
30
+ MoonshotModule = MoonshotModule_1 = __decorate([
31
+ XpertServerPlugin({
32
+ /**
33
+ * An array of modules that will be imported and registered with the plugin.
34
+ */
35
+ imports: [ConfigModule],
36
+ providers: [MoonshotProviderStrategy, MoonshotLargeLanguageModel],
37
+ })
38
+ ], MoonshotModule);
39
+ export { MoonshotModule };
@@ -0,0 +1,94 @@
1
+ background: '#FFFFFF'
2
+ configurate_methods:
3
+ - predefined-model
4
+ - customizable-model
5
+ description:
6
+ en_US: Models provided by Moonshot, such as kimi-k2.5, kimi-k2, moonshot-v1-8k, moonshot-v1-32k, and moonshot-v1-128k.
7
+ zh_Hans: Moonshot 提供的模型,例如 kimi-k2.5, kimi-k2, moonshot-v1-8k、moonshot-v1-32k 和 moonshot-v1-128k。
8
+ help:
9
+ title:
10
+ en_US: Get your API Key from Moonshot
11
+ zh_Hans: 从 Moonshot 获取 API Key
12
+ url:
13
+ en_US: https://platform.moonshot.cn/console/api-keys
14
+ icon_large:
15
+ en_US: icon_l_en.png
16
+ icon_small:
17
+ en_US: icon_k2_s_en.png
18
+ label:
19
+ en_US: Moonshot
20
+ zh_Hans: 月之暗面
21
+ model_credential_schema:
22
+ credential_form_schemas:
23
+ - label:
24
+ en_US: API Key
25
+ placeholder:
26
+ en_US: Enter your API Key
27
+ zh_Hans: 在此输入您的 API Key
28
+ required: true
29
+ type: secret-input
30
+ variable: api_key
31
+ - default: '4096'
32
+ label:
33
+ en_US: Model context size
34
+ zh_Hans: 模型上下文长度
35
+ placeholder:
36
+ en_US: Enter your Model context size
37
+ zh_Hans: 在此输入您的模型上下文长度
38
+ required: true
39
+ type: text-input
40
+ variable: context_size
41
+ - default: '4096'
42
+ label:
43
+ en_US: Upper bound for max tokens
44
+ zh_Hans: 最大 token 上限
45
+ type: text-input
46
+ variable: max_tokens
47
+ - default: no_call
48
+ label:
49
+ en_US: Function calling
50
+ options:
51
+ - label:
52
+ en_US: Not supported
53
+ zh_Hans: 不支持
54
+ value: no_call
55
+ - label:
56
+ en_US: Tool Call
57
+ zh_Hans: Tool Call
58
+ value: tool_call
59
+ required: false
60
+ type: select
61
+ variable: function_calling_type
62
+ model:
63
+ label:
64
+ en_US: Model Name
65
+ zh_Hans: 模型名称
66
+ placeholder:
67
+ en_US: Enter your model name
68
+ zh_Hans: 输入模型名称
69
+ models:
70
+ llm:
71
+ position: models/llm/_position.yaml
72
+ predefined:
73
+ - models/llm/*.yaml
74
+ provider: moonshot
75
+ provider_credential_schema:
76
+ credential_form_schemas:
77
+ - label:
78
+ en_US: API Key
79
+ placeholder:
80
+ en_US: Enter your API Key
81
+ zh_Hans: 在此输入您的 API Key
82
+ required: true
83
+ type: secret-input
84
+ variable: api_key
85
+ - label:
86
+ en_US: API Base
87
+ placeholder:
88
+ en_US: Base URL, e.g. https://api.moonshot.cn/v1
89
+ zh_Hans: Base URL, 如:https://api.moonshot.cn/v1
90
+ required: false
91
+ type: text-input
92
+ variable: endpoint_url
93
+ supported_model_types:
94
+ - llm
@@ -0,0 +1,10 @@
1
+ import { Logger } from '@nestjs/common';
2
+ import { ModelProvider } from '@xpert-ai/plugin-sdk';
3
+ import { MoonshotCredentials } from './types.js';
4
+ export declare class MoonshotProviderStrategy extends ModelProvider {
5
+ logger: Logger;
6
+ getBaseUrl(credentials: MoonshotCredentials): string;
7
+ getAuthorization(credentials: MoonshotCredentials): string;
8
+ validateProviderCredentials(credentials: MoonshotCredentials): Promise<void>;
9
+ }
10
+ //# sourceMappingURL=provider.strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.strategy.d.ts","sourceRoot":"","sources":["../src/provider.strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAGL,aAAa,EACd,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAGL,mBAAmB,EAEpB,MAAM,YAAY,CAAC;AAEpB,qBAEa,wBAAyB,SAAQ,aAAa;IAChD,MAAM,SAA6C;IAE5D,UAAU,CAAC,WAAW,EAAE,mBAAmB,GAAG,MAAM;IAIpD,gBAAgB,CAAC,WAAW,EAAE,mBAAmB,GAAG,MAAM;IAIpD,2BAA2B,CAC/B,WAAW,EAAE,mBAAmB,GAC/B,OAAO,CAAC,IAAI,CAAC;CA2BjB"}
@@ -0,0 +1,43 @@
1
+ var MoonshotProviderStrategy_1;
2
+ import { __decorate } from "tslib";
3
+ import { Injectable, Logger } from '@nestjs/common';
4
+ import { AIModelProviderStrategy, CredentialsValidateFailedError, ModelProvider, } from '@xpert-ai/plugin-sdk';
5
+ import { AiModelTypeEnum } from '@metad/contracts';
6
+ import { Moonshot, MoonshotBaseUrl, } from './types.js';
7
+ let MoonshotProviderStrategy = MoonshotProviderStrategy_1 = class MoonshotProviderStrategy extends ModelProvider {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.logger = new Logger(MoonshotProviderStrategy_1.name);
11
+ }
12
+ getBaseUrl(credentials) {
13
+ return credentials.base_url || MoonshotBaseUrl;
14
+ }
15
+ getAuthorization(credentials) {
16
+ return `Bearer ${credentials.api_key}`;
17
+ }
18
+ async validateProviderCredentials(credentials) {
19
+ try {
20
+ const modelInstance = this.getModelManager(AiModelTypeEnum.LLM);
21
+ // Use moonshot-v1-8k for validation (most cost-effective)
22
+ await modelInstance.validateCredentials('moonshot-v1-8k', credentials);
23
+ }
24
+ catch (ex) {
25
+ if (ex instanceof CredentialsValidateFailedError) {
26
+ throw ex;
27
+ }
28
+ else if (ex instanceof Error) {
29
+ this.logger.error(`${this.getProviderSchema().provider}: credentials verification failed`, ex.stack);
30
+ throw ex;
31
+ }
32
+ else {
33
+ this.logger.error(`${this.getProviderSchema().provider}: credentials verification failed`, ex);
34
+ throw ex;
35
+ }
36
+ }
37
+ }
38
+ };
39
+ MoonshotProviderStrategy = MoonshotProviderStrategy_1 = __decorate([
40
+ Injectable(),
41
+ AIModelProviderStrategy(Moonshot)
42
+ ], MoonshotProviderStrategy);
43
+ export { MoonshotProviderStrategy };
@@ -0,0 +1,39 @@
1
+ import { ClientOptions } from '@langchain/openai';
2
+ export declare const Moonshot = "moonshot";
3
+ export declare const MoonshotBaseUrl = "https://api.moonshot.cn/v1";
4
+ export declare const SvgIcon: string;
5
+ export type MoonshotCredentials = {
6
+ api_key: string;
7
+ base_url?: string;
8
+ };
9
+ export type MoonshotModelCredentials = MoonshotCredentials & {
10
+ temperature?: number;
11
+ max_tokens?: number;
12
+ top_p?: number;
13
+ frequency_penalty?: number;
14
+ presence_penalty?: number;
15
+ };
16
+ export declare function toCredentialKwargs(credentials: MoonshotCredentials, model?: string): {
17
+ configuration: ClientOptions;
18
+ temperature: number;
19
+ maxTokens?: number;
20
+ maxCompletionTokens?: number;
21
+ topP: number;
22
+ frequencyPenalty: number;
23
+ presencePenalty: number;
24
+ n: number;
25
+ logitBias?: Record<string, number>;
26
+ user?: string;
27
+ streaming: boolean;
28
+ streamUsage?: boolean;
29
+ modelName: string;
30
+ model: import("@langchain/openai").OpenAIChatModelId;
31
+ modelKwargs?: Record<string, any>;
32
+ stop?: string[];
33
+ stopSequences?: string[];
34
+ timeout?: number;
35
+ openAIApiKey?: string;
36
+ apiKey?: string;
37
+ verbosity?: import("@langchain/openai").OpenAIVerbosityParam;
38
+ };
39
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAmB,MAAM,mBAAmB,CAAC;AAQnE,eAAO,MAAM,QAAQ,aAAa,CAAC;AACnC,eAAO,MAAM,eAAe,+BAA+B,CAAC;AAE5D,eAAO,MAAM,OAAO,QAAiE,CAAC;AAEtF,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,mBAAmB,GAAG;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,mBAAmB,EAChC,KAAK,CAAC,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;EAcf"}
package/dist/types.js ADDED
@@ -0,0 +1,21 @@
1
+ import { readFileSync } from 'fs';
2
+ import { fileURLToPath } from 'url';
3
+ import { dirname, join } from 'path';
4
+ const __filename = fileURLToPath(import.meta.url);
5
+ const __dirname = dirname(__filename);
6
+ export const Moonshot = 'moonshot';
7
+ export const MoonshotBaseUrl = 'https://api.moonshot.cn/v1';
8
+ export const SvgIcon = readFileSync(join(__dirname, '_assets/icon_s_en.svg'), 'utf8');
9
+ export function toCredentialKwargs(credentials, model) {
10
+ const credentialsKwargs = {
11
+ apiKey: credentials.api_key,
12
+ model: model,
13
+ };
14
+ const configuration = {
15
+ baseURL: credentials.base_url || MoonshotBaseUrl,
16
+ };
17
+ return {
18
+ ...credentialsKwargs,
19
+ configuration,
20
+ };
21
+ }
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@jaybon24/plugin-moonshot",
3
+ "version": "0.0.1",
4
+ "author": {
5
+ "name": "XpertAI",
6
+ "url": "https://xpertai.cn"
7
+ },
8
+ "license": "AGPL-3.0",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/xpert-ai/xpert-plugins.git"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/xpert-ai/xpert-plugins/issues"
15
+ },
16
+ "type": "module",
17
+ "main": "./dist/index.js",
18
+ "module": "./dist/index.js",
19
+ "types": "./dist/index.d.ts",
20
+ "exports": {
21
+ "./package.json": "./package.json",
22
+ ".": {
23
+ "@xpert-plugins-starter/source": "./src/index.ts",
24
+ "types": "./dist/index.d.ts",
25
+ "import": "./dist/index.js",
26
+ "default": "./dist/index.js"
27
+ }
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "!**/*.tsbuildinfo"
32
+ ],
33
+ "scripts": {
34
+ "prepack": "node ./scripts/copy-assets.mjs"
35
+ },
36
+ "dependencies": {
37
+ "tslib": "^2.3.0"
38
+ },
39
+ "peerDependencies": {
40
+ "@langchain/openai": "0.6.9",
41
+ "@metad/contracts": "^3.6.1",
42
+ "@nestjs/common": "^11.1.6",
43
+ "@nestjs/config": "^4.0.2",
44
+ "@xpert-ai/plugin-sdk": "^3.6.1",
45
+ "chalk": "4.1.2",
46
+ "zod": "3.25.67"
47
+ }
48
+ }