Skip to content

Commit

Permalink
feat(gpt-runner-web): add realtime gpt.md file parse
Browse files Browse the repository at this point in the history
  • Loading branch information
2214962083 committed Jun 26, 2023
1 parent 7a4360f commit c3c6beb
Show file tree
Hide file tree
Showing 38 changed files with 1,393 additions and 669 deletions.
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,42 @@
"test:ci": "pnpm build && pnpm typecheck && pnpm lint && pnpm test"
},
"devDependencies": {
"@antfu/eslint-config": "^0.38.6",
"@antfu/eslint-config": "^0.39.5",
"@nicepkg/gpt-runner": "workspace:*",
"@nicepkg/gpt-runner-cli": "workspace:*",
"@nicepkg/gpt-runner-core": "workspace:*",
"@nicepkg/gpt-runner-shared": "workspace:*",
"@types/fs-extra": "^11.0.1",
"@types/node": "^18.16.4",
"@types/prettier": "^2.7.2",
"@types/react": "^18.2.6",
"@types/prettier": "^2.7.3",
"@types/react": "^18.2.14",
"@vitejs/plugin-legacy": "^4.0.3",
"@vitest/ui": "^0.31.0",
"@vitest/ui": "^0.32.2",
"bumpp": "^9.1.0",
"eslint": "8.39.0",
"eslint": "8.43.0",
"esno": "^0.16.3",
"execa": "^7.1.1",
"fast-glob": "^3.2.12",
"fs-extra": "^11.1.1",
"jsdom": "^22.0.0",
"jsdom": "^22.1.0",
"lint-staged": "^13.2.2",
"msw": "1.0.1",
"msw": "1.2.2",
"pnpm": "8.4.0",
"prettier": "^2.8.8",
"react": "^18.2.0",
"rollup": "^3.21.5",
"rollup": "^3.25.2",
"semver": "^7.5.0",
"simple-git-hooks": "^2.8.1",
"taze": "^0.10.1",
"terser": "^5.17.1",
"tsup": "^6.7.0",
"typescript": "^5.0.4",
"terser": "^5.18.1",
"tsup": "^7.1.0",
"typescript": "^5.1.3",
"unbuild": "^0.8.11",
"unplugin-auto-import": "^0.15.3",
"vite": "^4.3.5",
"vite-plugin-inspect": "^0.7.25",
"vite-plugin-pages": "^0.29.0",
"vitest": "^0.31.0"
"unplugin-auto-import": "^0.16.4",
"vite": "^4.3.9",
"vite-plugin-inspect": "^0.7.29",
"vite-plugin-pages": "^0.31.0",
"vitest": "^0.32.2"
},
"pnpm": {
"overrides": {
Expand All @@ -75,4 +75,4 @@
"eslint --cache --fix"
]
}
}
}
4 changes: 2 additions & 2 deletions packages/gpt-runner-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"dependencies": {
"@nicepkg/gpt-runner-shared": "workspace:*",
"ignore": "^5.2.4",
"langchain": "^0.0.95",
"langchain": "^0.0.96",
"unconfig": "^0.3.9"
}
}
}
2 changes: 2 additions & 0 deletions packages/gpt-runner-core/src/core/load-user-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export async function loadUserConfig<U extends IUserConfig = IUserConfig>(
: [
{
files: [
'.gpt-runner/gpt-runner.config',
'.gpt-runner/gptr.config',
'gpt-runner.config',
'gptr.config',
],
Expand Down
10 changes: 5 additions & 5 deletions packages/gpt-runner-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@
"https-proxy-agent": "^7.0.0",
"ip": "^1.1.8",
"launch-editor": "^2.6.0",
"minimatch": "^9.0.1",
"minimatch": "^9.0.2",
"open": "^8.4.2",
"socket.io": "^4.6.2",
"socket.io-client": "^4.6.2",
"socket.io": "^4.7.0",
"socket.io-client": "^4.7.0",
"zod": "^3.21.4",
"zod-to-json-schema": "^3.21.1"
"zod-to-json-schema": "^3.21.2"
},
"devDependencies": {
"@types/express": "^4.17.17",
"@types/ip": "^1.1.0",
"express": "^4.18.2"
}
}
}
4 changes: 2 additions & 2 deletions packages/gpt-runner-shared/scripts/zod-to-json-schema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { zodToJsonSchema } from 'zod-to-json-schema'
import { SingleFileConfigSchema, UserConfigSchema } from '../src/common'
import { SingleFileConfigSchema, UserConfigForUserSchema } from '../src/common'
import { FileUtils, PathUtils } from '../src/node'

const userConfigJsonSchema = zodToJsonSchema(UserConfigSchema)
const userConfigJsonSchema = zodToJsonSchema(UserConfigForUserSchema)
const singleFileJsonSchema = zodToJsonSchema(SingleFileConfigSchema)

interface JsonSchemaFile {
Expand Down
1 change: 1 addition & 0 deletions packages/gpt-runner-shared/src/common/types/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface SingleChat {
inputtingPrompt: string
systemPrompt: string
messages: SingleChatMessage[]
singleFilePath: string
singleFileConfig: SingleFileConfig
status: ChatMessageStatus
createAt: number
Expand Down
2 changes: 2 additions & 0 deletions packages/gpt-runner-shared/src/common/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ export interface UserConfig {
respectGitIgnore?: boolean
}

export type UserConfigForUser = Omit<UserConfig, 'rootPath'>

export interface SingleChatMessage {
name: ChatRole
text: string
Expand Down
2 changes: 2 additions & 0 deletions packages/gpt-runner-shared/src/common/types/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export enum ChatMessageStatus {

export enum ClientEventName {
RefreshTree = 'refreshTree',
RefreshChatTree = 'refreshChatTree',
RefreshFileTree = 'refreshFileTree',
InsertCodes = 'insertCodes',
DiffCodes = 'diffCodes',
}
Expand Down
4 changes: 4 additions & 0 deletions packages/gpt-runner-shared/src/common/types/eventemitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import type { ClientEventName } from './enum'
export interface ClientEventData {
[ClientEventName.RefreshTree]: void

[ClientEventName.RefreshChatTree]: void

[ClientEventName.RefreshFileTree]: void

[ClientEventName.InsertCodes]: {
codes: string
}
Expand Down
12 changes: 12 additions & 0 deletions packages/gpt-runner-shared/src/common/types/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,19 @@ export type FailResponse<T = any> = Omit<BaseResponse<T>, 'type'> & { type: 'Fai
export interface ChatStreamReqParams {
messages: SingleChatMessage[]
prompt: string

/**
* most times we don't use systemPrompt, we parse .gpt.md file
* and get the real time systemPrompt and then provide systemPrompt + appendSystemPrompt to LangchainJs
*/
systemPrompt?: string
appendSystemPrompt?: string
singleFilePath?: string

/**
* most times we don't use singleFileConfig, we parse .gpt.md file
* and get the real time singleFileConfig and then provide singleFileConfig to LangchainJs
*/
singleFileConfig?: SingleFileConfig
contextFilePaths?: string[]
rootPath?: string
Expand Down
6 changes: 5 additions & 1 deletion packages/gpt-runner-shared/src/common/zod/config.zod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from 'zod'
import type { BaseModelConfig, FilterPattern, FormCheckboxGroupConfig, FormFieldBaseConfig, FormInputConfig, FormItemConfig, FormOption, FormRadioGroupConfig, FormSelectConfig, FormTextareaConfig, OpenaiModelConfig, OpenaiSecrets, SingleChatMessage, SingleFileConfig, UserConfig } from '../types'
import type { BaseModelConfig, FilterPattern, FormCheckboxGroupConfig, FormFieldBaseConfig, FormInputConfig, FormItemConfig, FormOption, FormRadioGroupConfig, FormSelectConfig, FormTextareaConfig, OpenaiModelConfig, OpenaiSecrets, SingleChatMessage, SingleFileConfig, UserConfig, UserConfigForUser } from '../types'
import { ChatModelTypeSchema, ChatRoleSchema } from './enum.zod'

export const FilterPatternSchema = z.union([
Expand Down Expand Up @@ -48,6 +48,10 @@ export const UserConfigSchema = z.object({
respectGitIgnore: z.boolean().optional().default(true),
}) satisfies z.ZodType<UserConfig>

export const UserConfigForUserSchema = UserConfigSchema.omit({
rootPath: true,
}) satisfies z.ZodType<UserConfigForUser>

export const SingleChatMessageSchema = z.object({
name: ChatRoleSchema,
text: z.string(),
Expand Down
2 changes: 2 additions & 0 deletions packages/gpt-runner-shared/src/common/zod/server.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export const ChatStreamReqParamsSchema = z.object({
messages: z.array(SingleChatMessageSchema),
prompt: z.string(),
systemPrompt: z.string().optional(),
appendSystemPrompt: z.string().optional(),
singleFilePath: z.string().optional(),
singleFileConfig: SingleFileConfigSchema.optional(),
contextFilePaths: z.array(z.string()).optional(),
rootPath: z.string().optional(),
Expand Down
3 changes: 3 additions & 0 deletions packages/gpt-runner-web/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
...window.__GLOBAL_CONFIG__ || {},
}
}

// change locale language to navigator language
document.documentElement.lang = window.navigator.language
</script>
<script>
// before-script
Expand Down
1 change: 1 addition & 0 deletions packages/gpt-runner-web/client/public/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"delete_chat_btn": "Chat löschen",
"refresh_btn": "Aktualisieren",
"filter_btn": "Filtern",
"pin_up_btn": "Anheften",
"file_tree_top_tokens_tips": "<FileNumWrapper>{{fileNum}}</FileNumWrapper> Dateien <TokenNumWrapper>{{tokenNum}}</TokenNumWrapper> Tokens.",
"file_tree_top_clear_checked_btn": "Auswahl aufheben",
"file_tree_top_all_file_path_as_prompt": "Alle Dateipfade als Vorschlag {{tokenNum}} Tokens",
Expand Down
1 change: 1 addition & 0 deletions packages/gpt-runner-web/client/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"delete_chat_btn": "Delete Chat",
"refresh_btn": "Refresh",
"filter_btn": "Filter",
"pin_up_btn": "Pin Up",
"file_tree_top_tokens_tips": "<FileNumWrapper>{{fileNum}}</FileNumWrapper> Files <TokenNumWrapper>{{tokenNum}}</TokenNumWrapper> Tokens.",
"file_tree_top_clear_checked_btn": "Clear Checked",
"file_tree_top_all_file_path_as_prompt": "All file path as prompt {{tokenNum}} tokens",
Expand Down
1 change: 1 addition & 0 deletions packages/gpt-runner-web/client/public/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"delete_chat_btn": "チャットを削除",
"refresh_btn": "更新",
"filter_btn": "フィルター",
"pin_up_btn": "ピンアップ",
"file_tree_top_tokens_tips": "<FileNumWrapper>{{fileNum}}</FileNumWrapper>個のファイル、合計<TokenNumWrapper>{{tokenNum}}</TokenNumWrapper>トークン。",
"file_tree_top_clear_checked_btn": "選択をクリア",
"file_tree_top_all_file_path_as_prompt": "すべてのファイルパスをプロンプトとして使用、合計{{tokenNum}}トークン",
Expand Down
1 change: 1 addition & 0 deletions packages/gpt-runner-web/client/public/locales/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"delete_chat_btn": "删除聊天",
"refresh_btn": "刷新",
"filter_btn": "筛选",
"pin_up_btn": "钉住",
"file_tree_top_tokens_tips": "<FileNumWrapper>{{fileNum}}</FileNumWrapper>个文件,共<TokenNumWrapper>{{tokenNum}}</TokenNumWrapper>个 tokens。",
"file_tree_top_clear_checked_btn": "清除选中",
"file_tree_top_all_file_path_as_prompt": "将所有文件路径作为提示,共 {{tokenNum}} 个 tokens",
Expand Down
1 change: 1 addition & 0 deletions packages/gpt-runner-web/client/public/locales/zh_Hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"delete_chat_btn": "刪除聊天",
"refresh_btn": "刷新",
"filter_btn": "篩選",
"pin_up_btn": "钉住",
"file_tree_top_tokens_tips": "<FileNumWrapper>{{fileNum}}</FileNumWrapper>個文件,共<TokenNumWrapper>{{tokenNum}}</TokenNumWrapper>個 tokens。",
"file_tree_top_clear_checked_btn": "清除選中",
"file_tree_top_all_file_path_as_prompt": "將所有文件路徑作為提示,共 {{tokenNum}} 個 tokens",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function HookFormInput_<
{...{
...otherProps,
...(typeof filterField === 'function'
? filterField(field)
? filterField(field as any)
: field),
}}
>{label}</StyledVSCodeTextField>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function HookFormSelect_<
{...{
...otherProps,
...(typeof filterField === 'function'
? filterField(field)
? filterField(field as any)
: field),
onChange: (e: any) => {
field.onChange(e.target.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function HookFormSwitch_<
{...{
...otherProps,
...(typeof filterField === 'function'
? filterField(field)
? filterField(field as any)
: field),
checked: field.value,
onChange: (e: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function HookFormTextarea_<
{...{
...otherProps,
...(typeof filterField === 'function'
? filterField(field)
? filterField(field as any)
: field),
}}
>{label}</StyledVSCodeTextArea>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface IconButtonProps extends GetComponentProps<InstanceType<typeof V
to: Target
}
animatingWhenClick?: boolean
onClick?: () => MaybePromise<void>
onClick?: () => MaybePromise<any>
buttonStyle?: React.CSSProperties
}

Expand Down
2 changes: 2 additions & 0 deletions packages/gpt-runner-web/client/src/components/icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export const Icon: FC<IconProps> = memo((props) => {
<span
style={{
fontSize: 'inherit',
cursor: 'pointer',
color: 'inherit',
...style,
}}
className={clsx(
Expand Down
Loading

0 comments on commit c3c6beb

Please sign in to comment.