Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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-ai"

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-ai.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
Loading