Skip to content

Commit 47f88e5

Browse files
committed
feat(gpt-runner-web): optimize file tree popover menu request multiple
1 parent 0e021ba commit 47f88e5

File tree

18 files changed

+250
-122
lines changed

18 files changed

+250
-122
lines changed

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
"linebreak",
3434
"localstorage",
3535
"nicepkg",
36+
"nuxt",
3637
"OPENAI",
3738
"OVSE",
3839
"ovsx",
40+
"pycache",
3941
"rehype",
4042
"rubberband",
4143
"tablist",

packages/gpt-runner-core/src/core/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export async function getGptFilesInfo(params: GetGptFilesInfoParams): Promise<Ge
2424
exts = ['.gpt.md'],
2525
includes = null,
2626
excludes = null,
27-
respectGitignore = true,
27+
respectGitIgnore = true,
2828
} = resolvedUserConfig
2929

3030
const ig: Ignore | null = await (async () => {
@@ -36,7 +36,7 @@ export async function getGptFilesInfo(params: GetGptFilesInfoParams): Promise<Ge
3636
})()
3737

3838
const isGitignorePaths = (filePath: string): boolean => {
39-
if (!respectGitignore)
39+
if (!respectGitIgnore)
4040
return false
4141

4242
if (filePath && filePath.match(/\/\.git\//))

packages/gpt-runner-core/src/core/get-common-file-tree.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface CreateFileTreeParams {
1414

1515
interface CreateFileTreeReturns {
1616
tree: FileInfoTreeItem[]
17-
exts: string[]
17+
includeFileExts: string[]
1818
}
1919

2020
function createFileTree(params: CreateFileTreeParams): CreateFileTreeReturns {
@@ -34,7 +34,8 @@ function createFileTree(params: CreateFileTreeParams): CreateFileTreeReturns {
3434
const isFile = index === parts.length - 1
3535

3636
if (!pathMap.get(currentPath)) {
37-
const ext = isFile ? part.split('.').length > 1 ? part.split('.').pop() : '' : undefined
37+
const ext = isFile ? PathUtils.extname(part) : undefined
38+
3839
const tokenNum = isFile ? countFileTokens(currentPath) : 0
3940
const item = {
4041
id: currentPath,
@@ -94,7 +95,7 @@ function createFileTree(params: CreateFileTreeParams): CreateFileTreeReturns {
9495

9596
return {
9697
tree: finalTree,
97-
exts: Array.from(exts),
98+
includeFileExts: Array.from(exts),
9899
}
99100
}
100101

@@ -140,9 +141,9 @@ export async function getCommonFileTree(params: GetCommonFileTreeParams): Promis
140141
},
141142
})
142143

143-
const { tree, exts } = createFileTree({ rootPath, filePaths })
144+
const { tree, includeFileExts } = createFileTree({ rootPath, filePaths })
144145

145-
return { tree, exts }
146+
return { tree, includeFileExts }
146147
}
147148

148149
export interface CreateFileContextParams {

packages/gpt-runner-shared/src/common/helpers/config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { SingleFileConfig, UserConfig } from '../types'
2+
import { DEFAULT_EXCLUDE_FILES } from './constants'
23

34
export function singleFileConfigWithDefault(singleFileConfig?: Partial<SingleFileConfig>): SingleFileConfig {
45
return {
@@ -18,9 +19,9 @@ export function userConfigWithDefault(userConfig?: Partial<UserConfig>): UserCon
1819
},
1920
rootPath: process.cwd(),
2021
includes: null,
21-
excludes: null,
22+
excludes: DEFAULT_EXCLUDE_FILES,
2223
exts: ['.gpt.md'],
23-
respectGitignore: true,
24+
respectGitIgnore: true,
2425
...userConfig,
2526
}
2627
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
export const DEFAULT_EXCLUDE_FILES = [
2+
'node_modules',
3+
'.git',
4+
'__pycache__',
5+
'.Python',
6+
'.DS_Store',
7+
'.cache',
8+
'.next',
9+
'.nuxt',
10+
'.out',
11+
'dist/',
12+
'.serverless',
13+
'.parcel-cache',
14+
]
15+
16+
export const DEFAULT_EXCLUDE_FILE_EXTS = [
17+
'.jpg',
18+
'.png',
19+
'.gif',
20+
'.jpeg',
21+
'.svg',
22+
'.mp4',
23+
'.mp3',
24+
'.wav',
25+
'.flac',
26+
'.ogg',
27+
'.webm',
28+
'.ico',
29+
'.pdf',
30+
'.doc',
31+
'.docx',
32+
'.xls',
33+
'.xlsx',
34+
'.ppt',
35+
'.pptx',
36+
'.zip',
37+
'.rar',
38+
'.7z',
39+
'.tar',
40+
'.gz',
41+
'.tgz',
42+
'.bz2',
43+
'.xz',
44+
'.exe',
45+
'.dmg',
46+
'.pkg',
47+
'.deb',
48+
'.rpm',
49+
'.msi',
50+
'.apk',
51+
'.ipa',
52+
'.iso',
53+
'.img',
54+
'.bin',
55+
'.dll',
56+
'.so',
57+
'.dylib',
58+
'.a',
59+
'.lib',
60+
'.o',
61+
'.obj',
62+
'.class',
63+
'.jar',
64+
'.war',
65+
'.ear',
66+
'.swf',
67+
'.fla',
68+
'.as',
69+
'.as3',
70+
'.mxml',
71+
'.swc',
72+
'.swd',
73+
'.swz',
74+
'.swt',
75+
'.air',
76+
'.ane',
77+
'.ttf',
78+
'.woff',
79+
'.woff2',
80+
'.eot',
81+
'.otf',
82+
'.psd',
83+
'.ai',
84+
'.sketch',
85+
'.fig',
86+
'.xd',
87+
'.blend',
88+
'.fbx',
89+
'.obj',
90+
'.mtl',
91+
'.stl',
92+
'.3ds',
93+
'.dae',
94+
'.max',
95+
'.ma',
96+
'.mb',
97+
'.lwo',
98+
'.lws',
99+
'.lxo',
100+
'.c4d',
101+
102+
// data
103+
'.csv',
104+
'.tsv',
105+
106+
// ai
107+
'.pth',
108+
'.pt',
109+
'.h5',
110+
'.hdf5',
111+
'.ckpt',
112+
'.ckpt.index',
113+
]

packages/gpt-runner-shared/src/common/helpers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './common'
22
export * from './config'
3+
export * from './constants'
34
export * from './create-filter-pattern'
45
export * from './debug'
56
export * from './env-config'

packages/gpt-runner-shared/src/common/types/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export interface UserConfig {
8282
/**
8383
* @default true
8484
*/
85-
respectGitignore?: boolean
85+
respectGitIgnore?: boolean
8686
}
8787

8888
export interface SingleChatMessage {

packages/gpt-runner-shared/src/common/types/server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,6 @@ export interface GetCommonFilesReqParams {
7979

8080
export interface GetCommonFilesResData {
8181
filesInfoTree: FileInfoTree
82-
fileExts: string[]
82+
includeFileExts: string[]
83+
allFileExts: string[]
8384
}

packages/gpt-runner-shared/src/common/zod/config.zod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const UserConfigSchema = z.object({
3636
exts: z.array(z.string()).optional().default(['.gpt.md']),
3737
includes: FilterPatternSchema.optional().default(null),
3838
excludes: FilterPatternSchema.optional().default(null),
39-
respectGitignore: z.boolean().optional().default(true),
39+
respectGitIgnore: z.boolean().optional().default(true),
4040
}) satisfies z.ZodType<UserConfig>
4141

4242
export const SingleChatMessageSchema = z.object({

packages/gpt-runner-shared/src/node/helpers/file-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class FileUtils {
127127
if (!createFilterByPattern(includes)(filePath))
128128
return false
129129

130-
if (!createFilterByPattern(excludes)(filePath))
130+
if (createFilterByPattern(excludes)(filePath))
131131
return false
132132

133133
if (!isValidPath(filePath))

0 commit comments

Comments
 (0)