Skip to content

Commit 6416606

Browse files
committed
feat(gpt-runner-web): add new chat in sidebar
1 parent 18f4e35 commit 6416606

File tree

35 files changed

+689
-218
lines changed

35 files changed

+689
-218
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"tagify",
2424
"tanstack",
2525
"unconfig",
26+
"uuidv",
2627
"zustand"
2728
],
2829
"workbench.colorCustomizations": {

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

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,10 @@
1-
import type { GptFileInfo, GptFileInfoTree, GptFileInfoTreeItem, SingleFileConfig, UserConfig } from '@nicepkg/gpt-runner-shared/common'
2-
import { GptFileTreeItemType } from '@nicepkg/gpt-runner-shared/common'
1+
import type { GptFileInfo, GptFileInfoTree, GptFileInfoTreeItem, UserConfig } from '@nicepkg/gpt-runner-shared/common'
2+
import { GptFileTreeItemType, userConfigWithDefault } from '@nicepkg/gpt-runner-shared/common'
33
import { FileUtils, PathUtils } from '@nicepkg/gpt-runner-shared/node'
44
import type { Ignore } from 'ignore'
55
import ignore from 'ignore'
66
import { parseGptFile } from './parser'
77

8-
export function singleFileConfigWithDefault(singleFileConfig?: Partial<SingleFileConfig>): SingleFileConfig {
9-
return {
10-
...singleFileConfig,
11-
}
12-
}
13-
14-
export function userConfigWithDefault(userConfig?: Partial<UserConfig>): UserConfig {
15-
return {
16-
model: {
17-
type: 'openai',
18-
openaiKey: process.env.OPENAI_KEY!,
19-
modelName: 'gpt-3.5-turbo',
20-
temperature: 0.9,
21-
maxTokens: 2000,
22-
...userConfig?.model,
23-
},
24-
rootPath: process.cwd(),
25-
includes: null,
26-
excludes: null,
27-
exts: ['.gpt.md'],
28-
respectGitignore: true,
29-
...userConfig,
30-
}
31-
}
32-
33-
export interface ResolveSingleFileCConfigParams {
34-
userConfig: UserConfig
35-
singleFileConfig: SingleFileConfig
36-
}
37-
38-
export function resolveSingleFileConfig(params: ResolveSingleFileCConfigParams): SingleFileConfig {
39-
const userConfig = userConfigWithDefault(params.userConfig)
40-
const singleFileConfig = singleFileConfigWithDefault(params.singleFileConfig)
41-
42-
const resolvedConfig: SingleFileConfig = {
43-
...singleFileConfig,
44-
model: {
45-
...userConfig.model,
46-
...singleFileConfig.model,
47-
} as SingleFileConfig['model'],
48-
}
49-
50-
return resolvedConfig
51-
}
52-
538
export interface GetGptFilesInfoParams {
549
userConfig: UserConfig
5510
}
@@ -122,8 +77,11 @@ export async function getGptFilesInfo(params: GetGptFilesInfoParams): Promise<Ge
12277

12378
const parentTitleParts = titleParts.slice(0, -1)
12479

80+
const fileId = title || filePath
81+
12582
const fileInfo: GptFileInfo = {
126-
id: title,
83+
id: fileId,
84+
parentId: null,
12785
path: filePath,
12886
name: getName(title, filePath),
12987
content,
@@ -139,13 +97,14 @@ export async function getGptFilesInfo(params: GetGptFilesInfoParams): Promise<Ge
13997
if (!parentFileInfo.children)
14098
parentFileInfo.children = []
14199

142-
parentFileInfo.children.push({ ...fileInfo })
100+
parentFileInfo.children.push({ ...fileInfo, parentId: parentFileInfo.id })
143101
}
144102
else {
145103
const parentPath = ''
146104

147105
const parentFileInfo: GptFileInfoTreeItem = {
148106
id: parentTitle,
107+
parentId: null,
149108
path: parentPath,
150109
name: getName(parentTitle, parentPath),
151110
type: GptFileTreeItemType.Folder,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fs from 'node:fs'
33
import type { LoadConfigResult, LoadConfigSource } from 'unconfig'
44
import { createConfigLoader as createLoader } from 'unconfig'
55
import type { UserConfig } from '@nicepkg/gpt-runner-shared/common'
6-
import { userConfigWithDefault } from './config'
6+
import { userConfigWithDefault } from '@nicepkg/gpt-runner-shared/common'
77

88
export type { LoadConfigResult, LoadConfigSource }
99
export type IUserConfig = UserConfig & { configFile?: false | string }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'node:path'
22
import type { SingleFileConfig, UserConfig } from '@nicepkg/gpt-runner-shared/common'
3-
import { resolveSingleFileConfig } from '../config'
3+
import { resolveSingleFileConfig } from '@nicepkg/gpt-runner-shared/common'
44
import { gptMdFileParser } from './md'
55

66
export interface parseGptFileParams {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { SingleFileConfig, UserConfig } from '@nicepkg/gpt-runner-shared/common'
2-
import { tryParseJson } from '@nicepkg/gpt-runner-shared/common'
2+
import { resolveSingleFileConfig, singleFileConfigWithDefault, tryParseJson } from '@nicepkg/gpt-runner-shared/common'
33
import { FileUtils } from '@nicepkg/gpt-runner-shared/node'
4-
import { resolveSingleFileConfig, singleFileConfigWithDefault } from '../config'
54

65
export interface GptMdFileParserParams {
76
filePath: string
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import type { SingleFileConfig, UserConfig } from '../types'
2+
3+
export function singleFileConfigWithDefault(singleFileConfig?: Partial<SingleFileConfig>): SingleFileConfig {
4+
return {
5+
...singleFileConfig,
6+
}
7+
}
8+
9+
export function userConfigWithDefault(userConfig?: Partial<UserConfig>): UserConfig {
10+
return {
11+
model: {
12+
type: 'openai',
13+
openaiKey: process.env.OPENAI_KEY!,
14+
modelName: 'gpt-3.5-turbo',
15+
temperature: 0.9,
16+
maxTokens: 2000,
17+
...userConfig?.model,
18+
},
19+
rootPath: process.cwd(),
20+
includes: null,
21+
excludes: null,
22+
exts: ['.gpt.md'],
23+
respectGitignore: true,
24+
...userConfig,
25+
}
26+
}
27+
28+
export interface ResolveSingleFileCConfigParams {
29+
userConfig: UserConfig
30+
singleFileConfig: SingleFileConfig
31+
}
32+
33+
export function resolveSingleFileConfig(params: ResolveSingleFileCConfigParams, withDefault = true): SingleFileConfig {
34+
const userConfig = withDefault ? userConfigWithDefault(params.userConfig) : params.userConfig
35+
const singleFileConfig = withDefault ? singleFileConfigWithDefault(params.singleFileConfig) : params.singleFileConfig
36+
37+
const resolvedConfig: SingleFileConfig = {
38+
...singleFileConfig,
39+
model: {
40+
...userConfig.model,
41+
...singleFileConfig.model,
42+
} as SingleFileConfig['model'],
43+
}
44+
45+
return resolvedConfig
46+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './common'
2+
export * from './config'
23
export * from './create-filter-pattern'
34
export * from './debug'
45
export * from './env-config'
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import type { SingleChatMessage } from './config'
1+
import type { SingleChatMessage, SingleFileConfig } from './config'
22
import type { ChatMessageStatus } from './enum'
33

44
export interface SingleChat {
55
id: string
6-
title: string
6+
name: string
77
inputtingPrompt: string
88
systemPrompt: string
9-
temperature: number
109
messages: SingleChatMessage[]
10+
singleFileConfig: SingleFileConfig
1111
status: ChatMessageStatus
1212
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export interface UserConfig {
8787

8888
export interface GptPathBaseInfo {
8989
id: string
90+
parentId: string | null
9091
path: string
9192
name: string
9293
type: GptFileTreeItemType
@@ -102,7 +103,12 @@ export interface GptFolderInfo extends GptPathBaseInfo {
102103
type: GptFileTreeItemType.Folder
103104
}
104105

105-
export type GptFileInfoTreeItem = TreeItem<GptFolderInfo | GptFileInfo>
106+
export interface GptChatInfo extends GptPathBaseInfo {
107+
type: GptFileTreeItemType.Chat
108+
singleFileConfig: SingleFileConfig
109+
}
110+
111+
export type GptFileInfoTreeItem = TreeItem<GptFolderInfo | GptFileInfo | GptChatInfo>
106112
export type GptFileInfoTree = GptFileInfoTreeItem[]
107113

108114
export interface SingleChatMessage {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export enum ChatRole {
55
}
66

77
export enum ChatMessageStatus {
8-
Idle = 'idle',
98
Pending = 'pending',
109
Success = 'success',
1110
Error = 'error',

0 commit comments

Comments
 (0)