Skip to content

Commit 93704ab

Browse files
committed
feat(gpt-runner-web): add file tree component
1 parent 5701cf6 commit 93704ab

File tree

33 files changed

+743
-91
lines changed

33 files changed

+743
-91
lines changed

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
"codicon",
2121
"colorette",
2222
"consola",
23+
"dylib",
2324
"esbuild",
2425
"esno",
2526
"execa",
27+
"flac",
2628
"gptr",
2729
"hideable",
2830
"Jinming",

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export async function getGptFilesInfo(params: GetGptFilesInfoParams): Promise<Ge
3939
if (!respectGitignore)
4040
return false
4141

42+
if (filePath && filePath.match(/\/\.git\//))
43+
return true
44+
4245
const relativePath = PathUtils.relative(rootPath, filePath)
4346

4447
return ig?.ignores(relativePath) ?? false

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { dirname, resolve } from 'node:path'
21
import fs from 'node:fs'
2+
import { PathUtils } from '@nicepkg/gpt-runner-shared/node'
33
import type { LoadConfigResult, LoadConfigSource } from 'unconfig'
44
import { createConfigLoader as createLoader } from 'unconfig'
55
import type { UserConfig } from '@nicepkg/gpt-runner-shared/common'
@@ -28,12 +28,12 @@ export async function loadUserConfig<U extends IUserConfig = IUserConfig>(
2828
}
2929
}
3030

31-
const resolved = resolve(configOrPath)
31+
const resolved = PathUtils.resolve(configOrPath)
3232

3333
let isFile = false
3434
if (fs.existsSync(resolved) && fs.statSync(resolved).isFile()) {
3535
isFile = true
36-
cwd = dirname(resolved)
36+
cwd = PathUtils.dirname(resolved)
3737
}
3838

3939
const loader = createLoader<U>({

packages/gpt-runner-core/src/core/parser/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import path from 'node:path'
21
import type { SingleFileConfig, UserConfig } from '@nicepkg/gpt-runner-shared/common'
32
import { resolveSingleFileConfig } from '@nicepkg/gpt-runner-shared/common'
3+
import { PathUtils } from '@nicepkg/gpt-runner-shared/node'
44
import { gptMdFileParser } from './md'
55

66
export interface parseGptFileParams {
@@ -11,7 +11,7 @@ export interface parseGptFileParams {
1111
export async function parseGptFile(params: parseGptFileParams): Promise<SingleFileConfig> {
1212
const { filePath, userConfig } = params
1313

14-
const ext = path.extname(filePath)
14+
const ext = PathUtils.extname(filePath)
1515

1616
switch (ext) {
1717
case '.md':

packages/gpt-runner-core/src/smol-ai/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class Api {
1919
userPrompt,
2020
openaiKey,
2121
histories = [],
22-
model = 'gpt-3.5-turbo',
22+
model = 'gpt-3.5-turbo-16k',
2323
maxTokens = 2000,
2424
temperature = 0,
2525
}: AskGPTParams) {

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,30 @@ export function urlRemoveLocalhost(url: string | null | undefined): string {
170170
return url
171171
}
172172
}
173+
174+
export function objectToQueryString(obj: Record<string, any>, prefix?: string): string {
175+
const queryStringArray: string[] = []
176+
177+
for (const key in obj) {
178+
if (hasOwn(obj, key)) {
179+
const value = obj[key]
180+
const encodedKey = encodeURIComponent(prefix ? `${prefix}[${key}]` : key)
181+
182+
if (Array.isArray(value)) {
183+
for (const item of value) {
184+
queryStringArray.push(
185+
`${encodedKey}[]=${encodeURIComponent(item)}`,
186+
)
187+
}
188+
}
189+
else if (typeof value === 'object' && value !== null) {
190+
queryStringArray.push(objectToQueryString(value, encodedKey))
191+
}
192+
else {
193+
queryStringArray.push(`${encodedKey}=${encodeURIComponent(value)}`)
194+
}
195+
}
196+
}
197+
198+
return queryStringArray.join('&')
199+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function userConfigWithDefault(userConfig?: Partial<UserConfig>): UserCon
1111
model: {
1212
type: 'openai',
1313
openaiKey: process.env.OPENAI_KEY!,
14-
modelName: 'gpt-3.5-turbo',
14+
modelName: 'gpt-3.5-turbo-16k',
1515
temperature: 0.9,
1616
maxTokens: 2000,
1717
...userConfig?.model,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { TreeItem } from './common'
2+
3+
export interface FileBaseInfo {
4+
id: string
5+
parentId: string | null
6+
projectRelativePath: string
7+
fullPath: string
8+
name: string
9+
}
10+
11+
export interface FileInfo extends FileBaseInfo {
12+
isFile: true
13+
ext: string
14+
}
15+
16+
export interface FolderInfo extends FileBaseInfo {
17+
isFile: false
18+
}
19+
20+
export type FileInfoTreeItem = TreeItem<FolderInfo | FileInfo>
21+
export type FileInfoTree = FileInfoTreeItem[]

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

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { FilterPattern, TreeItem } from './common'
2-
import type { ChatRole, GptFileTreeItemType } from './enum'
1+
import type { FilterPattern } from './common'
2+
import type { ChatRole } from './enum'
33

44
export interface BaseModelConfig {
55
/**
@@ -85,32 +85,6 @@ export interface UserConfig {
8585
respectGitignore?: boolean
8686
}
8787

88-
export interface GptPathBaseInfo {
89-
id: string
90-
parentId: string | null
91-
path: string
92-
name: string
93-
type: GptFileTreeItemType
94-
}
95-
96-
export interface GptFileInfo extends GptPathBaseInfo {
97-
type: GptFileTreeItemType.File
98-
content: string
99-
singleFileConfig: SingleFileConfig
100-
}
101-
102-
export interface GptFolderInfo extends GptPathBaseInfo {
103-
type: GptFileTreeItemType.Folder
104-
}
105-
106-
export interface GptChatInfo extends GptPathBaseInfo {
107-
type: GptFileTreeItemType.Chat
108-
createAt: number
109-
}
110-
111-
export type GptFileInfoTreeItem = TreeItem<GptFolderInfo | GptFileInfo | GptChatInfo>
112-
export type GptFileInfoTree = GptFileInfoTreeItem[]
113-
11488
export interface SingleChatMessage {
11589
name: ChatRole
11690
text: string
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { TreeItem } from './common'
2+
import type { SingleFileConfig } from './config'
3+
import type { GptFileTreeItemType } from './enum'
4+
5+
export interface GptPathBaseInfo {
6+
id: string
7+
parentId: string | null
8+
path: string
9+
name: string
10+
type: GptFileTreeItemType
11+
}
12+
13+
export interface GptFileInfo extends GptPathBaseInfo {
14+
type: GptFileTreeItemType.File
15+
content: string
16+
singleFileConfig: SingleFileConfig
17+
}
18+
19+
export interface GptFolderInfo extends GptPathBaseInfo {
20+
type: GptFileTreeItemType.Folder
21+
}
22+
23+
export interface GptChatInfo extends GptPathBaseInfo {
24+
type: GptFileTreeItemType.Chat
25+
createAt: number
26+
}
27+
28+
export type GptFileInfoTreeItem = TreeItem<GptFolderInfo | GptFileInfo | GptChatInfo>
29+
export type GptFileInfoTree = GptFileInfoTreeItem[]

0 commit comments

Comments
 (0)