@molecule/api-ai-minimax 1.0.1 → 1.1.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.
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,UAAU,EAOX,MAAM,kBAAkB,CAAA;AASzB,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAymB/C;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,UAAU,CAEjE"}
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,UAAU,EAOX,MAAM,kBAAkB,CAAA;AASzB,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AA+oB/C;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,UAAU,CAEjE"}
package/dist/provider.js CHANGED
@@ -72,7 +72,12 @@ class MiniMaxAIProvider {
72
72
  const canonicalModel = params.model ?? this.defaultModel;
73
73
  const model = this.modelMap[canonicalModel] ?? canonicalModel;
74
74
  const maxTokens = params.maxTokens ?? this.maxTokens;
75
- const messages = this.formatMessages(params.messages, params.system, params.cacheControl);
75
+ const messages = this.formatMessages(params.messages, params.system, params.cacheControl,
76
+ // M3 is natively multimodal (M2.x is text-only) — forward image blocks
77
+ // for it; both the native host and the DeepInfra re-host accept the
78
+ // OpenAI image_url data-URI form. Gate on the CANONICAL id: the mapped
79
+ // upstream id never matches the family anchor.
80
+ isM3Family(canonicalModel));
76
81
  const body = {
77
82
  // Abuse attribution (see ChatParams.endUserId): OpenAI-compatible APIs
78
83
  // scope enforcement by `user`, so an abusive tenant can be actioned
@@ -91,14 +96,33 @@ class MiniMaxAIProvider {
91
96
  const allTools = [...functions, ...serverTools];
92
97
  if (allTools.length > 0) {
93
98
  body.tools = allTools;
99
+ // Honor forced tool choice (discovery mode relies on it — an unenforced
100
+ // 'required' lets the model narrate the call as text instead of emitting
101
+ // tool_use). OpenAI-compatible forms; 'auto' is the API default → omit.
102
+ if (params.toolChoice === 'required') {
103
+ body.tool_choice = 'required';
104
+ }
105
+ else if (typeof params.toolChoice === 'object' && params.toolChoice.type === 'tool') {
106
+ body.tool_choice = { type: 'function', function: { name: params.toolChoice.name } };
107
+ }
94
108
  }
95
109
  // MiniMax's native API has no reasoning_effort / thinking budget. M3 takes
96
110
  // `thinking: {type: "adaptive" | "disabled"}` (the OpenAI-compatible
97
111
  // endpoint defaults to adaptive when omitted); M2.x thinking is always on
98
112
  // and takes no param. Synthase runs M3 as a non-thinking executor (like
99
113
  // DeepSeek), so explicitly disable unless thinking was requested.
100
- if (isM3Family(model)) {
114
+ // Family-gate on the CANONICAL id: `model` is the mapped upstream id on
115
+ // re-hosts (`MiniMaxAI/MiniMax-M3`), which the `minimax-m3` anchor never
116
+ // matches — that omission left thinking defaulted ON for every US turn.
117
+ if (isM3Family(canonicalModel)) {
101
118
  body.thinking = { type: params.thinking ? 'adaptive' : 'disabled' };
119
+ if (!params.thinking) {
120
+ // Open-weights re-hosts (DeepInfra) IGNORE the native `thinking` param
121
+ // and default reasoning ON — only `chat_template_kwargs.enable_thinking`
122
+ // reaches the template there. The native host accepts both together
123
+ // (verified live 2026-08-28), so send both and each host honors its own.
124
+ body.chat_template_kwargs = { enable_thinking: false };
125
+ }
102
126
  }
103
127
  // Keep thinking out of the visible message: with reasoning_split, thinking
104
128
  // arrives in `reasoning_content` (parsed below) instead of inline
@@ -212,15 +236,17 @@ class MiniMaxAIProvider {
212
236
  /**
213
237
  * Converts internal `ChatMessage` objects to the OpenAI-compatible message format.
214
238
  * System prompt is prepended as a system role message.
215
- * MiniMax does not support vision/images, so image blocks are skipped.
239
+ * Image blocks are forwarded only for vision-capable models (M3 family);
240
+ * text-only M2.x models get them skipped.
216
241
  *
217
242
  * @param messages - The chat messages to format.
218
243
  * @param system - Optional system prompt to prepend.
219
244
  * @param cacheControl - Optional cache hint for the system prompt block.
220
245
  * @param cacheControl.type - Ephemeral cache policy label expected by MiniMax.
246
+ * @param supportsImages - Whether the target model accepts image input.
221
247
  * @returns The formatted messages array for the MiniMax API.
222
248
  */
223
- formatMessages(messages, system, cacheControl) {
249
+ formatMessages(messages, system, cacheControl, supportsImages = false) {
224
250
  const formatted = [];
225
251
  if (system) {
226
252
  if (cacheControl) {
@@ -251,7 +277,15 @@ class MiniMaxAIProvider {
251
277
  parts.push({ type: 'text', text: block.text });
252
278
  break;
253
279
  case 'image':
254
- // MiniMax does not support vision/images — skip image blocks
280
+ // M3 family is natively multimodal; M2.x is text-only. Dropping an
281
+ // image SILENTLY (the pre-M3 behavior for every model) made the
282
+ // model answer blind to attachments with no error anywhere.
283
+ if (supportsImages) {
284
+ parts.push({
285
+ type: 'image_url',
286
+ image_url: { url: `data:${block.mediaType};base64,${block.data}` },
287
+ });
288
+ }
255
289
  break;
256
290
  case 'tool_use':
257
291
  toolCalls.push({
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@molecule/api-ai-minimax",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "description": "MiniMax AI provider for molecule.dev",
5
+ "homepage": "https://www.molecule.dev/packages/api-ai-minimax",
5
6
  "type": "module",
6
7
  "main": "dist/index.js",
7
8
  "types": "dist/index.d.ts",
@@ -32,11 +33,11 @@
32
33
  "directory": "packages/api/bonds/ai/minimax"
33
34
  },
34
35
  "devDependencies": {
35
- "@molecule/api-ai": "1.0.1",
36
- "@molecule/api-bond": "1.0.1",
36
+ "@molecule/api-ai": "1.2.1",
37
+ "@molecule/api-bond": "1.0.2",
37
38
  "@types/node": "26.1.2",
38
39
  "typescript": "6.0.3",
39
- "vitest": "4.1.10"
40
+ "vitest": "4.1.11"
40
41
  },
41
42
  "peerDependencies": {
42
43
  "@molecule/api-ai": "^1.0.1",