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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@
"install-webview": "cd webview-ui && npm install",
"install-e2e": "cd e2e && npm install",
"lint": "npm-run-all -l -p lint:*",
"lint:extension": "eslint src/**/*.ts",
"lint:extension": "eslint src --ext .ts",
"lint:webview": "cd webview-ui && npm run lint",
"lint:e2e": "cd e2e && npm run lint",
"check-types": "npm-run-all -l -p check-types:*",
Expand Down
22 changes: 1 addition & 21 deletions src/__mocks__/fs/promises.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,6 @@ const baseTestDirs = [
"/test/log/path",
]

// Helper function to format instructions
const formatInstructions = (sections: string[]): string => {
const joinedSections = sections.filter(Boolean).join("\n\n")
return joinedSections
? `
====

USER'S CUSTOM INSTRUCTIONS

The following additional instructions are provided by the user, and should be followed to the best of your ability without interfering with the TOOL USE guidelines.

${joinedSections}`
: ""
}

// Helper function to format rule content
const formatRuleContent = (ruleFile: string, content: string): string => {
return `Rules:\n# Rules from ${ruleFile}:\n${content}`
}

type RuleFiles = {
".clinerules-code": string
".clinerules-ask": string
Expand All @@ -65,7 +45,7 @@ const ensureDirectoryExists = (path: string) => {
}

const mockFs = {
readFile: jest.fn().mockImplementation(async (filePath: string, encoding?: string) => {
readFile: jest.fn().mockImplementation(async (filePath: string, _encoding?: string) => {
// Return stored content if it exists
if (mockFiles.has(filePath)) {
return mockFiles.get(filePath)
Expand Down
6 changes: 3 additions & 3 deletions src/__mocks__/services/ripgrep/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @param vscodeAppRoot - Optional VSCode app root path (can be undefined)
* @returns Promise resolving to a mock path to the ripgrep binary
*/
export const getBinPath = jest.fn().mockImplementation(async (vscodeAppRoot?: string): Promise<string> => {
export const getBinPath = jest.fn().mockImplementation(async (_vscodeAppRoot?: string): Promise<string> => {
return "/mock/path/to/rg"
})

Expand All @@ -30,7 +30,7 @@ export const getBinPath = jest.fn().mockImplementation(async (vscodeAppRoot?: st
export const regexSearchFiles = jest
.fn()
.mockImplementation(
async (cwd?: string, directoryPath?: string, regex?: string, filePattern?: string): Promise<string> => {
async (_cwd?: string, _directoryPath?: string, _regex?: string, _filePattern?: string): Promise<string> => {
return "Mock search results"
},
)
Expand All @@ -43,6 +43,6 @@ export const regexSearchFiles = jest
* @param maxLength - Optional maximum length (can be undefined)
* @returns The original line or empty string if undefined
*/
export const truncateLine = jest.fn().mockImplementation((line?: string, maxLength?: number): string => {
export const truncateLine = jest.fn().mockImplementation((line?: string, _maxLength?: number): string => {
return line || ""
})
2 changes: 1 addition & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function buildApiHandler(configuration: ApiConfiguration): ApiHandler {
case "requesty":
return new RequestyHandler(options)
case "human-relay":
return new HumanRelayHandler(options)
return new HumanRelayHandler()
case "fake-ai":
return new FakeAIHandler(options)
case "xai":
Expand Down
8 changes: 4 additions & 4 deletions src/api/providers/__tests__/bedrock-custom-arn.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// npx jest src/api/providers/__tests__/bedrock-custom-arn.test.ts

import { AwsBedrockHandler } from "../bedrock"
import { ApiHandlerOptions } from "../../../shared/api"
import { logger } from "../../../utils/logging"
Expand Down Expand Up @@ -52,9 +54,6 @@ jest.mock("@aws-sdk/client-bedrock-runtime", () => {
}
})

// Get mock module for testing
const bedrockMock = jest.requireMock("@aws-sdk/client-bedrock-runtime").__mock

describe("Bedrock ARN Handling", () => {
// Helper function to create a handler with specific options
const createHandler = (options: Partial<ApiHandlerOptions> = {}) => {
Expand Down Expand Up @@ -236,7 +235,8 @@ describe("Bedrock ARN Handling", () => {
// Create handler with ARN region different from provided region
const arn =
"arn:aws:bedrock:eu-west-1:123456789012:inference-profile/anthropic.claude-3-sonnet-20240229-v1:0"
const handler = createHandler({

createHandler({
awsCustomArn: arn,
awsRegion: "us-east-1", // Different from ARN region
})
Expand Down
22 changes: 6 additions & 16 deletions src/api/providers/__tests__/bedrock-invokedModelId.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// npx jest src/api/providers/__tests__/bedrock-invokedModelId.test.ts

import { ApiHandlerOptions } from "../../../shared/api"

import { AwsBedrockHandler, StreamEvent } from "../bedrock"

// Mock AWS SDK credential providers and Bedrock client
jest.mock("@aws-sdk/credential-providers", () => ({
fromIni: jest.fn().mockReturnValue({
Expand Down Expand Up @@ -62,11 +68,6 @@ jest.mock("@aws-sdk/client-bedrock-runtime", () => {
}
})

import { AwsBedrockHandler, StreamEvent } from "../bedrock"
import { ApiHandlerOptions } from "../../../shared/api"
import { BedrockRuntimeClient } from "@aws-sdk/client-bedrock-runtime"
const { fromIni } = require("@aws-sdk/credential-providers")

describe("AwsBedrockHandler with invokedModelId", () => {
let mockSend: jest.Mock

Expand Down Expand Up @@ -279,17 +280,6 @@ describe("AwsBedrockHandler with invokedModelId", () => {
}
})

// Mock getModel to return expected values
const getModelSpy = jest.spyOn(handler, "getModel").mockReturnValue({
id: "anthropic.claude-3-5-sonnet-20241022-v2:0",
info: {
maxTokens: 4096,
contextWindow: 128_000,
supportsPromptCache: false,
supportsImages: true,
},
})

// Create a message generator
const messageGenerator = handler.createMessage("system prompt", [{ role: "user", content: "user message" }])

Expand Down
5 changes: 1 addition & 4 deletions src/api/providers/__tests__/bedrock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ jest.mock("@aws-sdk/client-bedrock-runtime", () => ({
}))

import { AwsBedrockHandler } from "../bedrock"
import { MessageContent } from "../../../shared/api"
import { BedrockRuntimeClient, ConverseStreamCommand } from "@aws-sdk/client-bedrock-runtime"

import { Anthropic } from "@anthropic-ai/sdk"
const { fromIni } = require("@aws-sdk/credential-providers")
import { logger } from "../../../utils/logging"

describe("AwsBedrockHandler", () => {
let handler: AwsBedrockHandler
Expand Down
2 changes: 1 addition & 1 deletion src/api/providers/__tests__/gemini.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe("GeminiHandler", () => {
const stream = handler.createMessage(systemPrompt, mockMessages)

await expect(async () => {
for await (const chunk of stream) {
for await (const _chunk of stream) {
// Should throw before yielding any chunks
}
}).rejects.toThrow()
Expand Down
6 changes: 3 additions & 3 deletions src/api/providers/__tests__/lmstudio.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Anthropic } from "@anthropic-ai/sdk"

import { LmStudioHandler } from "../lmstudio"
import { ApiHandlerOptions } from "../../../shared/api"
import OpenAI from "openai"
import { Anthropic } from "@anthropic-ai/sdk"

// Mock OpenAI client
const mockCreate = jest.fn()
Expand Down Expand Up @@ -120,7 +120,7 @@ describe("LmStudioHandler", () => {
const stream = handler.createMessage(systemPrompt, messages)

await expect(async () => {
for await (const chunk of stream) {
for await (const _chunk of stream) {
// Should not reach here
}
}).rejects.toThrow("Please check the LM Studio developer logs to debug what went wrong")
Expand Down
7 changes: 4 additions & 3 deletions src/api/providers/__tests__/mistral.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { MistralHandler } from "../mistral"
import { ApiHandlerOptions, mistralDefaultModelId } from "../../../shared/api"
import { Anthropic } from "@anthropic-ai/sdk"

import { MistralHandler } from "../mistral"
import { ApiHandlerOptions } from "../../../shared/api"
import { ApiStreamTextChunk } from "../../transform/stream"

// Mock Mistral client
Expand All @@ -9,7 +10,7 @@ jest.mock("@mistralai/mistralai", () => {
return {
Mistral: jest.fn().mockImplementation(() => ({
chat: {
stream: mockCreate.mockImplementation(async (options) => {
stream: mockCreate.mockImplementation(async (_options) => {
const stream = {
[Symbol.asyncIterator]: async function* () {
yield {
Expand Down
6 changes: 3 additions & 3 deletions src/api/providers/__tests__/ollama.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Anthropic } from "@anthropic-ai/sdk"

import { OllamaHandler } from "../ollama"
import { ApiHandlerOptions } from "../../../shared/api"
import OpenAI from "openai"
import { Anthropic } from "@anthropic-ai/sdk"

// Mock OpenAI client
const mockCreate = jest.fn()
Expand Down Expand Up @@ -120,7 +120,7 @@ describe("OllamaHandler", () => {
const stream = handler.createMessage(systemPrompt, messages)

await expect(async () => {
for await (const chunk of stream) {
for await (const _chunk of stream) {
// Should not reach here
}
}).rejects.toThrow("API Error")
Expand Down
6 changes: 3 additions & 3 deletions src/api/providers/__tests__/openai-native.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Anthropic } from "@anthropic-ai/sdk"

import { OpenAiNativeHandler } from "../openai-native"
import { ApiHandlerOptions } from "../../../shared/api"
import OpenAI from "openai"
import { Anthropic } from "@anthropic-ai/sdk"

// Mock OpenAI client
const mockCreate = jest.fn()
Expand Down Expand Up @@ -116,7 +116,7 @@ describe("OpenAiNativeHandler", () => {
mockCreate.mockRejectedValueOnce(new Error("API Error"))
const stream = handler.createMessage(systemPrompt, messages)
await expect(async () => {
for await (const chunk of stream) {
for await (const _chunk of stream) {
// Should not reach here
}
}).rejects.toThrow("API Error")
Expand Down
4 changes: 2 additions & 2 deletions src/api/providers/__tests__/openai.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ describe("OpenAiHandler", () => {
const stream = handler.createMessage("system prompt", testMessages)

await expect(async () => {
for await (const chunk of stream) {
for await (const _chunk of stream) {
// Should not reach here
}
}).rejects.toThrow("API Error")
Expand All @@ -191,7 +191,7 @@ describe("OpenAiHandler", () => {
const stream = handler.createMessage("system prompt", testMessages)

await expect(async () => {
for await (const chunk of stream) {
for await (const _chunk of stream) {
// Should not reach here
}
}).rejects.toThrow("Rate limit exceeded")
Expand Down
6 changes: 2 additions & 4 deletions src/api/providers/__tests__/requesty.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Anthropic } from "@anthropic-ai/sdk"
import OpenAI from "openai"
import { ApiHandlerOptions, ModelInfo, requestyDefaultModelInfo } from "../../../shared/api"
import { ApiHandlerOptions, ModelInfo } from "../../../shared/api"
import { RequestyHandler } from "../requesty"
import { convertToOpenAiMessages } from "../../transform/openai-format"
import { convertToR1Format } from "../../transform/r1-format"
Expand Down Expand Up @@ -40,9 +40,7 @@ describe("RequestyHandler", () => {
jest.clearAllMocks()

// Setup mock create function that preserves params
let lastParams: any
mockCreate = jest.fn().mockImplementation((params) => {
lastParams = params
mockCreate = jest.fn().mockImplementation((_params) => {
return {
[Symbol.asyncIterator]: async function* () {
yield {
Expand Down
3 changes: 1 addition & 2 deletions src/api/providers/__tests__/vertex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { Anthropic } from "@anthropic-ai/sdk"
import { AnthropicVertex } from "@anthropic-ai/vertex-sdk"
import { BetaThinkingConfigParam } from "@anthropic-ai/sdk/resources/beta"

import { VertexHandler } from "../vertex"
import { ApiStreamChunk } from "../../transform/stream"
Expand Down Expand Up @@ -388,7 +387,7 @@ describe("VertexHandler", () => {
const stream = handler.createMessage(systemPrompt, mockMessages)

await expect(async () => {
for await (const chunk of stream) {
for await (const _chunk of stream) {
// Should throw before yielding any chunks
}
}).rejects.toThrow("Vertex API error")
Expand Down
2 changes: 1 addition & 1 deletion src/api/providers/__tests__/vscode-lm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jest.mock("vscode", () => {

return {
workspace: {
onDidChangeConfiguration: jest.fn((callback) => ({
onDidChangeConfiguration: jest.fn((_callback) => ({
dispose: jest.fn(),
})),
},
Expand Down
7 changes: 4 additions & 3 deletions src/api/providers/bedrock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,8 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
// Look for a pattern where the first segment before a dot doesn't contain dots or colons
// and the remaining parts still contain at least one dot
const genericPrefixMatch = modelId.match(/^([^.:]+)\.(.+\..+)$/)

if (genericPrefixMatch) {
const genericPrefix = genericPrefixMatch[1] + "."
return genericPrefixMatch[2]
}
}
Expand Down Expand Up @@ -708,10 +708,11 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
if (Array.isArray(content)) {
return content.map((block) => {
// Use destructuring to remove cachePoint property
const { cachePoint, ...rest } = block
const { cachePoint: _, ...rest } = block
return rest
})
}

return content
}

Expand Down Expand Up @@ -864,7 +865,7 @@ Suggestions:
/**
* Formats an error message based on the error type and context
*/
private formatErrorMessage(error: unknown, errorType: string, isStreamContext: boolean): string {
private formatErrorMessage(error: unknown, errorType: string, _isStreamContext: boolean): string {
const definition = AwsBedrockHandler.ERROR_TYPES[errorType] || AwsBedrockHandler.ERROR_TYPES.GENERIC
let template = definition.messageTemplate

Expand Down
1 change: 0 additions & 1 deletion src/api/providers/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
type GenerateContentResponseUsageMetadata,
type GenerateContentParameters,
type Content,
CreateCachedContentConfig,
} from "@google/genai"
import NodeCache from "node-cache"

Expand Down
24 changes: 6 additions & 18 deletions src/api/providers/human-relay.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
// filepath: e:\Project\Roo-Code\src\api\providers\human-relay.ts
import { Anthropic } from "@anthropic-ai/sdk"
import { ApiHandlerOptions, ModelInfo } from "../../shared/api"
import * as vscode from "vscode"

import { ModelInfo } from "../../shared/api"
import { ApiHandler, SingleCompletionHandler } from "../index"
import { ApiStream } from "../transform/stream"
import * as vscode from "vscode"
import { ExtensionMessage } from "../../shared/ExtensionMessage"
import { getPanel } from "../../activate/registerCommands" // Import the getPanel function

/**
* Human Relay API processor
* This processor does not directly call the API, but interacts with the model through human operations copy and paste.
*/
export class HumanRelayHandler implements ApiHandler, SingleCompletionHandler {
private options: ApiHandlerOptions

constructor(options: ApiHandlerOptions) {
this.options = options
}
countTokens(content: Array<Anthropic.Messages.ContentBlockParam>): Promise<number> {
countTokens(_content: Array<Anthropic.Messages.ContentBlockParam>): Promise<number> {
return Promise.resolve(0)
}

Expand Down Expand Up @@ -125,15 +118,10 @@ async function showHumanRelayDialog(promptText: string): Promise<string | undefi
vscode.commands.executeCommand(
"roo-cline.registerHumanRelayCallback",
requestId,
(response: string | undefined) => {
resolve(response)
},
(response: string | undefined) => resolve(response),
)

// Open the dialog box directly using the current panel
vscode.commands.executeCommand("roo-cline.showHumanRelayDialog", {
requestId,
promptText,
})
vscode.commands.executeCommand("roo-cline.showHumanRelayDialog", { requestId, promptText })
})
}
Loading
Loading