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 {
|
2023-08-21 11:52:00 +08:00
|
|
|
registerOpenChatPanelCommand,
|
|
|
|
registerAddContextCommand,
|
|
|
|
registerAskForCodeCommand,
|
|
|
|
registerAskForFileCommand,
|
2023-09-13 10:08:16 +08:00
|
|
|
registerAccessKeySettingCommand,
|
2023-08-21 11:52:00 +08:00
|
|
|
regTopicDeleteCommand,
|
|
|
|
regAddTopicCommand,
|
|
|
|
regDeleteSelectTopicCommand,
|
|
|
|
regSelectTopicCommand,
|
|
|
|
regReloadTopicCommand,
|
|
|
|
regApplyDiffResultCommand,
|
|
|
|
registerStatusBarItemClickCommand,
|
|
|
|
regPythonPathCommand,
|
|
|
|
registerAskCodeIndexStartCommand,
|
2023-08-21 11:52:00 +08:00
|
|
|
registerAskCodeIndexStopCommand,
|
2023-08-21 11:52:00 +08:00
|
|
|
registerAskCodeSummaryIndexStartCommand,
|
|
|
|
registerAskCodeSummaryIndexStopCommand,
|
|
|
|
registerAddSummaryContextCommand,
|
2023-08-30 16:39:47 +08:00
|
|
|
registerInstallCommandsCommand,
|
2023-09-13 10:08:16 +08:00
|
|
|
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';
|
2023-08-21 11:52:00 +08:00
|
|
|
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';
|
2023-08-24 10:45:51 +08:00
|
|
|
import { FT } from './util/feature_flags/feature_toggles';
|
2023-05-19 20:07:34 +08:00
|
|
|
|
2023-09-13 10:08:16 +08:00
|
|
|
async function configUpdateTo_0912() {
|
2023-09-14 16:44:41 +08:00
|
|
|
const defaultModel: any = UiUtilWrapper.getConfiguration("devchat", "defaultModel");
|
|
|
|
if (!defaultModel) {
|
|
|
|
vscode.workspace.getConfiguration("devchat").update("defaultModel", "gpt-3.5-turbo", vscode.ConfigurationTarget.Global);
|
|
|
|
}
|
|
|
|
|
2023-09-14 20:17:55 +08:00
|
|
|
let devchatKey = UiUtilWrapper.getConfiguration('DevChat', 'Access_Key_DevChat');
|
|
|
|
let openaiKey = UiUtilWrapper.getConfiguration('DevChat', 'Api_Key_OpenAI');
|
2023-09-13 10:08:16 +08:00
|
|
|
const endpointKey = UiUtilWrapper.getConfiguration('DevChat', 'API_ENDPOINT');
|
2023-09-14 20:17:55 +08:00
|
|
|
|
|
|
|
devchatKey = undefined;
|
|
|
|
openaiKey = undefined;
|
|
|
|
if (!devchatKey && !openaiKey) {
|
|
|
|
openaiKey = await UiUtilWrapper.secretStorageGet("openai_OPENAI_API_KEY");
|
|
|
|
devchatKey = await UiUtilWrapper.secretStorageGet("devchat_OPENAI_API_KEY");
|
|
|
|
}
|
|
|
|
if (!devchatKey && !openaiKey) {
|
|
|
|
openaiKey = process.env.OPENAI_API_KEY;
|
|
|
|
}
|
|
|
|
|
2023-09-13 10:08:16 +08:00
|
|
|
let modelConfigNew = {};
|
|
|
|
if (openaiKey) {
|
|
|
|
modelConfigNew["api_key"] = openaiKey;
|
2023-09-13 10:08:16 +08:00
|
|
|
modelConfigNew["provider"] = "openai";
|
2023-09-13 10:08:16 +08:00
|
|
|
} else if (devchatKey) {
|
|
|
|
modelConfigNew["api_key"] = devchatKey;
|
2023-09-13 10:08:16 +08:00
|
|
|
modelConfigNew["provider"] = "openai";
|
2023-09-13 10:08:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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 &&
|
2023-09-13 10:08:16 +08:00
|
|
|
Object.keys(modelConfig3).length === 0) {
|
2023-09-13 10:08:16 +08:00
|
|
|
// config default gpt models
|
2023-09-13 10:08:16 +08:00
|
|
|
if (Object.keys(modelConfigNew).length === 0) {
|
|
|
|
modelConfigNew["api_key"] = "DC.<your devchat key>";
|
|
|
|
modelConfigNew["provider"] = "openai";
|
|
|
|
}
|
|
|
|
|
2023-09-13 10:08:16 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-04 11:50:45 +08:00
|
|
|
|
2023-05-04 07:27:26 +08:00
|
|
|
function activate(context: vscode.ExtensionContext) {
|
2023-08-21 11:52:00 +08:00
|
|
|
ExtensionContextHolder.context = context;
|
2023-05-31 16:10:53 +08:00
|
|
|
|
2023-08-21 11:52:00 +08:00
|
|
|
logger.init(LoggerChannelVscode.getInstance());
|
|
|
|
UiUtilWrapper.init(new UiUtilVscode());
|
2023-05-04 11:50:45 +08:00
|
|
|
|
2023-09-13 10:08:16 +08:00
|
|
|
configUpdateTo_0912();
|
|
|
|
|
2023-08-21 11:52:00 +08:00
|
|
|
regLanguageContext();
|
2023-05-16 10:40:57 +08:00
|
|
|
|
2023-08-21 11:52:00 +08:00
|
|
|
regDevChatView(context);
|
|
|
|
regTopicView(context);
|
2023-05-16 10:40:57 +08:00
|
|
|
|
2023-09-13 10:08:16 +08:00
|
|
|
registerAccessKeySettingCommand(context);
|
2023-08-21 11:52:00 +08:00
|
|
|
registerOpenChatPanelCommand(context);
|
|
|
|
registerAddContextCommand(context);
|
|
|
|
registerAskForCodeCommand(context);
|
|
|
|
registerAskForFileCommand(context);
|
|
|
|
registerStatusBarItemClickCommand(context);
|
2023-05-16 14:24:24 +08:00
|
|
|
|
2023-08-30 16:39:47 +08:00
|
|
|
registerInstallCommandsCommand(context);
|
2023-09-13 10:08:16 +08:00
|
|
|
registerUpdateChatModelsCommand(context);
|
2023-08-30 16:39:47 +08:00
|
|
|
|
2023-08-21 11:52:00 +08:00
|
|
|
createStatusBarItem(context);
|
2023-08-24 10:45:51 +08:00
|
|
|
if (FT("ask-code")) {
|
|
|
|
createAskCodeStatusBarItem(context);
|
|
|
|
}
|
2023-05-18 15:25:46 +08:00
|
|
|
|
2023-08-21 11:52:00 +08:00
|
|
|
regTopicDeleteCommand(context);
|
|
|
|
regAddTopicCommand(context);
|
|
|
|
regDeleteSelectTopicCommand(context);
|
|
|
|
regSelectTopicCommand(context);
|
|
|
|
regReloadTopicCommand(context);
|
|
|
|
regApplyDiffResultCommand(context);
|
2023-07-06 07:42:44 +08:00
|
|
|
|
2023-08-21 11:52:00 +08:00
|
|
|
regPythonPathCommand(context);
|
2023-08-24 10:45:51 +08:00
|
|
|
|
|
|
|
registerAskCodeIndexStartCommand(context);
|
|
|
|
registerAskCodeIndexStopCommand(context);
|
|
|
|
|
|
|
|
registerAskCodeSummaryIndexStartCommand(context);
|
|
|
|
registerAskCodeSummaryIndexStopCommand(context);
|
2023-08-21 11:52:00 +08:00
|
|
|
registerAddSummaryContextCommand(context);
|
2023-04-14 08:05:41 +08:00
|
|
|
}
|
2023-08-21 11:52:00 +08:00
|
|
|
exports.activate = activate;
|