Prettier backfill

This commit is contained in:
Matt Rubens
2025-01-17 14:11:28 -05:00
parent 3bcb4ff8c5
commit 60a0a824b9
174 changed files with 15715 additions and 15428 deletions

View File

@@ -94,7 +94,7 @@ export interface ExtensionState {
mode: Mode
modeApiConfigs?: Record<Mode, string>
enhancementApiConfigId?: string
experimentalDiffStrategy?: boolean
experimentalDiffStrategy?: boolean
autoApprovalEnabled?: boolean
}

View File

@@ -1,7 +1,7 @@
import { ApiConfiguration, ApiProvider } from "./api"
import { Mode, PromptComponent } from "./modes"
export type PromptMode = Mode | 'enhance'
export type PromptMode = Mode | "enhance"
export type AudioType = "notification" | "celebration" | "progress_loop"
@@ -72,7 +72,7 @@ export interface WebviewMessage {
| "getSystemPrompt"
| "systemPrompt"
| "enhancementApiConfigId"
| "experimentalDiffStrategy"
| "experimentalDiffStrategy"
| "autoApprovalEnabled"
text?: string
disabled?: boolean

View File

@@ -1,57 +1,57 @@
import { checkExistKey } from '../checkExistApiConfig';
import { ApiConfiguration } from '../api';
import { checkExistKey } from "../checkExistApiConfig"
import { ApiConfiguration } from "../api"
describe('checkExistKey', () => {
it('should return false for undefined config', () => {
expect(checkExistKey(undefined)).toBe(false);
});
describe("checkExistKey", () => {
it("should return false for undefined config", () => {
expect(checkExistKey(undefined)).toBe(false)
})
it('should return false for empty config', () => {
const config: ApiConfiguration = {};
expect(checkExistKey(config)).toBe(false);
});
it("should return false for empty config", () => {
const config: ApiConfiguration = {}
expect(checkExistKey(config)).toBe(false)
})
it('should return true when one key is defined', () => {
const config: ApiConfiguration = {
apiKey: 'test-key'
};
expect(checkExistKey(config)).toBe(true);
});
it("should return true when one key is defined", () => {
const config: ApiConfiguration = {
apiKey: "test-key",
}
expect(checkExistKey(config)).toBe(true)
})
it('should return true when multiple keys are defined', () => {
const config: ApiConfiguration = {
apiKey: 'test-key',
glamaApiKey: 'glama-key',
openRouterApiKey: 'openrouter-key'
};
expect(checkExistKey(config)).toBe(true);
});
it("should return true when multiple keys are defined", () => {
const config: ApiConfiguration = {
apiKey: "test-key",
glamaApiKey: "glama-key",
openRouterApiKey: "openrouter-key",
}
expect(checkExistKey(config)).toBe(true)
})
it('should return true when only non-key fields are undefined', () => {
const config: ApiConfiguration = {
apiKey: 'test-key',
apiProvider: undefined,
anthropicBaseUrl: undefined
};
expect(checkExistKey(config)).toBe(true);
});
it("should return true when only non-key fields are undefined", () => {
const config: ApiConfiguration = {
apiKey: "test-key",
apiProvider: undefined,
anthropicBaseUrl: undefined,
}
expect(checkExistKey(config)).toBe(true)
})
it('should return false when all key fields are undefined', () => {
const config: ApiConfiguration = {
apiKey: undefined,
glamaApiKey: undefined,
openRouterApiKey: undefined,
awsRegion: undefined,
vertexProjectId: undefined,
openAiApiKey: undefined,
ollamaModelId: undefined,
lmStudioModelId: undefined,
geminiApiKey: undefined,
openAiNativeApiKey: undefined,
deepSeekApiKey: undefined,
mistralApiKey: undefined,
vsCodeLmModelSelector: undefined
};
expect(checkExistKey(config)).toBe(false);
});
});
it("should return false when all key fields are undefined", () => {
const config: ApiConfiguration = {
apiKey: undefined,
glamaApiKey: undefined,
openRouterApiKey: undefined,
awsRegion: undefined,
vertexProjectId: undefined,
openAiApiKey: undefined,
ollamaModelId: undefined,
lmStudioModelId: undefined,
geminiApiKey: undefined,
openAiNativeApiKey: undefined,
deepSeekApiKey: undefined,
mistralApiKey: undefined,
vsCodeLmModelSelector: undefined,
}
expect(checkExistKey(config)).toBe(false)
})
})

View File

@@ -1,44 +1,44 @@
import { stringifyVsCodeLmModelSelector, SELECTOR_SEPARATOR } from '../vsCodeSelectorUtils';
import { LanguageModelChatSelector } from 'vscode';
import { stringifyVsCodeLmModelSelector, SELECTOR_SEPARATOR } from "../vsCodeSelectorUtils"
import { LanguageModelChatSelector } from "vscode"
describe('vsCodeSelectorUtils', () => {
describe('stringifyVsCodeLmModelSelector', () => {
it('should join all defined selector properties with separator', () => {
describe("vsCodeSelectorUtils", () => {
describe("stringifyVsCodeLmModelSelector", () => {
it("should join all defined selector properties with separator", () => {
const selector: LanguageModelChatSelector = {
vendor: 'test-vendor',
family: 'test-family',
version: 'v1',
id: 'test-id'
};
vendor: "test-vendor",
family: "test-family",
version: "v1",
id: "test-id",
}
const result = stringifyVsCodeLmModelSelector(selector);
expect(result).toBe('test-vendor/test-family/v1/test-id');
});
const result = stringifyVsCodeLmModelSelector(selector)
expect(result).toBe("test-vendor/test-family/v1/test-id")
})
it('should skip undefined properties', () => {
it("should skip undefined properties", () => {
const selector: LanguageModelChatSelector = {
vendor: 'test-vendor',
family: 'test-family'
};
vendor: "test-vendor",
family: "test-family",
}
const result = stringifyVsCodeLmModelSelector(selector);
expect(result).toBe('test-vendor/test-family');
});
const result = stringifyVsCodeLmModelSelector(selector)
expect(result).toBe("test-vendor/test-family")
})
it('should handle empty selector', () => {
const selector: LanguageModelChatSelector = {};
it("should handle empty selector", () => {
const selector: LanguageModelChatSelector = {}
const result = stringifyVsCodeLmModelSelector(selector);
expect(result).toBe('');
});
const result = stringifyVsCodeLmModelSelector(selector)
expect(result).toBe("")
})
it('should handle selector with only one property', () => {
it("should handle selector with only one property", () => {
const selector: LanguageModelChatSelector = {
vendor: 'test-vendor'
};
vendor: "test-vendor",
}
const result = stringifyVsCodeLmModelSelector(selector);
expect(result).toBe('test-vendor');
});
});
});
const result = stringifyVsCodeLmModelSelector(selector)
expect(result).toBe("test-vendor")
})
})
})

View File

@@ -1,4 +1,4 @@
import * as vscode from 'vscode';
import * as vscode from "vscode"
export type ApiProvider =
| "anthropic"
@@ -126,24 +126,24 @@ export const anthropicModels = {
// AWS Bedrock
// https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html
export interface MessageContent {
type: 'text' | 'image' | 'video' | 'tool_use' | 'tool_result';
text?: string;
source?: {
type: 'base64';
data: string | Uint8Array; // string for Anthropic, Uint8Array for Bedrock
media_type: 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp';
};
// Video specific fields
format?: string;
s3Location?: {
uri: string;
bucketOwner?: string;
};
// Tool use and result fields
toolUseId?: string;
name?: string;
input?: any;
output?: any; // Used for tool_result type
type: "text" | "image" | "video" | "tool_use" | "tool_result"
text?: string
source?: {
type: "base64"
data: string | Uint8Array // string for Anthropic, Uint8Array for Bedrock
media_type: "image/jpeg" | "image/png" | "image/gif" | "image/webp"
}
// Video specific fields
format?: string
s3Location?: {
uri: string
bucketOwner?: string
}
// Tool use and result fields
toolUseId?: string
name?: string
input?: any
output?: any // Used for tool_result type
}
export type BedrockModelId = keyof typeof bedrockModels
@@ -192,7 +192,6 @@ export const bedrockModels = {
outputPrice: 15.0,
cacheWritesPrice: 3.75, // per million tokens
cacheReadsPrice: 0.3, // per million tokens
},
"anthropic.claude-3-5-haiku-20241022-v1:0": {
maxTokens: 8192,
@@ -203,7 +202,6 @@ export const bedrockModels = {
outputPrice: 5.0,
cacheWritesPrice: 1.0,
cacheReadsPrice: 0.08,
},
"anthropic.claude-3-5-sonnet-20240620-v1:0": {
maxTokens: 8192,
@@ -237,7 +235,7 @@ export const bedrockModels = {
inputPrice: 0.25,
outputPrice: 1.25,
},
"meta.llama3-2-90b-instruct-v1:0" : {
"meta.llama3-2-90b-instruct-v1:0": {
maxTokens: 8192,
contextWindow: 128_000,
supportsImages: true,
@@ -246,7 +244,7 @@ export const bedrockModels = {
inputPrice: 0.72,
outputPrice: 0.72,
},
"meta.llama3-2-11b-instruct-v1:0" : {
"meta.llama3-2-11b-instruct-v1:0": {
maxTokens: 8192,
contextWindow: 128_000,
supportsImages: true,
@@ -255,7 +253,7 @@ export const bedrockModels = {
inputPrice: 0.16,
outputPrice: 0.16,
},
"meta.llama3-2-3b-instruct-v1:0" : {
"meta.llama3-2-3b-instruct-v1:0": {
maxTokens: 8192,
contextWindow: 128_000,
supportsImages: false,
@@ -264,7 +262,7 @@ export const bedrockModels = {
inputPrice: 0.15,
outputPrice: 0.15,
},
"meta.llama3-2-1b-instruct-v1:0" : {
"meta.llama3-2-1b-instruct-v1:0": {
maxTokens: 8192,
contextWindow: 128_000,
supportsImages: false,
@@ -273,7 +271,7 @@ export const bedrockModels = {
inputPrice: 0.1,
outputPrice: 0.1,
},
"meta.llama3-1-405b-instruct-v1:0" : {
"meta.llama3-1-405b-instruct-v1:0": {
maxTokens: 8192,
contextWindow: 128_000,
supportsImages: false,
@@ -282,7 +280,7 @@ export const bedrockModels = {
inputPrice: 2.4,
outputPrice: 2.4,
},
"meta.llama3-1-70b-instruct-v1:0" : {
"meta.llama3-1-70b-instruct-v1:0": {
maxTokens: 8192,
contextWindow: 128_000,
supportsImages: false,
@@ -291,7 +289,7 @@ export const bedrockModels = {
inputPrice: 0.72,
outputPrice: 0.72,
},
"meta.llama3-1-8b-instruct-v1:0" : {
"meta.llama3-1-8b-instruct-v1:0": {
maxTokens: 8192,
contextWindow: 8_000,
supportsImages: false,
@@ -300,8 +298,8 @@ export const bedrockModels = {
inputPrice: 0.22,
outputPrice: 0.22,
},
"meta.llama3-70b-instruct-v1:0" : {
maxTokens: 2048 ,
"meta.llama3-70b-instruct-v1:0": {
maxTokens: 2048,
contextWindow: 8_000,
supportsImages: false,
supportsComputerUse: false,
@@ -309,8 +307,8 @@ export const bedrockModels = {
inputPrice: 2.65,
outputPrice: 3.5,
},
"meta.llama3-8b-instruct-v1:0" : {
maxTokens: 2048 ,
"meta.llama3-8b-instruct-v1:0": {
maxTokens: 2048,
contextWindow: 4_000,
supportsImages: false,
supportsComputerUse: false,
@@ -488,7 +486,7 @@ export type OpenAiNativeModelId = keyof typeof openAiNativeModels
export const openAiNativeDefaultModelId: OpenAiNativeModelId = "gpt-4o"
export const openAiNativeModels = {
// don't support tool use yet
"o1": {
o1: {
maxTokens: 100_000,
contextWindow: 200_000,
supportsImages: true,
@@ -540,8 +538,8 @@ export const deepSeekModels = {
contextWindow: 64_000,
supportsImages: false,
supportsPromptCache: false,
inputPrice: 0.014, // $0.014 per million tokens
outputPrice: 0.28, // $0.28 per million tokens
inputPrice: 0.014, // $0.014 per million tokens
outputPrice: 0.28, // $0.28 per million tokens
description: `DeepSeek-V3 achieves a significant breakthrough in inference speed over previous models. It tops the leaderboard among open-source models and rivals the most advanced closed-source models globally.`,
},
} as const satisfies Record<string, ModelInfo>
@@ -551,7 +549,6 @@ export const deepSeekModels = {
// https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#api-specs
export const azureOpenAiDefaultApiVersion = "2024-08-01-preview"
// Mistral
// https://docs.mistral.ai/getting-started/models/models_overview/
export type MistralModelId = keyof typeof mistralModels

View File

@@ -1,21 +1,21 @@
import { ApiConfiguration } from "../shared/api";
import { ApiConfiguration } from "../shared/api"
export function checkExistKey(config: ApiConfiguration | undefined) {
return config
? [
config.apiKey,
config.glamaApiKey,
config.openRouterApiKey,
config.awsRegion,
config.vertexProjectId,
config.openAiApiKey,
config.ollamaModelId,
config.lmStudioModelId,
config.geminiApiKey,
config.openAiNativeApiKey,
config.deepSeekApiKey,
config.mistralApiKey,
config.vsCodeLmModelSelector,
].some((key) => key !== undefined)
: false;
config.apiKey,
config.glamaApiKey,
config.openRouterApiKey,
config.awsRegion,
config.vertexProjectId,
config.openAiApiKey,
config.ollamaModelId,
config.lmStudioModelId,
config.geminiApiKey,
config.openAiNativeApiKey,
config.deepSeekApiKey,
config.mistralApiKey,
config.vsCodeLmModelSelector,
].some((key) => key !== undefined)
: false
}

View File

@@ -49,11 +49,12 @@ Mention regex:
- `mentionRegexGlobal`: Creates a global version of the `mentionRegex` to find all matches within a given string.
*/
export const mentionRegex = /@((?:\/|\w+:\/\/)[^\s]+?|[a-f0-9]{7,40}\b|problems\b|git-changes\b)(?=[.,;:!?]?(?=[\s\r\n]|$))/
export const mentionRegex =
/@((?:\/|\w+:\/\/)[^\s]+?|[a-f0-9]{7,40}\b|problems\b|git-changes\b)(?=[.,;:!?]?(?=[\s\r\n]|$))/
export const mentionRegexGlobal = new RegExp(mentionRegex.source, "g")
export interface MentionSuggestion {
type: 'file' | 'folder' | 'git' | 'problems'
type: "file" | "folder" | "git" | "problems"
label: string
description?: string
value: string
@@ -61,7 +62,7 @@ export interface MentionSuggestion {
}
export interface GitMentionSuggestion extends MentionSuggestion {
type: 'git'
type: "git"
hash: string
shortHash: string
subject: string
@@ -69,17 +70,23 @@ export interface GitMentionSuggestion extends MentionSuggestion {
date: string
}
export function formatGitSuggestion(commit: { hash: string; shortHash: string; subject: string; author: string; date: string }): GitMentionSuggestion {
export function formatGitSuggestion(commit: {
hash: string
shortHash: string
subject: string
author: string
date: string
}): GitMentionSuggestion {
return {
type: 'git',
type: "git",
label: commit.subject,
description: `${commit.shortHash} by ${commit.author} on ${commit.date}`,
value: commit.hash,
icon: '$(git-commit)', // VSCode git commit icon
icon: "$(git-commit)", // VSCode git commit icon
hash: commit.hash,
shortHash: commit.shortHash,
subject: commit.subject,
author: commit.author,
date: commit.date
date: commit.date,
}
}

View File

@@ -1,187 +1,189 @@
// Tool options for specific tools
export type ToolOptions = {
string: readonly string[];
string: readonly string[]
}
// Tool configuration tuple type
export type ToolConfig = readonly [string] | readonly [string, ToolOptions];
export type ToolConfig = readonly [string] | readonly [string, ToolOptions]
// Mode types
export type Mode = string;
export type Mode = string
// Mode configuration type
export type ModeConfig = {
slug: string;
name: string;
roleDefinition: string;
tools: readonly ToolConfig[];
slug: string
name: string
roleDefinition: string
tools: readonly ToolConfig[]
}
// Separate enhance prompt type and definition
export type EnhanceConfig = {
prompt: string;
prompt: string
}
export const enhance: EnhanceConfig = {
prompt: "Generate an enhanced version of this prompt (reply with only the enhanced prompt - no conversation, explanations, lead-in, bullet points, placeholders, or surrounding quotes):"
} as const;
prompt: "Generate an enhanced version of this prompt (reply with only the enhanced prompt - no conversation, explanations, lead-in, bullet points, placeholders, or surrounding quotes):",
} as const
// Main modes configuration as an ordered array
export const modes: readonly ModeConfig[] = [
{
slug: 'code',
name: 'Code',
roleDefinition: "You are Cline, a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.",
tools: [
['execute_command'],
['read_file'],
['write_to_file'],
['apply_diff'],
['search_files'],
['list_files'],
['list_code_definition_names'],
['browser_action'],
['use_mcp_tool'],
['access_mcp_resource'],
['ask_followup_question'],
['attempt_completion'],
] as const
},
{
slug: 'architect',
name: 'Architect',
roleDefinition: "You are Cline, a software architecture expert specializing in analyzing codebases, identifying patterns, and providing high-level technical guidance. You excel at understanding complex systems, evaluating architectural decisions, and suggesting improvements while maintaining a read-only approach to the codebase. Make sure to help the user come up with a solid implementation plan for their project and don't rush to switch to implementing code.",
tools: [
['read_file'],
['search_files'],
['list_files'],
['list_code_definition_names'],
['browser_action'],
['use_mcp_tool'],
['access_mcp_resource'],
['ask_followup_question'],
['attempt_completion'],
] as const
},
{
slug: 'ask',
name: 'Ask',
roleDefinition: "You are Cline, a knowledgeable technical assistant focused on answering questions and providing information about software development, technology, and related topics. You can analyze code, explain concepts, and access external resources while maintaining a read-only approach to the codebase. Make sure to answer the user's questions and don't rush to switch to implementing code.",
tools: [
['read_file'],
['search_files'],
['list_files'],
['list_code_definition_names'],
['browser_action'],
['use_mcp_tool'],
['access_mcp_resource'],
['ask_followup_question'],
['attempt_completion'],
] as const
},
{
slug: 'test',
name: 'Test',
roleDefinition: "You are Cline, a software test engineering expert specializing in writing comprehensive test suites and ensuring thorough test coverage. You excel at writing unit tests, integration tests, and end-to-end tests that cover all edge cases while maintaining existing behavior. You must ask the user to confirm before making ANY changes to non-test code, and before implementing any test changes, you always ask the user to confirm your test plan. You focus on: 1) Writing tests that verify functionality without changing existing behavior, 2) Ensuring comprehensive test coverage including edge cases and error conditions, 3) Following testing best practices and patterns appropriate for the language/framework, 4) Using mocks, stubs, and fixtures effectively, 5) Writing clear, maintainable test code with descriptive names and good documentation.",
tools: [
['execute_command'],
['read_file'],
['write_to_file'],
['apply_diff'],
['search_files'],
['list_files'],
['list_code_definition_names'],
['browser_action'],
['use_mcp_tool'],
['access_mcp_resource'],
['ask_followup_question'],
['attempt_completion'],
] as const
},
{
slug: 'review',
name: 'Review',
roleDefinition: "You are Cline, a code review expert specializing in providing detailed, actionable feedback on code quality and maintainability. You excel at: 1) Identifying potential bugs, security vulnerabilities, and performance issues, 2) Ensuring code follows project standards, patterns, and best practices, 3) Checking for proper error handling and edge cases, 4) Verifying documentation completeness and clarity, 5) Suggesting specific, actionable improvements with examples. You maintain a read-only approach to the codebase and focus on helping developers improve their code through clear, constructive feedback.",
tools: [
['read_file'],
['search_files'],
['list_files'],
['list_code_definition_names'],
['browser_action'],
['use_mcp_tool'],
['access_mcp_resource'],
['ask_followup_question'],
['attempt_completion'],
] as const
},
] as const;
{
slug: "code",
name: "Code",
roleDefinition:
"You are Cline, a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.",
tools: [
["execute_command"],
["read_file"],
["write_to_file"],
["apply_diff"],
["search_files"],
["list_files"],
["list_code_definition_names"],
["browser_action"],
["use_mcp_tool"],
["access_mcp_resource"],
["ask_followup_question"],
["attempt_completion"],
] as const,
},
{
slug: "architect",
name: "Architect",
roleDefinition:
"You are Cline, a software architecture expert specializing in analyzing codebases, identifying patterns, and providing high-level technical guidance. You excel at understanding complex systems, evaluating architectural decisions, and suggesting improvements while maintaining a read-only approach to the codebase. Make sure to help the user come up with a solid implementation plan for their project and don't rush to switch to implementing code.",
tools: [
["read_file"],
["search_files"],
["list_files"],
["list_code_definition_names"],
["browser_action"],
["use_mcp_tool"],
["access_mcp_resource"],
["ask_followup_question"],
["attempt_completion"],
] as const,
},
{
slug: "ask",
name: "Ask",
roleDefinition:
"You are Cline, a knowledgeable technical assistant focused on answering questions and providing information about software development, technology, and related topics. You can analyze code, explain concepts, and access external resources while maintaining a read-only approach to the codebase. Make sure to answer the user's questions and don't rush to switch to implementing code.",
tools: [
["read_file"],
["search_files"],
["list_files"],
["list_code_definition_names"],
["browser_action"],
["use_mcp_tool"],
["access_mcp_resource"],
["ask_followup_question"],
["attempt_completion"],
] as const,
},
{
slug: "test",
name: "Test",
roleDefinition:
"You are Cline, a software test engineering expert specializing in writing comprehensive test suites and ensuring thorough test coverage. You excel at writing unit tests, integration tests, and end-to-end tests that cover all edge cases while maintaining existing behavior. You must ask the user to confirm before making ANY changes to non-test code, and before implementing any test changes, you always ask the user to confirm your test plan. You focus on: 1) Writing tests that verify functionality without changing existing behavior, 2) Ensuring comprehensive test coverage including edge cases and error conditions, 3) Following testing best practices and patterns appropriate for the language/framework, 4) Using mocks, stubs, and fixtures effectively, 5) Writing clear, maintainable test code with descriptive names and good documentation.",
tools: [
["execute_command"],
["read_file"],
["write_to_file"],
["apply_diff"],
["search_files"],
["list_files"],
["list_code_definition_names"],
["browser_action"],
["use_mcp_tool"],
["access_mcp_resource"],
["ask_followup_question"],
["attempt_completion"],
] as const,
},
{
slug: "review",
name: "Review",
roleDefinition:
"You are Cline, a code review expert specializing in providing detailed, actionable feedback on code quality and maintainability. You excel at: 1) Identifying potential bugs, security vulnerabilities, and performance issues, 2) Ensuring code follows project standards, patterns, and best practices, 3) Checking for proper error handling and edge cases, 4) Verifying documentation completeness and clarity, 5) Suggesting specific, actionable improvements with examples. You maintain a read-only approach to the codebase and focus on helping developers improve their code through clear, constructive feedback.",
tools: [
["read_file"],
["search_files"],
["list_files"],
["list_code_definition_names"],
["browser_action"],
["use_mcp_tool"],
["access_mcp_resource"],
["ask_followup_question"],
["attempt_completion"],
] as const,
},
] as const
// Export the default mode slug
export const defaultModeSlug = modes[0].slug;
export const defaultModeSlug = modes[0].slug
// Helper functions
export function getModeBySlug(slug: string): ModeConfig | undefined {
return modes.find(mode => mode.slug === slug);
return modes.find((mode) => mode.slug === slug)
}
export function getModeConfig(slug: string): ModeConfig {
const mode = getModeBySlug(slug);
if (!mode) {
throw new Error(`No mode found for slug: ${slug}`);
}
return mode;
const mode = getModeBySlug(slug)
if (!mode) {
throw new Error(`No mode found for slug: ${slug}`)
}
return mode
}
// Derive tool names from the modes configuration
export type ToolName = typeof modes[number]['tools'][number][0];
export type TestToolName = ToolName | 'unknown_tool';
export type ToolName = (typeof modes)[number]["tools"][number][0]
export type TestToolName = ToolName | "unknown_tool"
export function isToolAllowedForMode(tool: TestToolName, modeSlug: string): boolean {
if (tool === 'unknown_tool') {
return false;
}
const mode = getModeBySlug(modeSlug);
if (!mode) {
return false;
}
return mode.tools.some(([toolName]) => toolName === tool);
if (tool === "unknown_tool") {
return false
}
const mode = getModeBySlug(modeSlug)
if (!mode) {
return false
}
return mode.tools.some(([toolName]) => toolName === tool)
}
export function getToolOptions(tool: ToolName, modeSlug: string): ToolOptions | undefined {
const mode = getModeBySlug(modeSlug);
if (!mode) {
return undefined;
}
const toolConfig = mode.tools.find(([toolName]) => toolName === tool);
return toolConfig?.[1];
const mode = getModeBySlug(modeSlug)
if (!mode) {
return undefined
}
const toolConfig = mode.tools.find(([toolName]) => toolName === tool)
return toolConfig?.[1]
}
export type PromptComponent = {
roleDefinition?: string;
customInstructions?: string;
roleDefinition?: string
customInstructions?: string
}
export type CustomPrompts = {
[key: string]: PromptComponent | string | undefined;
[key: string]: PromptComponent | string | undefined
}
// Create the defaultPrompts object with the correct type
export const defaultPrompts: CustomPrompts = {
...Object.fromEntries(modes.map(mode => [
mode.slug,
{ roleDefinition: mode.roleDefinition }
])),
enhance: enhance.prompt
} as const;
...Object.fromEntries(modes.map((mode) => [mode.slug, { roleDefinition: mode.roleDefinition }])),
enhance: enhance.prompt,
} as const
// Helper function to safely get role definition
export function getRoleDefinition(modeSlug: string): string {
const prompt = defaultPrompts[modeSlug];
if (!prompt || typeof prompt === 'string') {
throw new Error(`Invalid mode slug: ${modeSlug}`);
}
if (!prompt.roleDefinition) {
throw new Error(`No role definition found for mode: ${modeSlug}`);
}
return prompt.roleDefinition;
}
const prompt = defaultPrompts[modeSlug]
if (!prompt || typeof prompt === "string") {
throw new Error(`Invalid mode slug: ${modeSlug}`)
}
if (!prompt.roleDefinition) {
throw new Error(`No role definition found for mode: ${modeSlug}`)
}
return prompt.roleDefinition
}

View File

@@ -1,14 +1,7 @@
import { LanguageModelChatSelector } from 'vscode';
import { LanguageModelChatSelector } from "vscode"
export const SELECTOR_SEPARATOR = '/';
export const SELECTOR_SEPARATOR = "/"
export function stringifyVsCodeLmModelSelector(selector: LanguageModelChatSelector): string {
return [
selector.vendor,
selector.family,
selector.version,
selector.id
]
.filter(Boolean)
.join(SELECTOR_SEPARATOR);
return [selector.vendor, selector.family, selector.version, selector.id].filter(Boolean).join(SELECTOR_SEPARATOR)
}