11import { ConnectIcon } from '@/components/icons'
2- import { AuthMode , type BlockConfig } from '@/blocks/types'
2+ import { AuthMode , type BlockConfig , type SubBlockConfig } from '@/blocks/types'
33import {
4- getModelOptions ,
4+ getCustomModelOptions ,
55 getProviderCredentialSubBlocks ,
66 PROVIDER_CREDENTIAL_INPUTS ,
77} from '@/blocks/utils'
8- import { getBaseModelProviders } from '@/providers/models'
8+ import {
9+ CUSTOM_MODEL_CONFIG_DEFAULT ,
10+ CUSTOM_MODEL_CONFIG_JSON_SCHEMA ,
11+ CUSTOM_MODEL_ID ,
12+ isCustomModel ,
13+ parseCustomModelConfig ,
14+ } from '@/providers/custom-model'
15+ import { getBaseModelProviders , isAutoModel } from '@/providers/models'
916import type { ProviderId } from '@/providers/types'
1017import type { ToolResponse } from '@/tools/types'
1118
@@ -41,6 +48,47 @@ interface TargetBlock {
4148 currentState ?: any
4249}
4350
51+ function getCustomModelSubBlock ( ) : SubBlockConfig {
52+ return {
53+ id : 'customModelConfig' ,
54+ title : 'Custom Model Configuration' ,
55+ type : 'code' ,
56+ language : 'json' ,
57+ placeholder : 'Enter custom provider and model configuration...' ,
58+ description :
59+ 'Provider, model, credentials, and provider-specific generation settings for routing inference. Use provider "sim" with model "sim-auto" for automatic routing.' ,
60+ defaultValue : CUSTOM_MODEL_CONFIG_DEFAULT ,
61+ superUserOnly : true ,
62+ required : {
63+ field : 'model' ,
64+ value : CUSTOM_MODEL_ID ,
65+ } ,
66+ condition : {
67+ field : 'model' ,
68+ value : CUSTOM_MODEL_ID ,
69+ } ,
70+ }
71+ }
72+
73+ function resolveRouterTool ( params : Record < string , any > ) : string {
74+ const model = params . model || 'claude-sonnet-5'
75+ if ( ! model ) {
76+ throw new Error ( 'No model selected' )
77+ }
78+ if ( isCustomModel ( model ) ) {
79+ const customConfig = parseCustomModelConfig ( params . customModelConfig )
80+ if ( customConfig . provider !== 'sim' ) return customConfig . provider
81+
82+ return getBaseModelProviders ( ) [ 'claude-sonnet-5' ]
83+ }
84+ const lookupModel = isAutoModel ( model ) ? 'claude-sonnet-5' : model
85+ const tool = getBaseModelProviders ( ) [ lookupModel as ProviderId ]
86+ if ( ! tool ) {
87+ throw new Error ( `Invalid model selected: ${ model } ` )
88+ }
89+ return tool
90+ }
91+
4492/**
4593 * Generates the system prompt for the legacy router (block-based).
4694 */
@@ -173,8 +221,9 @@ export const RouterBlock: BlockConfig<RouterResponse> = {
173221 placeholder : 'Type or select a model...' ,
174222 required : true ,
175223 defaultValue : 'claude-sonnet-5' ,
176- options : getModelOptions ,
224+ options : getCustomModelOptions ,
177225 } ,
226+ getCustomModelSubBlock ( ) ,
178227 ...getProviderCredentialSubBlocks ( ) ,
179228 {
180229 id : 'temperature' ,
@@ -204,22 +253,17 @@ export const RouterBlock: BlockConfig<RouterResponse> = {
204253 'deepseek_reasoner' ,
205254 ] ,
206255 config : {
207- tool : ( params : Record < string , any > ) => {
208- const model = params . model || 'gpt-4o'
209- if ( ! model ) {
210- throw new Error ( 'No model selected' )
211- }
212- const tool = getBaseModelProviders ( ) [ model as ProviderId ]
213- if ( ! tool ) {
214- throw new Error ( `Invalid model selected: ${ model } ` )
215- }
216- return tool
217- } ,
256+ tool : resolveRouterTool ,
218257 } ,
219258 } ,
220259 inputs : {
221260 prompt : { type : 'string' , description : 'Routing prompt content' } ,
222261 model : { type : 'string' , description : 'AI model to use' } ,
262+ customModelConfig : {
263+ type : 'json' ,
264+ description : 'Custom provider/model execution configuration for routing inference.' ,
265+ schema : CUSTOM_MODEL_CONFIG_JSON_SCHEMA ,
266+ } ,
223267 ...PROVIDER_CREDENTIAL_INPUTS ,
224268 temperature : {
225269 type : 'number' ,
@@ -300,8 +344,9 @@ export const RouterV2Block: BlockConfig<RouterV2Response> = {
300344 placeholder : 'Type or select a model...' ,
301345 required : true ,
302346 defaultValue : 'claude-sonnet-5' ,
303- options : getModelOptions ,
347+ options : getCustomModelOptions ,
304348 } ,
349+ getCustomModelSubBlock ( ) ,
305350 ...getProviderCredentialSubBlocks ( ) ,
306351 ] ,
307352 tools : {
@@ -314,23 +359,18 @@ export const RouterV2Block: BlockConfig<RouterV2Response> = {
314359 'deepseek_reasoner' ,
315360 ] ,
316361 config : {
317- tool : ( params : Record < string , any > ) => {
318- const model = params . model || 'gpt-4o'
319- if ( ! model ) {
320- throw new Error ( 'No model selected' )
321- }
322- const tool = getBaseModelProviders ( ) [ model as ProviderId ]
323- if ( ! tool ) {
324- throw new Error ( `Invalid model selected: ${ model } ` )
325- }
326- return tool
327- } ,
362+ tool : resolveRouterTool ,
328363 } ,
329364 } ,
330365 inputs : {
331366 context : { type : 'string' , description : 'Context for routing decision' } ,
332367 routes : { type : 'json' , description : 'Route definitions with descriptions' } ,
333368 model : { type : 'string' , description : 'AI model to use' } ,
369+ customModelConfig : {
370+ type : 'json' ,
371+ description : 'Custom provider/model execution configuration for routing inference.' ,
372+ schema : CUSTOM_MODEL_CONFIG_JSON_SCHEMA ,
373+ } ,
334374 ...PROVIDER_CREDENTIAL_INPUTS ,
335375 } ,
336376 outputs : {
0 commit comments