Skip to content

Commit

Permalink
feat: refactor code and add chat webview
Browse files Browse the repository at this point in the history
  • Loading branch information
2214962083 committed Aug 24, 2024
1 parent e795f54 commit d09c07a
Show file tree
Hide file tree
Showing 116 changed files with 3,884 additions and 2,065 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@
"@typescript-eslint/ban-types": "off",
"import/no-extraneous-dependencies": "off",
"react/jsx-no-bind": "off",
"react/react-in-jsx-scope": "off"
"react/react-in-jsx-scope": "off",
"react/function-component-definition": "off",
"react/no-array-index-key": "off"
}
}
]
Expand Down
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@
"onStartupFinished"
],
"contributes": {
"viewsContainers": {
"activitybar": [
{
"id": "aide",
"title": "AIDE",
"icon": "res/icon-mask.png"
}
]
},
"views": {
"aide": [
{
"type": "webview",
"id": "aide.webview",
"name": "AIDE"
}
]
},
"commands": [
{
"command": "aide.copyAsPrompt",
Expand Down Expand Up @@ -102,6 +120,11 @@
"command": "aide.batchProcessor",
"title": "%command.batchProcessor%"
},
{
"command": "aide.openWebview",
"title": "%command.openWebview%",
"icon": "res/icon.png"
},
{
"command": "aide.copyFileText",
"title": "%command.copyFileText%",
Expand Down Expand Up @@ -164,6 +187,10 @@
}
],
"editor/title": [
{
"command": "aide.openWebview",
"group": "navigation@0"
},
{
"command": "aide.codeViewerHelper",
"group": "navigation@1"
Expand Down Expand Up @@ -312,6 +339,7 @@
"@langchain/core": "0.2.23",
"@langchain/openai": "^0.2.6",
"@tomjs/vite-plugin-vscode": "^2.5.5",
"@types/diff": "^5.2.1",
"@types/fs-extra": "^11.0.4",
"@types/global-agent": "^2.1.3",
"@types/node": "^22.2.0",
Expand All @@ -326,6 +354,7 @@
"@vscode/vsce": "^2.31.1",
"@vscode/webview-ui-toolkit": "^1.4.0",
"commitizen": "^4.3.0",
"diff": "^5.2.0",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"eslint-config-airbnb": "^19.0.4",
Expand Down Expand Up @@ -359,6 +388,7 @@
"react-dom": "^18.3.1",
"rimraf": "^6.0.1",
"shell-quote": "^1.8.1",
"simple-git": "^3.25.0",
"tsup": "^8.2.4",
"typescript": "5.4.5",
"undici": "^6.19.7",
Expand Down
45 changes: 45 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions src/extension/ai/get-reference-file-paths.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { AbortError } from '@extension/constants'
import { traverseFileOrFolders } from '@extension/file-utils/traverse-fs'
import {
getCurrentWorkspaceFolderEditor,
toPlatformPath
} from '@extension/utils'
import { getWorkspaceFolder, toPlatformPath } from '@extension/utils'
import * as vscode from 'vscode'
import { z } from 'zod'

Expand All @@ -21,7 +18,7 @@ export const getReferenceFilePaths = async ({
currentFilePath: string
abortController?: AbortController
}): Promise<ReferenceFilePaths> => {
const { workspaceFolder } = await getCurrentWorkspaceFolderEditor()
const workspaceFolder = getWorkspaceFolder()
const allRelativePaths: string[] = []

await traverseFileOrFolders(
Expand Down
5 changes: 1 addition & 4 deletions src/extension/ai/model-providers/azure-openai.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/* eslint-disable no-useless-escape */
import { getConfigKey } from '@extension/config'
import { getContext } from '@extension/context'
import { t } from '@extension/i18n'
import {
AzureChatOpenAI,
ChatOpenAI,
type ChatOpenAICallOptions
} from '@langchain/openai'
import * as vscode from 'vscode'

import { parseModelBaseUrl } from '../parse-model-base-url'
import { BaseModelProvider } from './base'
Expand All @@ -16,7 +14,6 @@ export class AzureOpenAIModelProvider extends BaseModelProvider<
ChatOpenAI<ChatOpenAICallOptions>
> {
async createModel() {
const isDev = getContext().extensionMode !== vscode.ExtensionMode.Production
const { url: openaiBaseUrl } = await parseModelBaseUrl()
const openaiKey = await getConfigKey('openaiKey')

Expand Down Expand Up @@ -48,7 +45,7 @@ export class AzureOpenAIModelProvider extends BaseModelProvider<
fetch
},
temperature: 0.95, // never use 1.0, some models do not support it
verbose: isDev,
verbose: this.isDev,
maxRetries: 3
})
;('https://westeurope.api.microsoft.com/openai/deployments/devName/chat/completions?api-version=AVersion')
Expand Down
6 changes: 5 additions & 1 deletion src/extension/ai/model-providers/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { MaybePromise } from '@extension/types/common'
import { normalizeLineEndings } from '@extension/utils'
import { getIsDev, normalizeLineEndings } from '@extension/utils'
import { InMemoryChatMessageHistory } from '@langchain/core/chat_history'
import type { BaseChatModel } from '@langchain/core/language_models/chat_models'
import {
Expand Down Expand Up @@ -50,6 +50,10 @@ export abstract class BaseModelProvider<Model extends BaseChatModel> {
)
}

get isDev() {
return getIsDev()
}

model?: Model

abstract createModel(): MaybePromise<Model>
Expand Down
6 changes: 1 addition & 5 deletions src/extension/ai/model-providers/claude.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { getConfigKey } from '@extension/config'
import { getContext } from '@extension/context'
import { ChatAnthropic } from '@langchain/anthropic'
import * as vscode from 'vscode'

import { parseModelBaseUrl } from '../parse-model-base-url'
import { BaseModelProvider } from './base'

export class AnthropicModelProvider extends BaseModelProvider<ChatAnthropic> {
async createModel() {
const isDev = getContext().extensionMode !== vscode.ExtensionMode.Production

// anthropic@https://api.anthropic.com
const { url: openaiBaseUrl } = await parseModelBaseUrl()
const openaiKey = await getConfigKey('openaiKey')
Expand All @@ -24,7 +20,7 @@ export class AnthropicModelProvider extends BaseModelProvider<ChatAnthropic> {
model: openaiModel,
temperature: 0.95, // never use 1.0, some models do not support it
maxRetries: 6,
verbose: isDev
verbose: this.isDev
})

return model
Expand Down
5 changes: 1 addition & 4 deletions src/extension/ai/model-providers/openai.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { getConfigKey } from '@extension/config'
import { getContext } from '@extension/context'
import { ChatOpenAI, type ChatOpenAICallOptions } from '@langchain/openai'
import * as vscode from 'vscode'

import { parseModelBaseUrl } from '../parse-model-base-url'
import { BaseModelProvider } from './base'
Expand All @@ -10,7 +8,6 @@ export class OpenAIModelProvider extends BaseModelProvider<
ChatOpenAI<ChatOpenAICallOptions>
> {
async createModel() {
const isDev = getContext().extensionMode !== vscode.ExtensionMode.Production
const { url: openaiBaseUrl } = await parseModelBaseUrl()
const openaiKey = await getConfigKey('openaiKey')
const openaiModel = await getConfigKey('openaiModel')
Expand All @@ -24,7 +21,7 @@ export class OpenAIModelProvider extends BaseModelProvider<
model: openaiModel,
temperature: 0.95, // never use 1.0, some models do not support it
maxRetries: 3,
verbose: isDev
verbose: this.isDev
})

// some third-party language models are not compatible with the openAI specification,
Expand Down
57 changes: 0 additions & 57 deletions src/extension/auto-open-corresponding-files.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/extension/cleanup.ts

This file was deleted.

Loading

0 comments on commit d09c07a

Please sign in to comment.