127 lines
4.4 KiB
TypeScript
Raw Normal View History

2023-05-04 07:27:26 +08:00
import * as vscode from 'vscode';
2023-05-10 18:30:17 +08:00
2023-05-05 21:27:40 +08:00
import {
registerOpenChatPanelCommand,
registerAddContextCommand,
registerAskForCodeCommand,
registerAskForFileCommand,
registerAccessKeySettingCommand,
regTopicDeleteCommand,
regAddTopicCommand,
regDeleteSelectTopicCommand,
regSelectTopicCommand,
regReloadTopicCommand,
regApplyDiffResultCommand,
registerStatusBarItemClickCommand,
regPythonPathCommand,
registerAskCodeIndexStartCommand,
registerAskCodeIndexStopCommand,
registerAskCodeSummaryIndexStartCommand,
registerAskCodeSummaryIndexStopCommand,
registerAddSummaryContextCommand,
registerInstallCommandsCommand,
registerUpdateChatModelsCommand,
2023-05-05 21:27:40 +08:00
} from './contributes/commands';
2023-05-31 16:10:53 +08:00
import { regLanguageContext } from './contributes/context';
import { regDevChatView, regTopicView } from './contributes/views';
2023-04-27 14:07:46 +08:00
2023-05-05 21:27:40 +08:00
import ExtensionContextHolder from './util/extensionContext';
2023-05-09 08:52:07 +08:00
import { logger } from './util/logger';
2023-05-31 16:10:53 +08:00
import { LoggerChannelVscode } from './util/logger_vscode';
import { createStatusBarItem, createAskCodeStatusBarItem } from './panel/statusBarView';
2023-05-31 16:10:53 +08:00
import { UiUtilWrapper } from './util/uiUtil';
import { UiUtilVscode } from './util/uiUtil_vscode';
import { FT } from './util/feature_flags/feature_toggles';
2023-05-19 20:07:34 +08:00
async function configUpdateTo_0912() {
const devchatKey = UiUtilWrapper.getConfiguration('DevChat', 'Access_Key_DevChat');
const openaiKey = UiUtilWrapper.getConfiguration('DevChat', 'Api_Key_OpenAI');
const endpointKey = UiUtilWrapper.getConfiguration('DevChat', 'API_ENDPOINT');
let modelConfigNew = {};
if (openaiKey) {
modelConfigNew["api_key"] = openaiKey;
modelConfigNew["provider"] = "openai";
} else if (devchatKey) {
modelConfigNew["api_key"] = devchatKey;
modelConfigNew["provider"] = "openai";
}
if (endpointKey) {
modelConfigNew["api_base"] = endpointKey;
}
const modelConfig1: any = UiUtilWrapper.getConfiguration("devchat", "Model.gpt-3-5");
const modelConfig2: any = UiUtilWrapper.getConfiguration("devchat", "Model.gpt-3-5-16k");
const modelConfig3: any = UiUtilWrapper.getConfiguration("devchat", "Model.gpt-4");
//if (!modelConfig1 && !modelConfig2 && !modelConfig3 && Object.keys(modelConfigNew).length > 0) {
if (Object.keys(modelConfig1).length === 0 &&
Object.keys(modelConfig2).length === 0 &&
Object.keys(modelConfig3).length === 0) {
// config default gpt models
if (Object.keys(modelConfigNew).length === 0) {
modelConfigNew["api_key"] = "DC.<your devchat key>";
modelConfigNew["provider"] = "openai";
}
try {
vscode.workspace.getConfiguration("devchat").update("Model.gpt-3-5", modelConfigNew, vscode.ConfigurationTarget.Global);
vscode.workspace.getConfiguration("devchat").update("Model.gpt-3-5-16k", modelConfigNew, vscode.ConfigurationTarget.Global);
vscode.workspace.getConfiguration("devchat").update("Model.gpt-4", modelConfigNew, vscode.ConfigurationTarget.Global);
} catch(error) {
return;
}
}
const defaultModel: any = UiUtilWrapper.getConfiguration("devchat", "defaultModel");
if (!defaultModel) {
vscode.workspace.getConfiguration("devchat").update("defaultModel", "gpt-3.5-turbo");
}
}
2023-05-04 11:50:45 +08:00
2023-05-04 07:27:26 +08:00
function activate(context: vscode.ExtensionContext) {
ExtensionContextHolder.context = context;
2023-05-31 16:10:53 +08:00
logger.init(LoggerChannelVscode.getInstance());
UiUtilWrapper.init(new UiUtilVscode());
2023-05-04 11:50:45 +08:00
configUpdateTo_0912();
regLanguageContext();
regDevChatView(context);
regTopicView(context);
registerAccessKeySettingCommand(context);
registerOpenChatPanelCommand(context);
registerAddContextCommand(context);
registerAskForCodeCommand(context);
registerAskForFileCommand(context);
registerStatusBarItemClickCommand(context);
2023-05-16 14:24:24 +08:00
registerInstallCommandsCommand(context);
registerUpdateChatModelsCommand(context);
createStatusBarItem(context);
if (FT("ask-code")) {
createAskCodeStatusBarItem(context);
}
2023-05-18 15:25:46 +08:00
regTopicDeleteCommand(context);
regAddTopicCommand(context);
regDeleteSelectTopicCommand(context);
regSelectTopicCommand(context);
regReloadTopicCommand(context);
regApplyDiffResultCommand(context);
regPythonPathCommand(context);
registerAskCodeIndexStartCommand(context);
registerAskCodeIndexStopCommand(context);
registerAskCodeSummaryIndexStartCommand(context);
registerAskCodeSummaryIndexStopCommand(context);
registerAddSummaryContextCommand(context);
2023-04-14 08:05:41 +08:00
}
exports.activate = activate;