File tree Expand file tree Collapse file tree 6 files changed +49
-2
lines changed Expand file tree Collapse file tree 6 files changed +49
-2
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import { ApiStream } from "./transform/stream"
2020import { UnboundHandler } from "./providers/unbound"
2121import { RequestyHandler } from "./providers/requesty"
2222import { HumanRelayHandler } from "./providers/human-relay"
23+ import { FakeAIHandler } from "./providers/fake-ai"
2324
2425export interface SingleCompletionHandler {
2526 completePrompt ( prompt : string ) : Promise < string >
@@ -75,6 +76,8 @@ export function buildApiHandler(configuration: ApiConfiguration): ApiHandler {
7576 return new RequestyHandler ( options )
7677 case "human-relay" :
7778 return new HumanRelayHandler ( options )
79+ case "fake-ai" :
80+ return new FakeAIHandler ( options )
7881 default :
7982 return new AnthropicHandler ( options )
8083 }
Original file line number Diff line number Diff line change 1+ import { Anthropic } from "@anthropic-ai/sdk"
2+ import { ApiHandler , SingleCompletionHandler } from ".."
3+ import { ApiHandlerOptions , ModelInfo } from "../../shared/api"
4+ import { ApiStream } from "../transform/stream"
5+
6+ interface FakeAI {
7+ createMessage ( systemPrompt : string , messages : Anthropic . Messages . MessageParam [ ] ) : ApiStream
8+ getModel ( ) : { id : string ; info : ModelInfo }
9+ countTokens ( content : Array < Anthropic . Messages . ContentBlockParam > ) : Promise < number >
10+ completePrompt ( prompt : string ) : Promise < string >
11+ }
12+
13+ export class FakeAIHandler implements ApiHandler , SingleCompletionHandler {
14+ private ai : FakeAI
15+
16+ constructor ( options : ApiHandlerOptions ) {
17+ if ( ! options . fakeAi ) {
18+ throw new Error ( "Fake AI is not set" )
19+ }
20+
21+ this . ai = options . fakeAi as FakeAI
22+ }
23+
24+ async * createMessage ( systemPrompt : string , messages : Anthropic . Messages . MessageParam [ ] ) : ApiStream {
25+ yield * this . ai . createMessage ( systemPrompt , messages )
26+ }
27+
28+ getModel ( ) : { id : string ; info : ModelInfo } {
29+ return this . ai . getModel ( )
30+ }
31+
32+ countTokens ( content : Array < Anthropic . Messages . ContentBlockParam > ) : Promise < number > {
33+ return this . ai . countTokens ( content )
34+ }
35+
36+ completePrompt ( prompt : string ) : Promise < string > {
37+ return this . ai . completePrompt ( prompt )
38+ }
39+ }
Original file line number Diff line number Diff line change @@ -254,6 +254,7 @@ export type GlobalStateKey =
254254 | "showRooIgnoredFiles"
255255 | "remoteBrowserEnabled"
256256 | "language"
257+ | "fakeAi"
257258
258259export type ConfigurationKey = GlobalStateKey | SecretKey
259260
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ export type ApiProvider =
1717 | "unbound"
1818 | "requesty"
1919 | "human-relay"
20+ | "fake-ai"
2021
2122export interface ApiHandlerOptions {
2223 apiModelId ?: string
@@ -76,6 +77,7 @@ export interface ApiHandlerOptions {
7677 modelTemperature ?: number | null
7778 modelMaxTokens ?: number
7879 modelMaxThinkingTokens ?: number
80+ fakeAi ?: unknown
7981}
8082
8183export type ApiConfiguration = ApiHandlerOptions & {
@@ -134,6 +136,7 @@ export const API_CONFIG_KEYS: GlobalStateKey[] = [
134136 "modelTemperature" ,
135137 "modelMaxTokens" ,
136138 "modelMaxThinkingTokens" ,
139+ "fakeAi" ,
137140]
138141
139142// Models
Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ import { SECRET_KEYS } from "./globalState"
44export function checkExistKey ( config : ApiConfiguration | undefined ) {
55 if ( ! config ) return false
66
7- // Special case for human-relay provider which doesn 't need any configuration
8- if ( config . apiProvider === "human-relay" ) {
7+ // Special case for human-relay and fake-ai providers which don 't need any configuration
8+ if ( config . apiProvider === "human-relay" || config . apiProvider === "fake-ai" ) {
99 return true
1010 }
1111
Original file line number Diff line number Diff line change @@ -122,6 +122,7 @@ export const GLOBAL_STATE_KEYS = [
122122 "remoteBrowserEnabled" ,
123123 "language" ,
124124 "maxWorkspaceFiles" ,
125+ "fakeAi" ,
125126] as const
126127
127128export const PASS_THROUGH_STATE_KEYS = [ "taskHistory" ] as const
You can’t perform that action at this time.
0 commit comments