Skip to content

armgit / Orkas

Public Imported from GitHub
0

Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.

fix: sync BYO model image capabilities

wyt52ac96008ee0
diff --git a/src/main/features/auth.ts b/src/main/features/auth.ts
index 236fc3bd..91c77cb1 100644
--- a/src/main/features/auth.ts
+++ b/src/main/features/auth.ts
@@ -666,7 +666,9 @@ function customRuntimeConfigFromProfile(
contextWindow,
maxTokens,
...(profile.supportsReasoning === true ? { supportsReasoning: true } : {}),
- ...(profile.supportsVision === true ? { supportsVision: true } : {}),
+ ...(typeof profile.supportsVision === 'boolean'
+ ? { supportsVision: profile.supportsVision }
+ : {}),
...(reasoningEffort ? { reasoningEffort } : {}),
};
} catch {
@@ -1093,7 +1095,9 @@ export async function addCustomModelEntry(
contextWindow,
...(maxTokens !== undefined ? { maxTokens } : {}),
...(input.supportsReasoning === true ? { supportsReasoning: true } : {}),
- ...(input.supportsVision === true ? { supportsVision: true } : {}),
+ ...(typeof input.supportsVision === 'boolean'
+ ? { supportsVision: input.supportsVision }
+ : {}),
...(reasoningEffort
? { reasoningEffort: reasoningEffort as 'low' | 'medium' | 'high' }
: {}),
diff --git a/src/main/ipc/index.ts b/src/main/ipc/index.ts
index 64d83ecb..25a47196 100644
--- a/src/main/ipc/index.ts
+++ b/src/main/ipc/index.ts
@@ -2661,9 +2661,17 @@ const invokeHandlers: Record<string, InvokeHandler> = {
'auth.addApiKeyEntry': async ({ provider, model, apiKey, label }) => (
auth.addApiKeyEntry(provider, model, apiKey, label)
),
- 'auth.addCustomModelEntry': async ({ label, baseUrl, model, apiKey, contextWindow, maxTokens }) => (
- auth.addCustomModelEntry({ label, baseUrl, model, apiKey, contextWindow, maxTokens })
- ),
+ 'auth.addCustomModelEntry': async (
+ { label, baseUrl, model, apiKey, contextWindow, maxTokens, supportsVision },
+ ) => auth.addCustomModelEntry({
+ label,
+ baseUrl,
+ model,
+ apiKey,
+ contextWindow,
+ maxTokens,
+ supportsVision,
+ }),
// Legacy alias; renderer migrated to auth.addApiKey.
'auth.saveApiKey': async ({ provider, apiKey, label }) => auth.saveApiKey(provider, apiKey, label),
'auth.renameProfile': async ({ profileId, label }) => auth.renameProfile(profileId, label),
diff --git a/src/main/model/core-agent/external-providers.ts b/src/main/model/core-agent/external-providers.ts
index cbdab439..f79174d6 100644
--- a/src/main/model/core-agent/external-providers.ts
+++ b/src/main/model/core-agent/external-providers.ts
@@ -38,10 +38,12 @@
import type { LLMProvider } from '#core-agent';
import type { Model } from '@earendil-works/pi-ai';
+import { isBearerTokenHeaderSafe } from '../../util/http-authorization';
import {
curatedModelsFor,
type CustomOpenAICompatibleRuntimeConfig,
} from '../provider_catalog';
+import { repairOpenAIToolMessageOrder } from './openai-payload';
// core-agent is an ESM package and the Orkas main process is CJS, so
// **static import is not allowed**. Reuse the dynamic-import + lazy cache
@@ -59,6 +61,35 @@ function configuredPositiveInteger(value: number | undefined, fallback: number):
: fallback;
}
+/**
+ * OpenAI-compatible endpoints do not expose a portable capability-discovery
+ * API. Treat unknown custom models as multimodal so attached images reach new
+ * models without a client release, while retaining a narrow list of official
+ * DeepSeek aliases that are documented as text-only. Dated snapshots and the
+ * official `[1m]` alias share the same capability; names containing an
+ * explicit vision variant intentionally do not match.
+ */
+const KNOWN_TEXT_ONLY_OPENAI_COMPATIBLE_MODELS = [
+ /^deepseek-(?:chat|reasoner)$/i,
+ /^deepseek-v4-(?:pro|flash)(?:-\d{4,8})?(?:\[[^\]]+\])?$/i,
+];
+
+function openAICompatibleModelSupportsImages(
+ modelId: string,
+ declared: boolean | undefined,
+ unknownDefault: boolean,
+): boolean {
+ const leafId = String(modelId || '').trim().split('/').pop()?.split(':', 1)[0] || '';
+ if (KNOWN_TEXT_ONLY_OPENAI_COMPATIBLE_MODELS.some((pattern) => pattern.test(leafId))) {
+ return false;
+ }
+ return declared ?? unknownDefault;
+}
+
+export function repairOpenAICompatiblePayload(params: unknown): unknown {
+ return repairOpenAIToolMessageOrder(params);
+}
+
// ── Moonshot open-platform (https://api.moonshot.cn/v1) ─────────────────
const MOONSHOT_BASE_URL = 'https://api.moonshot.cn/v1';
@@ -186,24 +217,27 @@ export async function createMoonshotProvider(config: CreateMoonshotProviderConfi
const DEEPSEEK_BASE_URL = 'https://api.deepseek.com/v1';
// Context windows from https://api-docs.deepseek.com/quick_start/pricing
-// (checked 2026-04). DeepSeek V4 series introduced 1M-token context via
+// (checked 2026-08). DeepSeek V4 series introduced 1M-token context via
// Compressed Sparse Attention. Fallback 131072 for unknown ids (safe lower
// bound; older deprecated v3 snapshots top out there).
const DEEPSEEK_CONTEXT_WINDOW: Record<string, number> = {
- 'deepseek-v4-pro': 1_048_576,
- 'deepseek-v4-flash': 1_048_576,
+ 'deepseek-v4-pro': 1_048_576,
+ 'deepseek-v4-flash-vision-exp': 1_048_576,
+ 'deepseek-v4-flash': 1_048_576,
};
function deepseekContextWindow(modelId: string): number {
return DEEPSEEK_CONTEXT_WINDOW[modelId] ?? 131072;
}
-// V4 reasoner series streams long reasoning + final answer; 32K matches
-// pi-ai's clamp ceiling in simple-options. Older `deepseek-chat` /
-// `deepseek-reasoner` and unknown ids fall back to the conservative 8192.
+// The official V4 pricing/spec table lists a 384K maximum output for Pro,
+// Flash, and Flash Vision Exp. pi-ai clamps only against remaining context,
+// so preserving the provider's real cap avoids silently truncating long
+// reasoning + answers. Unknown/legacy ids retain a conservative 8192 fallback.
const DEEPSEEK_MAX_OUTPUT_TOKENS: Record<string, number> = {
- 'deepseek-v4-pro': 32768,
- 'deepseek-v4-flash': 16384,
+ 'deepseek-v4-pro': 384_000,
+ 'deepseek-v4-flash-vision-exp': 384_000,
+ 'deepseek-v4-flash': 384_000,
};
function deepseekMaxOutputTokens(modelId: string): number {
@@ -212,6 +246,9 @@ function deepseekMaxOutputTokens(modelId: string): number {
export function buildDeepSeekModel(modelId: string): Model<'openai-completions'> {
const curated = curatedModelsFor('deepseek').find((m) => m.id === modelId);
+ const configuredVision = typeof curated?.maxInputImages === 'number'
+ ? curated.maxInputImages > 0
+ : undefined;
return {
id: modelId,
name: curated?.name || modelId,
@@ -229,10 +266,14 @@ export function buildDeepSeekModel(modelId: string): Model<'openai-completions'>
// true, paired with `defaultReasoning: 'low'` below so the request
// always carries the effort field.
reasoning: /^deepseek-v4-/.test(modelId),
- input: ['text'],
+ // Official Pro/Flash aliases remain text-only. Flash Vision Exp opts into
+ // image input through its public catalog capability metadata.
+ input: openAICompatibleModelSupportsImages(modelId, configuredVision, false)
+ ? ['text', 'image']
+ : ['text'],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
- contextWindow: deepseekContextWindow(modelId),
- maxTokens: deepseekMaxOutputTokens(modelId),
+ contextWindow: configuredPositiveInteger(curated?.contextWindow, deepseekContextWindow(modelId)),
+ maxTokens: configuredPositiveInteger(curated?.maxTokens, deepseekMaxOutputTokens(modelId)),
};
}
@@ -388,15 +429,17 @@ export function buildCustomOpenAICompatibleModel(
api: 'openai-completions',
provider: 'custom' as any,
baseUrl: config.baseUrl,
- reasoning: false,
- input: ['text'],
+ reasoning: config.supportsReasoning ?? !!config.reasoningEffort,
+ input: openAICompatibleModelSupportsImages(modelId, config.supportsVision, true)
+ ? ['text', 'image']
+ : ['text'],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: config.contextWindow,
maxTokens: config.maxTokens,
compat: {
supportsDeveloperRole: false,
supportsStore: false,
- supportsReasoningEffort: false,
+ supportsReasoningEffort: !!config.reasoningEffort,
supportsStrictMode: false,
maxTokensField: 'max_tokens',
},
@@ -407,6 +450,14 @@ export async function createCustomOpenAICompatibleProvider(
config: CreateCustomOpenAICompatibleProviderConfig,
): Promise<LLMProvider> {
if (!config.apiKey) throw new Error('custom: apiKey required');
+ if (!isBearerTokenHeaderSafe(config.apiKey)) {
+ throw Object.assign(
+ new Error(
+ 'Custom model has an invalid API key for HTTP Authorization headers. Re-enter it in Settings.',
+ ),
+ { code: 'CUSTOM_API_KEY_INVALID' },
+ );
+ }
if (!config.modelId) throw new Error('custom: modelId required');
if (!config.baseUrl) throw new Error('custom: baseUrl required');
const mod = await ca();
@@ -414,5 +465,7 @@ export async function createCustomOpenAICompatibleProvider(
provider: 'custom',
apiKey: config.apiKey,
customModel: buildCustomOpenAICompatibleModel(config.modelId, config),
+ onPayload: repairOpenAICompatiblePayload,
+ ...(config.reasoningEffort ? { defaultReasoning: config.reasoningEffort } : {}),
});
}
diff --git a/src/main/model/provider_catalog.ts b/src/main/model/provider_catalog.ts
index 6b464141..46029cc6 100644
--- a/src/main/model/provider_catalog.ts
+++ b/src/main/model/provider_catalog.ts
@@ -657,7 +657,8 @@ export interface CustomOpenAICompatibleRuntimeConfig {
baseUrl: string;
contextWindow: number;
maxTokens: number;
- /** Curated capability metadata; omitted custom profiles stay conservative. */
+ /** Curated capability metadata. Vision defaults on for unknown custom
+ * models; false explicitly disables image blocks. */
supportsReasoning?: boolean;
supportsVision?: boolean;
/** Optional OpenAI-compatible reasoning effort for curated relay profiles. */
diff --git a/src/main/model/public_model_catalog.ts b/src/main/model/public_model_catalog.ts
index bc2a50f0..345a2515 100644
--- a/src/main/model/public_model_catalog.ts
+++ b/src/main/model/public_model_catalog.ts
@@ -80,6 +80,7 @@ export const PUBLIC_PROVIDER_MODELS: Readonly<Record<string, readonly ProviderMo
],
deepseek: [
{ id: 'deepseek-v4-pro', name: 'DeepSeek V4 Pro', contextWindow: 1_048_576, maxTokens: 384_000 },
+ { id: 'deepseek-v4-flash-vision-exp', name: 'DeepSeek V4 Flash Vision', contextWindow: 1_048_576, maxTokens: 384_000, maxInputImages: 600 },
{ id: 'deepseek-v4-flash', name: 'DeepSeek V4 Flash', contextWindow: 1_048_576, maxTokens: 384_000 },
],
doubao: [
diff --git a/test/main/features/auth.test.ts b/test/main/features/auth.test.ts
index 52767d0a..89129ed4 100644
--- a/test/main/features/auth.test.ts
+++ b/test/main/features/auth.test.ts
@@ -386,6 +386,23 @@ describe('auth › custom OpenAI-compatible model configuration', () => {
});
});
+ it('preserves an explicit text-only override for a custom model', async () => {
+ const a = await import('../../../src/main/features/auth');
+ const added = await a.addCustomModelEntry({
+ baseUrl: 'https://gateway.example.test/v1',
+ model: 'acme/text-only',
+ apiKey: 'sk-custom-text-only-xxxxxxxx',
+ supportsVision: false,
+ });
+
+ expect(await a.pickChatEntryGroup()).toEqual([
+ expect.objectContaining({
+ entryId: added.entryId,
+ customConfig: expect.objectContaining({ supportsVision: false }),
+ }),
+ ]);
+ });
+
it('assigns provider-local labels when the optional label is blank', async () => {
const a = await import('../../../src/main/features/auth');
const first = await a.addCustomModelEntry({
diff --git a/test/main/model/core-agent/external-providers.test.ts b/test/main/model/core-agent/external-providers.test.ts
index 5dd4d044..a618b98f 100644
--- a/test/main/model/core-agent/external-providers.test.ts
+++ b/test/main/model/core-agent/external-providers.test.ts
@@ -1,9 +1,87 @@
import { describe, it, expect } from 'vitest';
import {
+ buildCustomOpenAICompatibleModel,
+ buildDeepSeekModel,
buildDoubaoModel,
buildMoonshotModel,
createMoonshotProvider,
} from '../../../../src/main/model/core-agent/external-providers';
+import { modelInputImageLimit } from '../../../../src/main/model/provider_catalog';
+
+describe('external-providers › custom OpenAI-compatible model', () => {
+ const runtimeConfig = {
+ baseUrl: 'https://gateway.example.test/v1',
+ contextWindow: 262_144,
+ maxTokens: 16_384,
+ };
+
+ it('defaults unknown models to image input and preserves explicit text-only overrides', () => {
+ expect(buildCustomOpenAICompatibleModel('acme/reasoner-v2', runtimeConfig)).toMatchObject({
+ reasoning: false,
+ input: ['text', 'image'],
+ contextWindow: 262_144,
+ maxTokens: 16_384,
+ });
+ expect(buildCustomOpenAICompatibleModel('acme/text-only', {
+ ...runtimeConfig,
+ supportsVision: false,
+ }).input).toEqual(['text']);
+ });
+
+ it('keeps documented DeepSeek text aliases text-only without hiding vision variants', () => {
+ for (const modelId of [
+ 'deepseek-chat',
+ 'deepseek-reasoner',
+ 'deepseek-v4-flash',
+ 'deepseek-v4-pro[1m]',
+ 'deepseek/deepseek-v4-flash-0731',
+ ]) {
+ expect(buildCustomOpenAICompatibleModel(modelId, {
+ ...runtimeConfig,
+ supportsVision: true,
+ }).input).toEqual(['text']);
+ }
+ expect(buildCustomOpenAICompatibleModel(
+ 'deepseek-v4-flash-vision-exp',
+ runtimeConfig,
+ ).input).toEqual(['text', 'image']);
+ });
+
+ it('carries explicit reasoning controls into the custom adapter contract', () => {
+ expect(buildCustomOpenAICompatibleModel('acme/reasoner-v2', {
+ ...runtimeConfig,
+ supportsReasoning: true,
+ reasoningEffort: 'medium',
+ })).toMatchObject({
+ reasoning: true,
+ compat: { supportsReasoningEffort: true },
+ });
+ });
+});
+
+describe('external-providers › DeepSeek model capabilities', () => {
+ it('uses official V4 limits and keeps the text aliases text-only', () => {
+ for (const modelId of ['deepseek-v4-pro', 'deepseek-v4-flash']) {
+ expect(buildDeepSeekModel(modelId)).toMatchObject({
+ id: modelId,
+ input: ['text'],
+ contextWindow: 1_048_576,
+ maxTokens: 384_000,
+ });
+ }
+ });
+
+ it('enables image input for DeepSeek V4 Flash Vision', () => {
+ const model = buildDeepSeekModel('deepseek-v4-flash-vision-exp');
+ expect(model).toMatchObject({
+ name: 'DeepSeek V4 Flash Vision',
+ input: ['text', 'image'],
+ contextWindow: 1_048_576,
+ maxTokens: 384_000,
+ });
+ expect(modelInputImageLimit('deepseek', 'deepseek-v4-flash-vision-exp', model)).toBe(20);
+ });
+});
describe('external-providers › buildMoonshotModel', () => {
it('builds a Model for https://api.moonshot.cn/v1 using openai-completions', () => {
diff --git a/test/main/model/public_model_catalog.test.ts b/test/main/model/public_model_catalog.test.ts
index 2fa2b13d..6b187b79 100644
--- a/test/main/model/public_model_catalog.test.ts
+++ b/test/main/model/public_model_catalog.test.ts
@@ -47,6 +47,19 @@ describe('public model catalog', () => {
]);
});
+ it('publishes the DeepSeek V4 vision model with its official limits', () => {
+ expect(PUBLIC_PROVIDER_MODELS.deepseek?.map((model) => model.id)).toEqual([
+ 'deepseek-v4-pro',
+ 'deepseek-v4-flash-vision-exp',
+ 'deepseek-v4-flash',
+ ]);
+ expect(PUBLIC_PROVIDER_MODELS.deepseek?.[1]).toMatchObject({
+ contextWindow: 1_048_576,
+ maxTokens: 384_000,
+ maxInputImages: 600,
+ });
+ });
+
it('keeps the explicitly curated OpenRouter shortcut set', () => {
expect(PUBLIC_PROVIDER_MODELS.openrouter?.map((model) => model.id)).toEqual([
'anthropic/claude-opus-5',