mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 12:21:13 -05:00
Fixes
This commit is contained in:
@@ -21,6 +21,7 @@ const OpenRouterModelPicker: React.FC = () => {
|
|||||||
const dropdownListRef = useRef<HTMLDivElement>(null)
|
const dropdownListRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
const handleModelChange = (newModelId: string) => {
|
const handleModelChange = (newModelId: string) => {
|
||||||
|
// could be setting invalid model id/undefined info but validation will catch it
|
||||||
setApiConfiguration({
|
setApiConfiguration({
|
||||||
...apiConfiguration,
|
...apiConfiguration,
|
||||||
openRouterModelId: newModelId,
|
openRouterModelId: newModelId,
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
import React, { createContext, useCallback, useContext, useEffect, useState } from "react"
|
import React, { createContext, useCallback, useContext, useEffect, useState } from "react"
|
||||||
import { useEvent } from "react-use"
|
import { useEvent } from "react-use"
|
||||||
import { ExtensionMessage, ExtensionState } from "../../../src/shared/ExtensionMessage"
|
import { ExtensionMessage, ExtensionState } from "../../../src/shared/ExtensionMessage"
|
||||||
import { ApiConfiguration, ModelInfo } from "../../../src/shared/api"
|
import {
|
||||||
|
ApiConfiguration,
|
||||||
|
ModelInfo,
|
||||||
|
openRouterDefaultModelId,
|
||||||
|
openRouterDefaultModelInfo,
|
||||||
|
} from "../../../src/shared/api"
|
||||||
import { vscode } from "../utils/vscode"
|
import { vscode } from "../utils/vscode"
|
||||||
import { convertTextMateToHljs } from "../utils/textMateToHljs"
|
import { convertTextMateToHljs } from "../utils/textMateToHljs"
|
||||||
import { findLastIndex } from "../../../src/shared/array"
|
import { findLastIndex } from "../../../src/shared/array"
|
||||||
@@ -31,7 +36,9 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
|
|||||||
const [showWelcome, setShowWelcome] = useState(false)
|
const [showWelcome, setShowWelcome] = useState(false)
|
||||||
const [theme, setTheme] = useState<any>(undefined)
|
const [theme, setTheme] = useState<any>(undefined)
|
||||||
const [filePaths, setFilePaths] = useState<string[]>([])
|
const [filePaths, setFilePaths] = useState<string[]>([])
|
||||||
const [openRouterModels, setOpenRouterModels] = useState<Record<string, ModelInfo>>({})
|
const [openRouterModels, setOpenRouterModels] = useState<Record<string, ModelInfo>>({
|
||||||
|
[openRouterDefaultModelId]: openRouterDefaultModelInfo,
|
||||||
|
})
|
||||||
|
|
||||||
const handleMessage = useCallback((event: MessageEvent) => {
|
const handleMessage = useCallback((event: MessageEvent) => {
|
||||||
const message: ExtensionMessage = event.data
|
const message: ExtensionMessage = event.data
|
||||||
@@ -80,7 +87,11 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
case "openRouterModels": {
|
case "openRouterModels": {
|
||||||
setOpenRouterModels(message.openRouterModels ?? {})
|
const updatedModels = message.openRouterModels ?? {}
|
||||||
|
setOpenRouterModels({
|
||||||
|
[openRouterDefaultModelId]: openRouterDefaultModelInfo, // in case the extension sent a model list without the default model
|
||||||
|
...updatedModels,
|
||||||
|
})
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ApiConfiguration } from "../../../src/shared/api"
|
import { ApiConfiguration, openRouterDefaultModelId } from "../../../src/shared/api"
|
||||||
import { ModelInfo } from "../../../src/shared/api"
|
import { ModelInfo } from "../../../src/shared/api"
|
||||||
export function validateApiConfiguration(apiConfiguration?: ApiConfiguration): string | undefined {
|
export function validateApiConfiguration(apiConfiguration?: ApiConfiguration): string | undefined {
|
||||||
if (apiConfiguration) {
|
if (apiConfiguration) {
|
||||||
@@ -59,11 +59,12 @@ export function validateModelId(
|
|||||||
if (apiConfiguration) {
|
if (apiConfiguration) {
|
||||||
switch (apiConfiguration.apiProvider) {
|
switch (apiConfiguration.apiProvider) {
|
||||||
case "openrouter":
|
case "openrouter":
|
||||||
const modelId = apiConfiguration.openRouterModelId
|
const modelId = apiConfiguration.openRouterModelId ?? openRouterDefaultModelId // in case the user hasn't changed the model id, it will be undefined by default
|
||||||
if (!modelId) {
|
if (!modelId) {
|
||||||
return "You must provide a model ID."
|
return "You must provide a model ID."
|
||||||
}
|
}
|
||||||
if (openRouterModels && !Object.keys(openRouterModels).includes(modelId)) {
|
if (openRouterModels && !Object.keys(openRouterModels).includes(modelId)) {
|
||||||
|
// even if the model list endpoint failed, extensionstatecontext will always have the default model info
|
||||||
return "The model ID you provided is not available. Please choose a different model."
|
return "The model ID you provided is not available. Please choose a different model."
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user