refactor: Remove usage of deprecated contexts and APIs

- Comment out refDefsContext and defRefsContext usage in loadContexts
- Replace accessKey logic with defaultModel in several files
- Remove unused functions related to API key handling

Closes #286
This commit is contained in:
bobo.yang 2024-03-10 16:35:10 +08:00
parent 70ea72fabe
commit 33a4ee14f1
6 changed files with 8 additions and 55 deletions

View File

@ -2,8 +2,8 @@ import { ChatContextManager } from './contextManager';
import { gitDiffCachedContext } from './contextGitDiffCached';
import { gitDiffContext } from './contextGitDiff';
import { customCommandContext } from './contextCustomCommand';
import { refDefsContext } from './contextRefDefs';
import { defRefsContext } from './contextDefRefs';
// import { refDefsContext } from './contextRefDefs';
// import { defRefsContext } from './contextDefRefs';
const chatContextManager = ChatContextManager.getInstance();
@ -11,6 +11,6 @@ const chatContextManager = ChatContextManager.getInstance();
// 注册命令
chatContextManager.registerContext(gitDiffCachedContext);
chatContextManager.registerContext(gitDiffContext);
chatContextManager.registerContext(refDefsContext);
chatContextManager.registerContext(defRefsContext);
// chatContextManager.registerContext(refDefsContext);
// chatContextManager.registerContext(defRefsContext);
chatContextManager.registerContext(customCommandContext);

View File

@ -164,8 +164,8 @@ function regAccessKeyCommand(
await ApiKeyManager.writeApiKeySecret(passwordInput, provider);
// update default model
const accessKey = await ApiKeyManager.getApiKey();
if (!accessKey) {
const defaultModel = await ApiKeyManager.llmModel();
if (!defaultModel) {
const modelList = await ApiKeyManager.getValidModels();
if (modelList && modelList.length > 0) {
// update default llm model

View File

@ -4,7 +4,6 @@ import DevChat, { LogEntry, LogOptions } from '../toolwrapper/devchat';
import messageHistory from '../util/messageHistory';
import { ApiKeyManager } from '../util/apiKey';
let isApiSet: boolean | undefined = undefined;
export interface LoadHistoryMessages {
command: string;
@ -68,14 +67,6 @@ export function isValidApiKey(apiKey: string, llmType: string = "None") {
return true;
}
export async function isWaitForApiKey() {
if (isApiSet === undefined) {
const apiKey = await ApiKeyManager.getApiKey();
isApiSet = apiKey !== undefined;
}
return !isApiSet;
}
export async function loadTopicHistoryLogs(topicId: string | undefined): Promise<Array<LogEntry> | undefined> {
if (!topicId) {
return undefined;
@ -133,22 +124,6 @@ export function loadTopicHistoryFromCurrentMessageHistory(skip: number, count: n
} as LoadHistoryMessages;
}
export async function apiKeyInvalidMessage(): Promise<LoadHistoryMessages | undefined> {
const apiKey = await ApiKeyManager.getApiKey();
isApiSet = true;
if (!apiKey) {
const startMessage = [apiKeyMissedMessage()];
isApiSet = false;
return {
command: 'loadHistoryMessages',
entries: startMessage,
} as LoadHistoryMessages;
} else {
return undefined;
}
}
export async function historyMessagesBase(topicId: string): Promise<LoadHistoryMessages | undefined> {
const logEntriesFlat = await loadTopicHistoryLogs(topicId);
if (!logEntriesFlat) {

View File

@ -25,8 +25,3 @@ export async function getHistoryMessages(message: {command: string, topicId: str
}
}
export async function onApiKey(apiKey: string, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
const resMessage = await onApiKeyBase(apiKey);
MessageHandler.sendMessage(panel, resMessage);
}

View File

@ -4,9 +4,6 @@ import * as vscode from 'vscode';
import '../context/loadContexts';
import { logger } from '../util/logger';
import { isWaitForApiKey } from './historyMessagesBase';
import { onApiKey } from './historyMessagesHandler';
import { ApiKeyManager } from '../util/apiKey';
export class MessageHandler {
@ -37,12 +34,6 @@ export class MessageHandler {
} catch (e) {
}
}
if (message.command === 'sendMessage') {
if (await isWaitForApiKey() && !await ApiKeyManager.getApiKey()) {
onApiKey(message.text, panel);
return;
}
}
const handler = this.handlers[message.command];
if (handler) {

View File

@ -65,19 +65,11 @@ export async function dependencyCheck(): Promise<[string, string]> {
// define subfunction to check api key
const getApiKeyStatus = async (): Promise<string> => {
if (apiKeyStatus === '' || apiKeyStatus === 'Click "DevChat" status icon to set key') {
const accessKey = await ApiKeyManager.getApiKey();
if (accessKey) {
const defaultModel = await ApiKeyManager.llmModel();
if (defaultModel) {
apiKeyStatus = 'has valid access key';
return apiKeyStatus;
} else {
// test whether valid model exists
const modelList = await ApiKeyManager.getValidModels();
if (modelList && modelList.length > 0) {
// update default llm model
await UiUtilWrapper.updateConfiguration('devchat', 'defaultModel', modelList[0]);
apiKeyStatus = 'has valid access key';
return apiKeyStatus;
}
apiKeyStatus = 'Click "DevChat" status icon to set key';
return apiKeyStatus;
}