Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ApiStream } from "./transform/stream"
import { UnboundHandler } from "./providers/unbound"
import { RequestyHandler } from "./providers/requesty"
import { HumanRelayHandler } from "./providers/human-relay"
import { FakeAIHandler } from "./providers/fake-provider"

export interface SingleCompletionHandler {
completePrompt(prompt: string): Promise<string>
Expand Down Expand Up @@ -75,6 +76,8 @@ export function buildApiHandler(configuration: ApiConfiguration): ApiHandler {
return new RequestyHandler(options)
case "human-relay":
return new HumanRelayHandler(options)
case "fake-ai":
return new FakeAIHandler(options)
default:
return new AnthropicHandler(options)
}
Expand Down
39 changes: 39 additions & 0 deletions src/api/providers/fake-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Anthropic } from "@anthropic-ai/sdk"
import { ApiHandler, SingleCompletionHandler } from ".."
import { ApiHandlerOptions, ModelInfo } from "../../shared/api"
import { ApiStream } from "../transform/stream"

interface FakeAI {
createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream
getModel(): { id: string; info: ModelInfo }
countTokens(content: Array<Anthropic.Messages.ContentBlockParam>): Promise<number>
completePrompt(prompt: string): Promise<string>
}

export class FakeAIHandler implements ApiHandler, SingleCompletionHandler {
private ai: FakeAI

constructor(options: ApiHandlerOptions) {
if (!options.fakeAi) {
throw new Error("Fake AI is not set")
}

this.ai = options.fakeAi as FakeAI
}

async *createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream {
yield* this.ai.createMessage(systemPrompt, messages)
}

getModel(): { id: string; info: ModelInfo } {
return this.ai.getModel()
}

countTokens(content: Array<Anthropic.Messages.ContentBlockParam>): Promise<number> {
return this.ai.countTokens(content)
}

completePrompt(prompt: string): Promise<string> {
return this.ai.completePrompt(prompt)
}
}
1 change: 1 addition & 0 deletions src/exports/roo-code.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export type GlobalStateKey =
| "showRooIgnoredFiles"
| "remoteBrowserEnabled"
| "language"
| "fakeAi"

export type ConfigurationKey = GlobalStateKey | SecretKey

Expand Down
3 changes: 3 additions & 0 deletions src/shared/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type ApiProvider =
| "unbound"
| "requesty"
| "human-relay"
| "fake-ai"

export interface ApiHandlerOptions {
apiModelId?: string
Expand Down Expand Up @@ -76,6 +77,7 @@ export interface ApiHandlerOptions {
modelTemperature?: number | null
modelMaxTokens?: number
modelMaxThinkingTokens?: number
fakeAi?: unknown
}

export type ApiConfiguration = ApiHandlerOptions & {
Expand Down Expand Up @@ -134,6 +136,7 @@ export const API_CONFIG_KEYS: GlobalStateKey[] = [
"modelTemperature",
"modelMaxTokens",
"modelMaxThinkingTokens",
"fakeAi",
]

// Models
Expand Down
4 changes: 2 additions & 2 deletions src/shared/checkExistApiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { SECRET_KEYS } from "./globalState"
export function checkExistKey(config: ApiConfiguration | undefined) {
if (!config) return false

// Special case for human-relay provider which doesn't need any configuration
if (config.apiProvider === "human-relay") {
// Special case for human-relay and fake-ai providers which don't need any configuration
if (config.apiProvider === "human-relay" || config.apiProvider === "fake-ai") {
return true
}

Expand Down
1 change: 1 addition & 0 deletions src/shared/globalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const GLOBAL_STATE_KEYS = [
"remoteBrowserEnabled",
"language",
"maxWorkspaceFiles",
"fakeAi",
] as const

export const PASS_THROUGH_STATE_KEYS = ["taskHistory"] as const
Expand Down
1 change: 1 addition & 0 deletions webview-ui/src/components/settings/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const PROVIDERS = [
{ value: "unbound", label: "Unbound" },
{ value: "requesty", label: "Requesty" },
{ value: "human-relay", label: "Human Relay" },
{ value: "fake-ai", label: "Fake AI" },
Copy link
Collaborator

@cte cte Mar 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we hide this in the settings UI? I'm assuming this will only be used programmatically.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to hide it. My only concern would be if the fake-ai provider is set via RooCodeAPI.setConfiguration, and later the settings view is opened as part of the e2e test, wouldn't this lead to some inconsistent state and possibly the setting view "normalizing" and overwriting the config value? Although, you could just say "don't open settings during e2e tests" and that would be fine for us, since we can use setConfiguration to setup settings for a test.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can deal with this if it ever comes up in the e2e tests; for now let's optimize for not causing user confusion and hide this in the settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.
It seems that when Fake AI is set as an API provider, in the settings view the API Provider input simply shows an empty field (no API provider is selected).
Saving the settings will clear the fakeAi object that handles API requests (and thus further requests will fail until the user sets another API provider). Showing settings view without saving does not overwrite configuration.

].sort((a, b) => a.label.localeCompare(b.label))

export const AWS_REGIONS = [
Expand Down