@prismshadow/mmsp 0.5.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 +121 -0
- package/dist/ant_messages/client.d.ts +59 -0
- package/dist/ant_messages/client.d.ts.map +1 -0
- package/dist/ant_messages/client.js +419 -0
- package/dist/ant_messages/index.d.ts +2 -0
- package/dist/ant_messages/index.d.ts.map +1 -0
- package/dist/ant_messages/index.js +18 -0
- package/dist/anthropic_official/client.d.ts +63 -0
- package/dist/anthropic_official/client.d.ts.map +1 -0
- package/dist/anthropic_official/client.js +540 -0
- package/dist/anthropic_official/index.d.ts +2 -0
- package/dist/anthropic_official/index.d.ts.map +1 -0
- package/dist/anthropic_official/index.js +18 -0
- package/dist/autoClient.d.ts +96 -0
- package/dist/autoClient.d.ts.map +1 -0
- package/dist/autoClient.js +258 -0
- package/dist/baseClient.d.ts +111 -0
- package/dist/baseClient.d.ts.map +1 -0
- package/dist/baseClient.js +284 -0
- package/dist/deepseek_official/client.d.ts +60 -0
- package/dist/deepseek_official/client.d.ts.map +1 -0
- package/dist/deepseek_official/client.js +407 -0
- package/dist/deepseek_official/index.d.ts +2 -0
- package/dist/deepseek_official/index.d.ts.map +1 -0
- package/dist/deepseek_official/index.js +18 -0
- package/dist/errors.d.ts +84 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +140 -0
- package/dist/gemini_generate_content/client.d.ts +86 -0
- package/dist/gemini_generate_content/client.d.ts.map +1 -0
- package/dist/gemini_generate_content/client.js +809 -0
- package/dist/gemini_generate_content/index.d.ts +2 -0
- package/dist/gemini_generate_content/index.d.ts.map +1 -0
- package/dist/gemini_generate_content/index.js +18 -0
- package/dist/gemini_official/client.d.ts +87 -0
- package/dist/gemini_official/client.d.ts.map +1 -0
- package/dist/gemini_official/client.js +780 -0
- package/dist/gemini_official/index.d.ts +2 -0
- package/dist/gemini_official/index.d.ts.map +1 -0
- package/dist/gemini_official/index.js +18 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +44 -0
- package/dist/integration/index.d.ts +1 -0
- package/dist/integration/index.d.ts.map +1 -0
- package/dist/integration/index.js +14 -0
- package/dist/integration/playground.d.ts +17 -0
- package/dist/integration/playground.d.ts.map +1 -0
- package/dist/integration/playground.js +3246 -0
- package/dist/integration/tracer.d.ts +188 -0
- package/dist/integration/tracer.d.ts.map +1 -0
- package/dist/integration/tracer.js +1928 -0
- package/dist/legacy.d.ts +13 -0
- package/dist/legacy.d.ts.map +1 -0
- package/dist/legacy.js +59 -0
- package/dist/minimax_official/client.d.ts +43 -0
- package/dist/minimax_official/client.d.ts.map +1 -0
- package/dist/minimax_official/client.js +346 -0
- package/dist/minimax_official/index.d.ts +2 -0
- package/dist/minimax_official/index.d.ts.map +1 -0
- package/dist/minimax_official/index.js +18 -0
- package/dist/moonshot_official/client.d.ts +73 -0
- package/dist/moonshot_official/client.d.ts.map +1 -0
- package/dist/moonshot_official/client.js +477 -0
- package/dist/moonshot_official/index.d.ts +2 -0
- package/dist/moonshot_official/index.d.ts.map +1 -0
- package/dist/moonshot_official/index.js +18 -0
- package/dist/openai_chat/client.d.ts +67 -0
- package/dist/openai_chat/client.d.ts.map +1 -0
- package/dist/openai_chat/client.js +419 -0
- package/dist/openai_chat/index.d.ts +2 -0
- package/dist/openai_chat/index.d.ts.map +1 -0
- package/dist/openai_chat/index.js +18 -0
- package/dist/openai_chat_vllm_adapter/client.d.ts +15 -0
- package/dist/openai_chat_vllm_adapter/client.d.ts.map +1 -0
- package/dist/openai_chat_vllm_adapter/client.js +118 -0
- package/dist/openai_chat_vllm_adapter/index.d.ts +2 -0
- package/dist/openai_chat_vllm_adapter/index.d.ts.map +1 -0
- package/dist/openai_chat_vllm_adapter/index.js +5 -0
- package/dist/openai_embedding/client.d.ts +46 -0
- package/dist/openai_embedding/client.d.ts.map +1 -0
- package/dist/openai_embedding/client.js +124 -0
- package/dist/openai_embedding/index.d.ts +2 -0
- package/dist/openai_embedding/index.d.ts.map +1 -0
- package/dist/openai_embedding/index.js +18 -0
- package/dist/openai_official/client.d.ts +61 -0
- package/dist/openai_official/client.d.ts.map +1 -0
- package/dist/openai_official/client.js +464 -0
- package/dist/openai_official/index.d.ts +2 -0
- package/dist/openai_official/index.d.ts.map +1 -0
- package/dist/openai_official/index.js +18 -0
- package/dist/openai_responses/client.d.ts +61 -0
- package/dist/openai_responses/client.d.ts.map +1 -0
- package/dist/openai_responses/client.js +449 -0
- package/dist/openai_responses/index.d.ts +2 -0
- package/dist/openai_responses/index.d.ts.map +1 -0
- package/dist/openai_responses/index.js +18 -0
- package/dist/registry.d.ts +49 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +798 -0
- package/dist/streamItems.d.ts +36 -0
- package/dist/streamItems.d.ts.map +1 -0
- package/dist/streamItems.js +183 -0
- package/dist/types.d.ts +190 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +37 -0
- package/dist/utils.d.ts +99 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +312 -0
- package/dist/zai_official/client.d.ts +78 -0
- package/dist/zai_official/client.d.ts.map +1 -0
- package/dist/zai_official/client.js +420 -0
- package/dist/zai_official/index.d.ts +2 -0
- package/dist/zai_official/index.d.ts.map +1 -0
- package/dist/zai_official/index.js +18 -0
- package/package.json +68 -0
package/dist/legacy.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { UniMessage } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Convert messages recorded before 0.5.0 to the current content item types.
|
|
4
|
+
*
|
|
5
|
+
* A legacy item type such as `text` becomes `text.done`, and a stray `partial_tool_call`
|
|
6
|
+
* is dropped. Messages already in the current format are returned as they are; a message
|
|
7
|
+
* that needed converting is returned as a copy, so the caller's data is never modified.
|
|
8
|
+
*
|
|
9
|
+
* @param messages - Messages that may carry legacy content item types
|
|
10
|
+
* @returns The messages with current content item types only
|
|
11
|
+
*/
|
|
12
|
+
export declare function normalizeLegacyMessages(messages: UniMessage[]): UniMessage[];
|
|
13
|
+
//# sourceMappingURL=legacy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy.d.ts","sourceRoot":"","sources":["../src/legacy.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAerC;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE,CAiC5E"}
|
package/dist/legacy.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2025 Prism Shadow. and/or its affiliates
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.normalizeLegacyMessages = normalizeLegacyMessages;
|
|
17
|
+
const LEGACY_ITEM_TYPES = new Set([
|
|
18
|
+
"text",
|
|
19
|
+
"image_url",
|
|
20
|
+
"inline_data",
|
|
21
|
+
"thinking",
|
|
22
|
+
"inline_thinking",
|
|
23
|
+
"tool_call",
|
|
24
|
+
"tool_result",
|
|
25
|
+
"embedding",
|
|
26
|
+
]);
|
|
27
|
+
let warned = false;
|
|
28
|
+
/**
|
|
29
|
+
* Convert messages recorded before 0.5.0 to the current content item types.
|
|
30
|
+
*
|
|
31
|
+
* A legacy item type such as `text` becomes `text.done`, and a stray `partial_tool_call`
|
|
32
|
+
* is dropped. Messages already in the current format are returned as they are; a message
|
|
33
|
+
* that needed converting is returned as a copy, so the caller's data is never modified.
|
|
34
|
+
*
|
|
35
|
+
* @param messages - Messages that may carry legacy content item types
|
|
36
|
+
* @returns The messages with current content item types only
|
|
37
|
+
*/
|
|
38
|
+
function normalizeLegacyMessages(messages) {
|
|
39
|
+
return messages.map((message) => {
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
+
const items = message.content_items;
|
|
42
|
+
if (!items.some((item) => LEGACY_ITEM_TYPES.has(item.type) || item.type === "partial_tool_call")) {
|
|
43
|
+
return message;
|
|
44
|
+
}
|
|
45
|
+
if (!warned) {
|
|
46
|
+
warned = true;
|
|
47
|
+
process.emitWarning("Content item types without the .done suffix (text, tool_call, ...) are deprecated " +
|
|
48
|
+
"and will stop being accepted in MMSP 0.6.0; use text.done, tool_call.done, ...", "DeprecationWarning");
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
...message,
|
|
52
|
+
content_items: items
|
|
53
|
+
.filter((item) => item.type !== "partial_tool_call")
|
|
54
|
+
.map((item) => LEGACY_ITEM_TYPES.has(item.type)
|
|
55
|
+
? { ...item, type: `${item.type}.done` }
|
|
56
|
+
: item),
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ResponseStreamEvent } from "openai/resources/responses/responses";
|
|
2
|
+
import { LLMClient } from "../baseClient";
|
|
3
|
+
import { UniConfig, UniEvent, UniMessage } from "../types";
|
|
4
|
+
/** MiniMax M3 client using MiniMax's Responses API. */
|
|
5
|
+
export declare class MiniMaxOfficialClient extends LLMClient {
|
|
6
|
+
protected _model: string;
|
|
7
|
+
private _client;
|
|
8
|
+
constructor(options: {
|
|
9
|
+
model: string;
|
|
10
|
+
apiKey?: string;
|
|
11
|
+
baseUrl?: string | null;
|
|
12
|
+
defaultHeaders?: Record<string, string>;
|
|
13
|
+
});
|
|
14
|
+
private _convertThinkingLevelToEffort;
|
|
15
|
+
private _convertToolChoice;
|
|
16
|
+
/**
|
|
17
|
+
* Transform universal configuration to MiniMax's Responses API payload.
|
|
18
|
+
*/
|
|
19
|
+
transformUniConfigToModelConfig(config: UniConfig): any;
|
|
20
|
+
/**
|
|
21
|
+
* Transform universal messages to MiniMax Responses input items.
|
|
22
|
+
*/
|
|
23
|
+
transformUniMessageToModelInput(messages: UniMessage[]): any[];
|
|
24
|
+
/**
|
|
25
|
+
* Transform one MiniMax stream event into a universal event, identifying items by output item id.
|
|
26
|
+
*/
|
|
27
|
+
transformModelOutputToUniEvent(modelOutput: ResponseStreamEvent): UniEvent;
|
|
28
|
+
/**
|
|
29
|
+
* Stream MiniMax Responses events with unified conversion methods.
|
|
30
|
+
*/
|
|
31
|
+
_streamingResponseInternal(options: {
|
|
32
|
+
messages: UniMessage[];
|
|
33
|
+
config: UniConfig;
|
|
34
|
+
signal?: AbortSignal;
|
|
35
|
+
}): AsyncGenerator<UniEvent>;
|
|
36
|
+
/**
|
|
37
|
+
* List the model ids the configured endpoint serves.
|
|
38
|
+
*
|
|
39
|
+
* @returns The model ids, in the order the endpoint returned them.
|
|
40
|
+
*/
|
|
41
|
+
listModels(): Promise<string[]>;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/minimax_official/client.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAEV,mBAAmB,EACpB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAOL,SAAS,EACT,QAAQ,EACR,UAAU,EAEX,MAAM,UAAU,CAAC;AAOlB,uDAAuD;AACvD,qBAAa,qBAAsB,SAAQ,SAAS;IAClD,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE;QACnB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACxB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACzC;IAiBD,OAAO,CAAC,6BAA6B;IAerC,OAAO,CAAC,kBAAkB;IAY1B;;OAEG;IAEH,+BAA+B,CAAC,MAAM,EAAE,SAAS,GAAG,GAAG;IA6DvD;;OAEG;IAEH,+BAA+B,CAAC,QAAQ,EAAE,UAAU,EAAE,GAAG,GAAG,EAAE;IAuF9D;;OAEG;IACH,8BAA8B,CAAC,WAAW,EAAE,mBAAmB,GAAG,QAAQ;IAuG1E;;OAEG;IACI,0BAA0B,CAAC,OAAO,EAAE;QACzC,QAAQ,EAAE,UAAU,EAAE,CAAC;QACvB,MAAM,EAAE,SAAS,CAAC;QAClB,MAAM,CAAC,EAAE,WAAW,CAAC;KACtB,GAAG,cAAc,CAAC,QAAQ,CAAC;IAoB5B;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAQtC"}
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2025 Prism Shadow. and/or its affiliates
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
15
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.MiniMaxOfficialClient = void 0;
|
|
20
|
+
const openai_1 = __importDefault(require("openai"));
|
|
21
|
+
const baseClient_1 = require("../baseClient");
|
|
22
|
+
const errors_1 = require("../errors");
|
|
23
|
+
const types_1 = require("../types");
|
|
24
|
+
const utils_1 = require("../utils");
|
|
25
|
+
const DEFAULT_BASE_URL = "https://api.minimax.io/v1";
|
|
26
|
+
/** MiniMax M3 client using MiniMax's Responses API. */
|
|
27
|
+
class MiniMaxOfficialClient extends baseClient_1.LLMClient {
|
|
28
|
+
constructor(options) {
|
|
29
|
+
super();
|
|
30
|
+
this._model = options.model;
|
|
31
|
+
// The wrapped OpenAI SDK falls back to OPENAI_API_KEY when handed undefined, which would send
|
|
32
|
+
// an OpenAI credential to the MiniMax host, so resolve the key here and fail loudly instead.
|
|
33
|
+
const apiKey = options.apiKey || process.env.MINIMAX_API_KEY;
|
|
34
|
+
if (!apiKey) {
|
|
35
|
+
throw new Error("MINIMAX_API_KEY is required for MiniMaxOfficialClient.");
|
|
36
|
+
}
|
|
37
|
+
this._client = new openai_1.default({
|
|
38
|
+
apiKey,
|
|
39
|
+
baseURL: options.baseUrl || process.env.MINIMAX_BASE_URL || DEFAULT_BASE_URL,
|
|
40
|
+
defaultHeaders: options.defaultHeaders,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
_convertThinkingLevelToEffort(thinkingLevel) {
|
|
44
|
+
const mapping = {
|
|
45
|
+
[types_1.ThinkingLevel.NONE]: "none",
|
|
46
|
+
[types_1.ThinkingLevel.LOW]: "low",
|
|
47
|
+
[types_1.ThinkingLevel.MEDIUM]: "medium",
|
|
48
|
+
[types_1.ThinkingLevel.HIGH]: "high",
|
|
49
|
+
[types_1.ThinkingLevel.XHIGH]: "high",
|
|
50
|
+
// MiniMax stops at "high"
|
|
51
|
+
[types_1.ThinkingLevel.MAX]: "high",
|
|
52
|
+
};
|
|
53
|
+
return mapping[thinkingLevel];
|
|
54
|
+
}
|
|
55
|
+
_convertToolChoice(toolChoice) {
|
|
56
|
+
if (toolChoice === "auto" || toolChoice === "none") {
|
|
57
|
+
return toolChoice;
|
|
58
|
+
}
|
|
59
|
+
throw new errors_1.UnsupportedParameterError({
|
|
60
|
+
client: this.constructor.name,
|
|
61
|
+
parameter: "tool_choice",
|
|
62
|
+
message: "MiniMax Responses API does not support required or named tool selection.",
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Transform universal configuration to MiniMax's Responses API payload.
|
|
67
|
+
*/
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
+
transformUniConfigToModelConfig(config) {
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
+
const minimaxConfig = { model: this._model, store: false };
|
|
72
|
+
if (config.system_prompt !== undefined) {
|
|
73
|
+
minimaxConfig.instructions = config.system_prompt;
|
|
74
|
+
}
|
|
75
|
+
if (config.max_tokens !== undefined) {
|
|
76
|
+
minimaxConfig.max_output_tokens = config.max_tokens;
|
|
77
|
+
}
|
|
78
|
+
if (config.temperature !== undefined) {
|
|
79
|
+
// Written as a positive range test so NaN is rejected too: every `<`/`>` comparison against
|
|
80
|
+
// NaN is false, which would let it through to the provider as a null temperature.
|
|
81
|
+
if (!(config.temperature >= 0 && config.temperature <= 1)) {
|
|
82
|
+
throw new errors_1.UnsupportedParameterError({
|
|
83
|
+
client: this.constructor.name,
|
|
84
|
+
parameter: "temperature",
|
|
85
|
+
message: "MiniMax Responses API does not support temperatures outside the range 0 to 1.",
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
minimaxConfig.temperature = config.temperature;
|
|
89
|
+
}
|
|
90
|
+
if (config.thinking_level !== undefined) {
|
|
91
|
+
minimaxConfig.reasoning = {
|
|
92
|
+
effort: this._convertThinkingLevelToEffort(config.thinking_level),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (config.tools !== undefined) {
|
|
96
|
+
minimaxConfig.tools = config.tools.map((tool) => ({
|
|
97
|
+
type: "function",
|
|
98
|
+
...tool,
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
if (config.tool_choice !== undefined) {
|
|
102
|
+
minimaxConfig.tool_choice = this._convertToolChoice(config.tool_choice);
|
|
103
|
+
}
|
|
104
|
+
if (config.fast_mode) {
|
|
105
|
+
minimaxConfig.service_tier = "priority";
|
|
106
|
+
}
|
|
107
|
+
if (config.prompt_caching === types_1.PromptCaching.DISABLE) {
|
|
108
|
+
throw new errors_1.UnsupportedParameterError({
|
|
109
|
+
client: this.constructor.name,
|
|
110
|
+
parameter: "prompt_caching",
|
|
111
|
+
message: "MiniMax Responses API does not support disabling its automatic prompt cache.",
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (config.prompt_caching === types_1.PromptCaching.ENHANCE) {
|
|
115
|
+
throw new errors_1.UnsupportedParameterError({
|
|
116
|
+
client: this.constructor.name,
|
|
117
|
+
parameter: "prompt_caching",
|
|
118
|
+
message: "MiniMax Responses API does not support enhancing its automatic prompt cache.",
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return minimaxConfig;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Transform universal messages to MiniMax Responses input items.
|
|
125
|
+
*/
|
|
126
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
127
|
+
transformUniMessageToModelInput(messages) {
|
|
128
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
129
|
+
const inputList = [];
|
|
130
|
+
for (const message of messages) {
|
|
131
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
132
|
+
let contentItems = [];
|
|
133
|
+
for (const item of message.content_items) {
|
|
134
|
+
// anything that is not message content becomes an input item of its own, so the
|
|
135
|
+
// text collected so far is flushed first to keep the order the model produced
|
|
136
|
+
if (item.type !== "text.done" &&
|
|
137
|
+
item.type !== "image_url.done" &&
|
|
138
|
+
contentItems.length > 0) {
|
|
139
|
+
// Every turn goes back as a typed message item — the Responses API's EasyInputMessage
|
|
140
|
+
// shape, where type "message" is valid for any role. A vLLM-style Responses server
|
|
141
|
+
// answers a bare { role: "assistant", content: [...] } item with a 400 on the turn that
|
|
142
|
+
// replays it and takes the typed form for every role; OpenAI, DeepSeek and MiniMax accept
|
|
143
|
+
// either shape. Nothing beyond that minimal shape goes out: an id or a status the server
|
|
144
|
+
// never sent would be an invention.
|
|
145
|
+
inputList.push({
|
|
146
|
+
type: "message",
|
|
147
|
+
role: message.role,
|
|
148
|
+
content: contentItems,
|
|
149
|
+
});
|
|
150
|
+
contentItems = [];
|
|
151
|
+
}
|
|
152
|
+
if (item.type === "text.done") {
|
|
153
|
+
contentItems.push({
|
|
154
|
+
type: message.role === "user" ? "input_text" : "output_text",
|
|
155
|
+
text: item.text,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
else if (item.type === "image_url.done") {
|
|
159
|
+
contentItems.push({ type: "input_image", image_url: item.image_url });
|
|
160
|
+
}
|
|
161
|
+
else if (item.type === "thinking.done") {
|
|
162
|
+
// MiniMax accepts a reasoning item rebuilt from the thinking text alone, so no fidelity
|
|
163
|
+
// is recorded for it.
|
|
164
|
+
inputList.push({
|
|
165
|
+
type: "reasoning",
|
|
166
|
+
content: item.thinking
|
|
167
|
+
? [{ type: "reasoning_text", text: item.thinking }]
|
|
168
|
+
: [],
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
else if (item.type === "tool_call.done") {
|
|
172
|
+
inputList.push({
|
|
173
|
+
type: "function_call",
|
|
174
|
+
call_id: item.tool_call_id,
|
|
175
|
+
name: item.name,
|
|
176
|
+
arguments: JSON.stringify(item.arguments),
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
else if (item.type === "tool_result.done") {
|
|
180
|
+
if (item.tool_call_id === undefined) {
|
|
181
|
+
throw new Error("tool_call_id is required for tool result.");
|
|
182
|
+
}
|
|
183
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
184
|
+
let output = item.text;
|
|
185
|
+
if (item.images?.length) {
|
|
186
|
+
output = [{ type: "input_text", text: item.text }];
|
|
187
|
+
for (const imageUrl of item.images) {
|
|
188
|
+
output.push({ type: "input_image", image_url: imageUrl });
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
inputList.push({
|
|
192
|
+
type: "function_call_output",
|
|
193
|
+
call_id: item.tool_call_id,
|
|
194
|
+
output,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
throw new Error(`Unknown item: ${JSON.stringify(item)}`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (contentItems.length > 0) {
|
|
202
|
+
inputList.push({
|
|
203
|
+
type: "message",
|
|
204
|
+
role: message.role,
|
|
205
|
+
content: contentItems,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return inputList;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Transform one MiniMax stream event into a universal event, identifying items by output item id.
|
|
213
|
+
*/
|
|
214
|
+
transformModelOutputToUniEvent(modelOutput) {
|
|
215
|
+
let eventType = "delta";
|
|
216
|
+
const contentItems = [];
|
|
217
|
+
let usageMetadata = null;
|
|
218
|
+
let finishReason = null;
|
|
219
|
+
const minimaxEventType = modelOutput.type;
|
|
220
|
+
if (minimaxEventType === "response.output_text.delta") {
|
|
221
|
+
contentItems.push({
|
|
222
|
+
type: "text.delta",
|
|
223
|
+
text: modelOutput.delta,
|
|
224
|
+
fidelity: { item_id: modelOutput.item_id },
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
else if (minimaxEventType === "response.reasoning_text.delta") {
|
|
228
|
+
contentItems.push({
|
|
229
|
+
type: "thinking.delta",
|
|
230
|
+
thinking: modelOutput.delta,
|
|
231
|
+
fidelity: { item_id: modelOutput.item_id },
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
else if (minimaxEventType === "response.output_item.added") {
|
|
235
|
+
// a message or reasoning item begins: an empty delta under its id ends the item before it
|
|
236
|
+
if (modelOutput.item.type === "message") {
|
|
237
|
+
contentItems.push({
|
|
238
|
+
type: "text.delta",
|
|
239
|
+
text: "",
|
|
240
|
+
fidelity: { item_id: modelOutput.item.id },
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
else if (modelOutput.item.type === "reasoning") {
|
|
244
|
+
contentItems.push({
|
|
245
|
+
type: "thinking.delta",
|
|
246
|
+
thinking: "",
|
|
247
|
+
fidelity: { item_id: modelOutput.item.id },
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
else if (minimaxEventType === "response.output_item.done") {
|
|
252
|
+
// MiniMax's tool calls are read from the completed item alone: the argument deltas are
|
|
253
|
+
// left unread rather than reconciled against this item, and the call streams as one
|
|
254
|
+
// delta carrying the whole arguments, so what a consumer streams and the call it is
|
|
255
|
+
// handed are one and the same.
|
|
256
|
+
const item = modelOutput.item;
|
|
257
|
+
if (item.type === "function_call") {
|
|
258
|
+
contentItems.push({
|
|
259
|
+
type: "tool_call.delta",
|
|
260
|
+
name: item.name,
|
|
261
|
+
// a server may complete a call without its arguments field
|
|
262
|
+
arguments: item.arguments || "",
|
|
263
|
+
tool_call_id: item.call_id,
|
|
264
|
+
// a server that sends no item id still sends the call id
|
|
265
|
+
fidelity: { item_id: item.id || item.call_id },
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
else if (minimaxEventType === "response.completed" ||
|
|
270
|
+
minimaxEventType === "response.incomplete") {
|
|
271
|
+
eventType = "stop";
|
|
272
|
+
const response = modelOutput.response;
|
|
273
|
+
const finishReasonMapping = {
|
|
274
|
+
completed: "stop",
|
|
275
|
+
incomplete: "length",
|
|
276
|
+
};
|
|
277
|
+
finishReason = finishReasonMapping[response.status ?? ""] ?? "unknown";
|
|
278
|
+
if (response.usage) {
|
|
279
|
+
// MiniMax drops the detail blocks on truncated responses, so default them to zero.
|
|
280
|
+
const cachedTokens = response.usage.input_tokens_details?.cached_tokens ?? 0;
|
|
281
|
+
const reasoningTokens = response.usage.output_tokens_details?.reasoning_tokens ?? 0;
|
|
282
|
+
usageMetadata = {
|
|
283
|
+
cached_tokens: cachedTokens,
|
|
284
|
+
prompt_tokens: response.usage.input_tokens - cachedTokens,
|
|
285
|
+
thoughts_tokens: reasoningTokens,
|
|
286
|
+
response_tokens: response.usage.output_tokens - reasoningTokens,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
else if (![
|
|
291
|
+
"response.created",
|
|
292
|
+
"response.in_progress",
|
|
293
|
+
"response.output_text.done",
|
|
294
|
+
"response.reasoning_text.done",
|
|
295
|
+
"response.function_call_arguments.delta",
|
|
296
|
+
"response.function_call_arguments.done",
|
|
297
|
+
"response.content_part.added",
|
|
298
|
+
"response.content_part.done",
|
|
299
|
+
// gateway heartbeat on long generations; carries no content
|
|
300
|
+
"keepalive",
|
|
301
|
+
].includes(minimaxEventType) &&
|
|
302
|
+
(0, utils_1.isDebugEnabled)()) {
|
|
303
|
+
throw new Error(`Unknown output: ${JSON.stringify(modelOutput)}`);
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
role: "assistant",
|
|
307
|
+
event_type: eventType,
|
|
308
|
+
content_items: contentItems,
|
|
309
|
+
usage_metadata: usageMetadata,
|
|
310
|
+
finish_reason: finishReason,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Stream MiniMax Responses events with unified conversion methods.
|
|
315
|
+
*/
|
|
316
|
+
async *_streamingResponseInternal(options) {
|
|
317
|
+
const minimaxConfig = this.transformUniConfigToModelConfig(options.config);
|
|
318
|
+
const inputList = this.transformUniMessageToModelInput(options.messages);
|
|
319
|
+
// MiniMax accepts output_text assistant inputs and function tools without OpenAI's required
|
|
320
|
+
// strict field, so narrow the compatibility cast to this boundary.
|
|
321
|
+
const params = {
|
|
322
|
+
...minimaxConfig,
|
|
323
|
+
input: inputList,
|
|
324
|
+
stream: true,
|
|
325
|
+
};
|
|
326
|
+
const stream = await this._client.responses.create(params, {
|
|
327
|
+
signal: options.signal,
|
|
328
|
+
});
|
|
329
|
+
for await (const event of stream) {
|
|
330
|
+
yield this.transformModelOutputToUniEvent(event);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* List the model ids the configured endpoint serves.
|
|
335
|
+
*
|
|
336
|
+
* @returns The model ids, in the order the endpoint returned them.
|
|
337
|
+
*/
|
|
338
|
+
async listModels() {
|
|
339
|
+
const models = [];
|
|
340
|
+
for await (const model of this._client.models.list()) {
|
|
341
|
+
models.push(model.id);
|
|
342
|
+
}
|
|
343
|
+
return models;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
exports.MiniMaxOfficialClient = MiniMaxOfficialClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/minimax_official/index.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2025 Prism Shadow. and/or its affiliates
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.MiniMaxOfficialClient = void 0;
|
|
17
|
+
var client_1 = require("./client");
|
|
18
|
+
Object.defineProperty(exports, "MiniMaxOfficialClient", { enumerable: true, get: function () { return client_1.MiniMaxOfficialClient; } });
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { ChatCompletionChunk, ChatCompletionMessageParam } from "openai/resources/chat/completions";
|
|
2
|
+
import { LLMClient } from "../baseClient";
|
|
3
|
+
import { UniConfig, UniEvent, UniMessage } from "../types";
|
|
4
|
+
/**
|
|
5
|
+
* Kimi K3-specific LLM client implementation using OpenAI-compatible API (also serves K2.5 and K2.6).
|
|
6
|
+
*/
|
|
7
|
+
export declare class MoonshotOfficialClient extends LLMClient {
|
|
8
|
+
protected _model: string;
|
|
9
|
+
private _client;
|
|
10
|
+
/**
|
|
11
|
+
* Initialize Kimi K3 client with model and API key.
|
|
12
|
+
*/
|
|
13
|
+
constructor(options: {
|
|
14
|
+
model: string;
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
baseUrl?: string | null;
|
|
17
|
+
defaultHeaders?: Record<string, string>;
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Detect MIME type from URL extension for image.
|
|
21
|
+
*/
|
|
22
|
+
private _detectImageMimeType;
|
|
23
|
+
/**
|
|
24
|
+
* Convert image URL to base64-encoded data URL.
|
|
25
|
+
*/
|
|
26
|
+
private _convertImageUrlToBase64;
|
|
27
|
+
/**
|
|
28
|
+
* Convert ThinkingLevel enum to the K2-generation thinking configuration.
|
|
29
|
+
*/
|
|
30
|
+
private _convertThinkingLevelToThinkingConfig;
|
|
31
|
+
/**
|
|
32
|
+
* Convert ThinkingLevel enum to Kimi K3's reasoning_effort.
|
|
33
|
+
*
|
|
34
|
+
* K3 cannot disable reasoning, so NONE degrades to the lowest effort
|
|
35
|
+
* instead of throwing.
|
|
36
|
+
*/
|
|
37
|
+
private _convertThinkingLevelToReasoningEffort;
|
|
38
|
+
/**
|
|
39
|
+
* Convert ToolChoice to OpenAI's tool_choice format.
|
|
40
|
+
*/
|
|
41
|
+
private _convertToolChoice;
|
|
42
|
+
/**
|
|
43
|
+
* Transform universal configuration to Kimi K3-specific configuration.
|
|
44
|
+
*/
|
|
45
|
+
transformUniConfigToModelConfig(config: UniConfig): any;
|
|
46
|
+
/**
|
|
47
|
+
* Transform universal message format to OpenAI's message format.
|
|
48
|
+
*/
|
|
49
|
+
transformUniMessageToModelInput(messages: UniMessage[], signal?: AbortSignal): Promise<ChatCompletionMessageParam[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Transform one Kimi K3 streaming chunk into a universal event.
|
|
52
|
+
*
|
|
53
|
+
* Chat Completions gives an item no identity, so each delta's item_id is the wire field
|
|
54
|
+
* that carried it: an item runs until a delta arrives from another field, or names the next
|
|
55
|
+
* tool call.
|
|
56
|
+
*/
|
|
57
|
+
transformModelOutputToUniEvent(modelOutput: ChatCompletionChunk): UniEvent;
|
|
58
|
+
/**
|
|
59
|
+
* Stream generate using Kimi SDK with unified conversion methods.
|
|
60
|
+
*/
|
|
61
|
+
_streamingResponseInternal(options: {
|
|
62
|
+
messages: UniMessage[];
|
|
63
|
+
config: UniConfig;
|
|
64
|
+
signal?: AbortSignal;
|
|
65
|
+
}): AsyncGenerator<UniEvent>;
|
|
66
|
+
/**
|
|
67
|
+
* List the model ids the configured endpoint serves.
|
|
68
|
+
*
|
|
69
|
+
* @returns The model ids, in the order the endpoint returned them.
|
|
70
|
+
*/
|
|
71
|
+
listModels(): Promise<string[]>;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/moonshot_official/client.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACV,mBAAmB,EACnB,0BAA0B,EAE3B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAOL,SAAS,EACT,QAAQ,EACR,UAAU,EAEX,MAAM,UAAU,CAAC;AAGlB;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,SAAS;IACnD,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,OAAO,CAAS;IAExB;;OAEG;gBACS,OAAO,EAAE;QACnB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACxB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACzC;IAsBD;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAe5B;;OAEG;YACW,wBAAwB;IAqBtC;;OAEG;IACH,OAAO,CAAC,qCAAqC;IAc7C;;;;;OAKG;IACH,OAAO,CAAC,sCAAsC;IAc9C;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAsB1B;;OAEG;IAEH,+BAA+B,CAAC,MAAM,EAAE,SAAS,GAAG,GAAG;IA2EvD;;OAEG;IACG,+BAA+B,CACnC,QAAQ,EAAE,UAAU,EAAE,EACtB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,0BAA0B,EAAE,CAAC;IA+GxC;;;;;;OAMG;IACH,8BAA8B,CAAC,WAAW,EAAE,mBAAmB,GAAG,QAAQ;IAmH1E;;OAEG;IACI,0BAA0B,CAAC,OAAO,EAAE;QACzC,QAAQ,EAAE,UAAU,EAAE,CAAC;QACvB,MAAM,EAAE,SAAS,CAAC;QAClB,MAAM,CAAC,EAAE,WAAW,CAAC;KACtB,GAAG,cAAc,CAAC,QAAQ,CAAC;IA6B5B;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAQtC"}
|