2
0
Эх сурвалжийг харах

Fake AI provider (#1769)

* Fake AI

* Do not show Fake AI in Roo-Code settings

* Rename providers/fake-provider.ts to providers/fake-ai.ts
Wojciech Kordalski 9 сар өмнө
parent
commit
499b8e4665

+ 3 - 0
src/api/index.ts

@@ -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>
@@ -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)
 	}

+ 39 - 0
src/api/providers/fake-ai.ts

@@ -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 - 0
src/exports/roo-code.d.ts

@@ -254,6 +254,7 @@ export type GlobalStateKey =
 	| "showRooIgnoredFiles"
 	| "remoteBrowserEnabled"
 	| "language"
+	| "fakeAi"
 
 export type ConfigurationKey = GlobalStateKey | SecretKey
 

+ 3 - 0
src/shared/api.ts

@@ -17,6 +17,7 @@ export type ApiProvider =
 	| "unbound"
 	| "requesty"
 	| "human-relay"
+	| "fake-ai"
 
 export interface ApiHandlerOptions {
 	apiModelId?: string
@@ -76,6 +77,7 @@ export interface ApiHandlerOptions {
 	modelTemperature?: number | null
 	modelMaxTokens?: number
 	modelMaxThinkingTokens?: number
+	fakeAi?: unknown
 }
 
 export type ApiConfiguration = ApiHandlerOptions & {
@@ -134,6 +136,7 @@ export const API_CONFIG_KEYS: GlobalStateKey[] = [
 	"modelTemperature",
 	"modelMaxTokens",
 	"modelMaxThinkingTokens",
+	"fakeAi",
 ]
 
 // Models

+ 2 - 2
src/shared/checkExistApiConfig.ts

@@ -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
 	}
 

+ 1 - 0
src/shared/globalState.ts

@@ -122,6 +122,7 @@ export const GLOBAL_STATE_KEYS = [
 	"remoteBrowserEnabled",
 	"language",
 	"maxWorkspaceFiles",
+	"fakeAi",
 ] as const
 
 export const PASS_THROUGH_STATE_KEYS = ["taskHistory"] as const