@@ -14,6 +14,7 @@ import {
1414import { McpServer , McpTool } from "../../../../src/shared/mcp"
1515import { findLast } from "../../../../src/shared/array"
1616import { combineApiRequests } from "../../../../src/shared/combineApiRequests"
17+ import { ModelInfo , pearAiDefaultModelId , pearAiDefaultModelInfo , PEARAI_URL } from "../../../../src/shared/api"
1718import { combineCommandSequences } from "../../../../src/shared/combineCommandSequences"
1819import { getApiMetrics } from "../../../../src/shared/getApiMetrics"
1920import { useExtensionState } from "../../context/ExtensionStateContext"
@@ -463,9 +464,35 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
463464 startNewTask ( )
464465 } , [ startNewTask ] )
465466
467+ const [ pearAiModels , setPearAiModels ] = useState < Record < string , ModelInfo > > ( {
468+ [ pearAiDefaultModelId ] : pearAiDefaultModelInfo ,
469+ } )
470+
471+ // Fetch PearAI models when provider is selected
472+ useEffect ( ( ) => {
473+ if ( apiConfiguration ?. apiProvider === "pearai" ) {
474+ const fetchPearAiModels = async ( ) => {
475+ try {
476+ const res = await fetch ( `${ PEARAI_URL } /getPearAIAgentModels` )
477+ if ( ! res . ok ) throw new Error ( "Failed to fetch models" )
478+ const config = await res . json ( )
479+
480+ if ( config . models && Object . keys ( config . models ) . length > 0 ) {
481+ console . log ( "Models successfully loaded from server" )
482+ setPearAiModels ( config . models )
483+ }
484+ } catch ( error ) {
485+ console . error ( "Error fetching PearAI models:" , error )
486+ }
487+ }
488+
489+ fetchPearAiModels ( )
490+ }
491+ } , [ apiConfiguration ?. apiProvider ] )
492+
466493 const { selectedModelInfo } = useMemo ( ( ) => {
467- return normalizeApiConfiguration ( apiConfiguration )
468- } , [ apiConfiguration ] )
494+ return normalizeApiConfiguration ( apiConfiguration , pearAiModels )
495+ } , [ apiConfiguration , pearAiModels ] )
469496
470497 const selectImages = useCallback ( ( ) => {
471498 vscode . postMessage ( { type : "selectImages" } )
0 commit comments