MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / MiniMaxHandler

Class MiniMaxHandler

src/api/providers/minimax.ts:53–306  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53export class MiniMaxHandler extends BaseProvider implements SingleCompletionHandler {
54 private options: ApiHandlerOptions
55 private client: Anthropic
56
57 constructor(options: ApiHandlerOptions) {
58 super()
59 this.options = options
60
61 // Use Anthropic-compatible endpoint
62 // Default to international endpoint: https://api.minimax.io/anthropic
63 // China endpoint: https://api.minimaxi.com/anthropic
64 let baseURL = options.minimaxBaseUrl || "https://api.minimax.io/anthropic"
65
66 // If user provided a /v1 endpoint, convert to /anthropic
67 if (baseURL.endsWith("/v1")) {
68 baseURL = baseURL.replace(/\/v1$/, "/anthropic")
69 } else if (!baseURL.endsWith("/anthropic")) {
70 baseURL = `${baseURL.replace(/\/$/, "")}/anthropic`
71 }
72
73 this.client = new Anthropic({
74 baseURL,
75 apiKey: options.minimaxApiKey,
76 timeout: this.timeoutMs,
77 })
78 }
79
80 async *createMessage(
81 systemPrompt: string,
82 messages: Anthropic.Messages.MessageParam[],
83 metadata?: ApiHandlerCreateMessageMetadata,
84 ): ApiStream {
85 const cacheControl: CacheControlEphemeral = { type: "ephemeral" }
86 const { id: modelId, info, maxTokens, temperature } = this.getModel()
87
88 // MiniMax M2 models support prompt caching
89 const supportsPromptCache = info.supportsPromptCache ?? false
90
91 // Merge environment_details from messages that follow tool_result blocks
92 // into the tool_result content. This preserves reasoning continuity for
93 // thinking models by preventing user messages from interrupting the
94 // reasoning context after tool use (similar to r1-format's mergeToolResultText).
95 const processedMessages = mergeEnvironmentDetailsForMiniMax(messages)
96
97 // Build the system blocks array
98 const systemBlocks: Anthropic.Messages.TextBlockParam[] = [
99 supportsPromptCache
100 ? { text: systemPrompt, type: "text", cache_control: cacheControl }
101 : { text: systemPrompt, type: "text" },
102 ]
103
104 // Prepare request parameters
105 const requestParams: Anthropic.Messages.MessageCreateParams = {
106 model: modelId,
107 max_tokens: maxTokens ?? 16_384,
108 temperature: temperature ?? 1.0,
109 system: systemBlocks,
110 messages: supportsPromptCache ? this.addCacheControl(processedMessages, cacheControl) : processedMessages,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected