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'
3
3
import { FileUtils , PathUtils } from '@nicepkg/gpt-runner-shared/node'
4
4
import type { Ignore } from 'ignore'
5
5
import ignore from 'ignore'
6
6
import { parseGptFile } from './parser'
7
7
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
-
53
8
export interface GetGptFilesInfoParams {
54
9
userConfig : UserConfig
55
10
}
@@ -122,8 +77,11 @@ export async function getGptFilesInfo(params: GetGptFilesInfoParams): Promise<Ge
122
77
123
78
const parentTitleParts = titleParts . slice ( 0 , - 1 )
124
79
80
+ const fileId = title || filePath
81
+
125
82
const fileInfo : GptFileInfo = {
126
- id : title ,
83
+ id : fileId ,
84
+ parentId : null ,
127
85
path : filePath ,
128
86
name : getName ( title , filePath ) ,
129
87
content,
@@ -139,13 +97,14 @@ export async function getGptFilesInfo(params: GetGptFilesInfoParams): Promise<Ge
139
97
if ( ! parentFileInfo . children )
140
98
parentFileInfo . children = [ ]
141
99
142
- parentFileInfo . children . push ( { ...fileInfo } )
100
+ parentFileInfo . children . push ( { ...fileInfo , parentId : parentFileInfo . id } )
143
101
}
144
102
else {
145
103
const parentPath = ''
146
104
147
105
const parentFileInfo : GptFileInfoTreeItem = {
148
106
id : parentTitle ,
107
+ parentId : null ,
149
108
path : parentPath ,
150
109
name : getName ( parentTitle , parentPath ) ,
151
110
type : GptFileTreeItemType . Folder ,
0 commit comments