Repository navigation
Add MiniMax remote presets with Flash-first text choices #725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
octo-patch
wants to merge
2
commits into
off-grid-ai:main
Choose a base branch
from
octo-patch:octo/20261019-provider-add-recvsHV9QBP2B3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+372
−9
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
__tests__/unit/services/providers/minimaxDiscovery.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import { fetchModelsFromServer, testEndpointAndGetModels } from '../../../../src/stores/remoteServerHelpers'; | ||
| import type { RemoteServer } from '../../../../src/types'; | ||
|
|
||
| jest.mock('../../../../src/utils/logger', () => ({ | ||
| __esModule: true, | ||
| default: { log: jest.fn(), warn: jest.fn(), error: jest.fn() }, | ||
| })); | ||
| jest.mock('../../../../src/services/offGridDesktopModels', () => ({ | ||
| readOffGridDesktopModelState: jest.fn(async () => null), | ||
| })); | ||
| jest.mock('../../../../src/services/httpClient', () => ({ | ||
| testEndpoint: jest.fn(async () => ({ success: true, latency: 1 })), | ||
| detectServerType: jest.fn(async () => null), | ||
| })); | ||
| jest.mock('../../../../src/stores/remoteModelCapabilities', () => ({ | ||
| isGenerativeModel: () => true, | ||
| fetchModelCapabilities: jest.fn(async () => ({ contextLength: 4096, supportsVision: false })), | ||
| RemoteAuthenticationError: class extends Error {}, | ||
| })); | ||
|
|
||
| const directModels = [ | ||
| { id: 'MiniMax-M2.7', kind: 'chat' }, | ||
| { id: 'MiniMax-M3', kind: 'chat' }, | ||
| { id: 'MiniMax-M3.1-Flash', kind: 'chat' }, | ||
| { id: 'MiniMax-image', kind: 'image' }, | ||
| { id: 'MiniMax-speech', kind: 'speech' }, | ||
| ]; | ||
|
|
||
| describe('MiniMax discovery', () => { | ||
| const originalFetch = global.fetch; | ||
| afterEach(() => { global.fetch = originalFetch; }); | ||
| const serve = (data: unknown[]) => { | ||
| global.fetch = jest.fn(async () => ({ | ||
| ok: true, status: 200, json: async () => ({ object: 'list', data }), | ||
| })) as unknown as typeof fetch; | ||
| }; | ||
|
|
||
| it.each(['https://api.minimax.io/v1', 'https://api.minimaxi.com/v1/'])( | ||
| 'refreshes ordinary text choices at %s without changing saved IDs or media', | ||
| async endpoint => { | ||
| serve(directModels); | ||
| const server = { id: 'saved', endpoint, mediaModels: { text: 'MiniMax-M2.7' } } as RemoteServer; | ||
| const models = await fetchModelsFromServer(server); | ||
| expect(models.map(model => model.id)).toEqual(['MiniMax-M3.1-Flash', 'MiniMax-M3']); | ||
| expect(models[0].capabilities).toMatchObject({ | ||
| maxContextLength: 1_000_000, supportsVision: true, | ||
| supportsToolCalling: true, thinkingLevelsOnly: true, acceptsThinkingKwarg: false, | ||
| }); | ||
| expect(server.mediaModels?.text).toBe('MiniMax-M2.7'); | ||
| const result = await testEndpointAndGetModels(endpoint); | ||
| expect(result.modelCatalog?.text?.map(model => model.id)).toEqual(['MiniMax-M3.1-Flash', 'MiniMax-M3']); | ||
| expect(result.mediaModels).toEqual({ text: 'MiniMax-M3.1-Flash', image: 'MiniMax-image', voice: 'MiniMax-speech' }); | ||
| }, | ||
| ); | ||
|
|
||
| it('keeps gateway metadata, non-MiniMax models and media while ordering current text models', async () => { | ||
| const data = [ | ||
| { id: 'other/model', context_length: 12345 }, | ||
| { id: 'minimax/minimax-m2.7' }, | ||
| { id: 'minimax/minimax-m3', context_length: 524288 }, | ||
| { id: 'minimax/minimax-m3.1-flash:free', context_length: 1000000 }, | ||
| ].map(model => ({ ...model, architecture: { input_modalities: ['text', 'image'], output_modalities: ['text'] }, supported_parameters: ['tools'] })); | ||
| serve([...data, { id: 'minimax/media', architecture: { output_modalities: ['image'] } }]); | ||
| const endpoint = 'https://openrouter.ai/api/v1'; | ||
| const models = await fetchModelsFromServer({ id: 'gateway', endpoint } as RemoteServer); | ||
| expect(models.map(model => model.id)).toEqual(['other/model', 'minimax/minimax-m3.1-flash:free', 'minimax/minimax-m3']); | ||
| expect(models[2].capabilities.maxContextLength).toBe(524288); | ||
| expect(models[1].capabilities).toMatchObject({ | ||
| supportsThinking: true, thinkingLevelsOnly: true, acceptsThinkingKwarg: false, | ||
| }); | ||
| const result = await testEndpointAndGetModels(endpoint); | ||
| expect(result.modelCatalog?.text?.map(model => model.id)).toEqual(models.map(model => model.id)); | ||
| expect(result.modelCatalog?.image?.map(model => model.id)).toEqual(['minimax/media']); | ||
| }); | ||
|
|
||
| it('leaves custom endpoint model lists alone', async () => { | ||
| serve(directModels); | ||
| const models = await fetchModelsFromServer({ id: 'custom', endpoint: 'https://custom.example/v1' } as RemoteServer); | ||
| expect(models.map(model => model.id)).toEqual(['MiniMax-M2.7', 'MiniMax-M3', 'MiniMax-M3.1-Flash']); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import React from 'react'; | ||
| import { act, create } from 'react-test-renderer'; | ||
| import { useRemoteServerForm } from '../../../../src/components/RemoteServerEditor/useRemoteServerForm'; | ||
| import { remoteServerManager } from '../../../../src/services/remoteServerManager'; | ||
| import type { RemoteServer } from '../../../../src/types'; | ||
|
|
||
| jest.mock('../../../../src/services/remoteServerManager', () => ({ | ||
| remoteServerManager: { | ||
| getApiKey: jest.fn(async () => null), | ||
| testConnectionByEndpoint: jest.fn(async () => ({ | ||
| success: true, models: [{ id: 'MiniMax-M3' }], | ||
| })), | ||
| }, | ||
| })); | ||
| jest.mock('../../../../src/stores', () => ({ useRemoteServerStore: {} })); | ||
| jest.mock('../../../../src/services/httpClient', () => ({ isPrivateNetworkEndpoint: () => false })); | ||
| jest.mock('../../../../src/components/CustomAlert', () => ({ initialAlertState: {}, showAlert: jest.fn() })); | ||
|
|
||
| // Hooks are mounted so edits between renders exercise callback capture and updater ordering. | ||
| describe('MiniMax editor defaults', () => { | ||
| it.each(['', 'MiniMax-M2.7', 'custom-model'])('preserves explicit selection %s when testing', async selection => { | ||
| let form!: ReturnType<typeof useRemoteServerForm>; | ||
| function Harness() { | ||
| form = useRemoteServerForm({ visible: true, onClose: jest.fn() }); | ||
| return null; | ||
| } | ||
| let renderer!: ReturnType<typeof create>; | ||
| await act(async () => { renderer = create(React.createElement(Harness)); }); | ||
| await act(async () => { | ||
| form.setName('MiniMax'); | ||
| form.setEndpoint('https://api.minimax.io/v1'); | ||
| }); | ||
| await act(async () => { form.setTextModelId(selection); }); | ||
| await act(async () => { await form.handleTestConnection(); }); | ||
| expect(form.textModelId).toBe(selection || 'MiniMax-M3.1-Flash'); | ||
| expect(form.providerType).toBe('minimax'); | ||
| expect(remoteServerManager.testConnectionByEndpoint).toHaveBeenCalled(); | ||
| await act(async () => { renderer.unmount(); }); | ||
| }); | ||
|
|
||
| it('preserves an existing provider type on a custom endpoint', async () => { | ||
| const server = { | ||
| id: 'saved', name: 'Custom', endpoint: 'https://custom.example/anthropic', | ||
| providerType: 'anthropic', mediaModels: { text: 'saved-model' }, | ||
| } as RemoteServer; | ||
| let form!: ReturnType<typeof useRemoteServerForm>; | ||
| function Harness() { | ||
| form = useRemoteServerForm({ server, visible: true, onClose: jest.fn() }); | ||
| return null; | ||
| } | ||
| let renderer!: ReturnType<typeof create>; | ||
| await act(async () => { renderer = create(React.createElement(Harness)); }); | ||
| await act(async () => { await form.handleTestConnection(); }); | ||
| expect(form.providerType).toBe('anthropic'); | ||
| expect(form.textModelId).toBe('saved-model'); | ||
| await act(async () => { renderer.unmount(); }); | ||
| }); | ||
| }); |
88 changes: 88 additions & 0 deletions
88
__tests__/unit/services/providers/minimaxTransport.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import { createOpenAIProvider } from '../../../../src/services/providers/openAICompatibleProvider'; | ||
| import { MINIMAX_DEFAULT_MODEL, MINIMAX_ENDPOINTS, MINIMAX_MODELS, isMiniMaxEndpoint } from '../../../../src/services/providers/minimax'; | ||
| import type { Message } from '../../../../src/types'; | ||
|
|
||
| jest.mock('../../../../src/utils/logger', () => ({ | ||
| __esModule: true, | ||
| default: { log: jest.fn(), warn: jest.fn(), error: jest.fn() }, | ||
| })); | ||
| jest.mock('../../../../src/stores/appStore', () => ({ | ||
| useAppStore: { getState: () => ({ settings: {} }) }, | ||
| })); | ||
|
|
||
| // Exercise the real provider, message builder, JSON serialization and SSE reader. | ||
| // Only the native network boundary is replaced; no request reaches an API. | ||
| class RecordingXHR { | ||
| static requests: Array<{ url: string; body: Record<string, any> }> = []; | ||
| readyState = 0; | ||
| status = 200; | ||
| responseText = 'data: {"choices":[{"delta":{"content":"ok"},"finish_reason":"stop"}]}\n\n'; | ||
| responseURL = ''; | ||
| onreadystatechange?: () => void; | ||
| open(_method: string, url: string) { this.responseURL = url; } | ||
| setRequestHeader() {} | ||
| abort() {} | ||
| send(body: string) { | ||
| RecordingXHR.requests.push({ url: this.responseURL, body: JSON.parse(body) }); | ||
| this.readyState = 4; | ||
| this.onreadystatechange?.(); | ||
| } | ||
| } | ||
|
|
||
| describe('MiniMax serialized remote requests', () => { | ||
| const originalXHR = global.XMLHttpRequest; | ||
| beforeEach(() => { | ||
| RecordingXHR.requests = []; | ||
| global.XMLHttpRequest = RecordingXHR as unknown as typeof XMLHttpRequest; | ||
| }); | ||
| afterEach(() => { global.XMLHttpRequest = originalXHR; }); | ||
|
|
||
| it('offers Flash first and M3 without treating other protocols as this transport', () => { | ||
| expect(MINIMAX_MODELS.map(model => model.id)).toEqual(['MiniMax-M3.1-Flash', 'MiniMax-M3']); | ||
| expect(isMiniMaxEndpoint(MINIMAX_ENDPOINTS.global.anthropic)).toBe(false); | ||
| expect(isMiniMaxEndpoint('https://api.minimax.io.example/v1')).toBe(false); | ||
| expect(isMiniMaxEndpoint('invalid')).toBe(false); | ||
| }); | ||
|
|
||
| it.each(Object.values(MINIMAX_ENDPOINTS).map(region => region.openai))( | ||
| 'serializes default, saved and custom models at %s without losing tool/image history', | ||
| async endpoint => { | ||
| const messages = [ | ||
| { role: 'user', content: 'Describe', attachments: [{ type: 'image', uri: 'data:image/png;base64,AAAA' }] }, | ||
| { role: 'assistant', content: '', reasoningDetails: [{ type: 'reasoning.text', text: 'kept' }], toolCalls: [{ id: 'call-1', name: 'lookup', arguments: '{}' }] }, | ||
| { role: 'tool', content: 'result', toolCallId: 'call-1' }, | ||
| ] as Message[]; | ||
| for (const modelId of [MINIMAX_DEFAULT_MODEL, 'MiniMax-M3', 'MiniMax-M2.7', 'custom-model']) { | ||
| const provider = createOpenAIProvider('test', endpoint, { modelId }); | ||
| provider.updateCapabilities({ supportsVision: true, supportsThinking: true }); | ||
| const callbacks = { onToken: jest.fn(), onComplete: jest.fn(), onError: jest.fn() }; | ||
| await provider.generate(messages, { enableThinking: false }, callbacks); | ||
| expect(callbacks.onError).not.toHaveBeenCalled(); | ||
| expect(callbacks.onComplete).toHaveBeenCalledWith(expect.objectContaining({ content: 'ok' })); | ||
| const request = RecordingXHR.requests[RecordingXHR.requests.length - 1]; | ||
| expect(request.url).toBe(`${endpoint}/chat/completions`); | ||
| expect(request.body.model).toBe(modelId); | ||
| expect(request.body.messages[0].content[1].image_url.url).toBe('data:image/png;base64,AAAA'); | ||
| expect(request.body.messages[1].tool_calls[0].id).toBe('call-1'); | ||
| expect(request.body.messages[1].reasoning_details).toEqual(messages[1].reasoningDetails); | ||
| expect(request.body.messages[2].tool_call_id).toBe('call-1'); | ||
| expect(request.body.thinking).toEqual(modelId === 'MiniMax-M3' ? { type: 'disabled' } : undefined); | ||
| expect(request.body).not.toHaveProperty('reasoning_effort'); | ||
| expect(request.body).not.toHaveProperty('service_tier'); | ||
| expect(request.body).not.toHaveProperty('reasoning_split'); | ||
| expect(request.body).not.toHaveProperty('chat_template_kwargs'); | ||
| } | ||
| }, | ||
| ); | ||
|
|
||
| it('uses adaptive M3 thinking by default and preserves non-MiniMax requests', async () => { | ||
| for (const endpoint of ['https://api.minimax.io/v1', 'https://custom.example/v1']) { | ||
| const provider = createOpenAIProvider('test', endpoint, { modelId: 'MiniMax-M3' }); | ||
| const onError = jest.fn(); | ||
| await provider.generate([], {}, { onToken: jest.fn(), onComplete: jest.fn(), onError }); | ||
| expect(onError).not.toHaveBeenCalled(); | ||
| expect(RecordingXHR.requests[RecordingXHR.requests.length - 1].body.thinking) | ||
| .toEqual(endpoint.includes('minimax.io') ? { type: 'adaptive' } : undefined); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Set
providerTypefrom the endpoint at save time, not only during a connection test.providerTypechanges only inhandleTestConnection.saveServersaves whatever value the state holds. Two cases make the saved value stale:'openai-compatible'.'minimax'with a non-MiniMax endpoint.Put the same mapping in a helper. Call the helper in
saveServerforupdateServerandaddServer. This also removes the nested ternary that SonarCloud flags.Proposed fix
🧰 Tools
🪛 GitHub Check: SonarCloud Code Analysis
[warning] 203-203: Extract this nested ternary operation into an independent statement.
See more on https://sonarcloud.io/project/issues?id=off-grid-ai_off-grid-ai-mobile&issues=AaFZcFdJ6d11yHibRCzk&open=AaFZcFdJ6d11yHibRCzk&pullRequest=725
🤖 Prompt for AI Agents
Source: Linters/SAST tools