@lobehub/chat 1.81.3 → 1.81.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +1 -0
- package/.github/workflows/release.yml +5 -0
- package/.github/workflows/test.yml +5 -0
- package/CHANGELOG.md +58 -0
- package/changelog/v1.json +21 -0
- package/locales/ar/common.json +2 -0
- package/locales/ar/electron.json +32 -0
- package/locales/ar/models.json +129 -3
- package/locales/ar/plugin.json +1 -0
- package/locales/ar/tool.json +25 -0
- package/locales/bg-BG/common.json +2 -0
- package/locales/bg-BG/electron.json +32 -0
- package/locales/bg-BG/models.json +129 -3
- package/locales/bg-BG/plugin.json +1 -0
- package/locales/bg-BG/tool.json +25 -0
- package/locales/de-DE/common.json +2 -0
- package/locales/de-DE/electron.json +32 -0
- package/locales/de-DE/models.json +129 -3
- package/locales/de-DE/plugin.json +1 -0
- package/locales/de-DE/tool.json +25 -0
- package/locales/en-US/common.json +2 -0
- package/locales/en-US/electron.json +32 -0
- package/locales/en-US/models.json +129 -3
- package/locales/en-US/plugin.json +1 -0
- package/locales/en-US/tool.json +25 -0
- package/locales/es-ES/common.json +2 -0
- package/locales/es-ES/electron.json +32 -0
- package/locales/es-ES/models.json +129 -3
- package/locales/es-ES/plugin.json +1 -0
- package/locales/es-ES/tool.json +25 -0
- package/locales/fa-IR/common.json +2 -0
- package/locales/fa-IR/electron.json +32 -0
- package/locales/fa-IR/models.json +129 -3
- package/locales/fa-IR/plugin.json +1 -0
- package/locales/fa-IR/tool.json +25 -0
- package/locales/fr-FR/common.json +2 -0
- package/locales/fr-FR/electron.json +32 -0
- package/locales/fr-FR/models.json +129 -3
- package/locales/fr-FR/plugin.json +1 -0
- package/locales/fr-FR/tool.json +25 -0
- package/locales/it-IT/common.json +2 -0
- package/locales/it-IT/electron.json +32 -0
- package/locales/it-IT/models.json +129 -3
- package/locales/it-IT/plugin.json +1 -0
- package/locales/it-IT/tool.json +25 -0
- package/locales/ja-JP/common.json +2 -0
- package/locales/ja-JP/electron.json +32 -0
- package/locales/ja-JP/models.json +129 -3
- package/locales/ja-JP/plugin.json +1 -0
- package/locales/ja-JP/tool.json +25 -0
- package/locales/ko-KR/common.json +2 -0
- package/locales/ko-KR/electron.json +32 -0
- package/locales/ko-KR/models.json +129 -3
- package/locales/ko-KR/plugin.json +1 -0
- package/locales/ko-KR/tool.json +25 -0
- package/locales/nl-NL/common.json +2 -0
- package/locales/nl-NL/electron.json +32 -0
- package/locales/nl-NL/models.json +129 -3
- package/locales/nl-NL/plugin.json +1 -0
- package/locales/nl-NL/tool.json +25 -0
- package/locales/pl-PL/common.json +2 -0
- package/locales/pl-PL/electron.json +32 -0
- package/locales/pl-PL/models.json +129 -3
- package/locales/pl-PL/plugin.json +1 -0
- package/locales/pl-PL/tool.json +25 -0
- package/locales/pt-BR/common.json +2 -0
- package/locales/pt-BR/electron.json +32 -0
- package/locales/pt-BR/models.json +129 -3
- package/locales/pt-BR/plugin.json +1 -0
- package/locales/pt-BR/tool.json +25 -0
- package/locales/ru-RU/common.json +2 -0
- package/locales/ru-RU/electron.json +32 -0
- package/locales/ru-RU/models.json +129 -3
- package/locales/ru-RU/plugin.json +1 -0
- package/locales/ru-RU/tool.json +25 -0
- package/locales/tr-TR/common.json +2 -0
- package/locales/tr-TR/electron.json +32 -0
- package/locales/tr-TR/models.json +129 -3
- package/locales/tr-TR/plugin.json +1 -0
- package/locales/tr-TR/tool.json +25 -0
- package/locales/vi-VN/common.json +2 -0
- package/locales/vi-VN/electron.json +32 -0
- package/locales/vi-VN/models.json +129 -3
- package/locales/vi-VN/plugin.json +1 -0
- package/locales/vi-VN/tool.json +25 -0
- package/locales/zh-CN/common.json +2 -0
- package/locales/zh-CN/electron.json +32 -0
- package/locales/zh-CN/models.json +134 -8
- package/locales/zh-CN/plugin.json +1 -0
- package/locales/zh-CN/tool.json +25 -0
- package/locales/zh-TW/common.json +2 -0
- package/locales/zh-TW/electron.json +32 -0
- package/locales/zh-TW/models.json +129 -3
- package/locales/zh-TW/plugin.json +1 -0
- package/locales/zh-TW/tool.json +25 -0
- package/package.json +4 -3
- package/packages/electron-client-ipc/src/events/index.ts +5 -5
- package/packages/electron-client-ipc/src/events/localFile.ts +22 -0
- package/packages/electron-client-ipc/src/events/{file.ts → upload.ts} +1 -1
- package/packages/electron-client-ipc/src/types/index.ts +2 -1
- package/packages/electron-client-ipc/src/types/localFile.ts +52 -0
- package/packages/file-loaders/README.md +63 -0
- package/packages/file-loaders/package.json +42 -0
- package/packages/file-loaders/src/index.ts +2 -0
- package/packages/file-loaders/src/loadFile.ts +206 -0
- package/packages/file-loaders/src/loaders/docx/__snapshots__/index.test.ts.snap +74 -0
- package/packages/file-loaders/src/loaders/docx/fixtures/test.docx +0 -0
- package/packages/file-loaders/src/loaders/docx/index.test.ts +41 -0
- package/packages/file-loaders/src/loaders/docx/index.ts +73 -0
- package/packages/file-loaders/src/loaders/excel/__snapshots__/index.test.ts.snap +58 -0
- package/packages/file-loaders/src/loaders/excel/fixtures/test.xlsx +0 -0
- package/packages/file-loaders/src/loaders/excel/index.test.ts +47 -0
- package/packages/file-loaders/src/loaders/excel/index.ts +121 -0
- package/packages/file-loaders/src/loaders/index.ts +19 -0
- package/packages/file-loaders/src/loaders/pdf/__snapshots__/index.test.ts.snap +98 -0
- package/packages/file-loaders/src/loaders/pdf/index.test.ts +49 -0
- package/packages/file-loaders/src/loaders/pdf/index.ts +133 -0
- package/packages/file-loaders/src/loaders/pptx/__snapshots__/index.test.ts.snap +40 -0
- package/packages/file-loaders/src/loaders/pptx/fixtures/test.pptx +0 -0
- package/packages/file-loaders/src/loaders/pptx/index.test.ts +47 -0
- package/packages/file-loaders/src/loaders/pptx/index.ts +186 -0
- package/packages/file-loaders/src/loaders/text/__snapshots__/index.test.ts.snap +15 -0
- package/packages/file-loaders/src/loaders/text/fixtures/test.txt +2 -0
- package/packages/file-loaders/src/loaders/text/index.test.ts +38 -0
- package/packages/file-loaders/src/loaders/text/index.ts +53 -0
- package/packages/file-loaders/src/types.ts +200 -0
- package/packages/file-loaders/src/utils/isTextReadableFile.ts +68 -0
- package/packages/file-loaders/src/utils/parser-utils.ts +112 -0
- package/packages/file-loaders/test/__snapshots__/loaders.test.ts.snap +93 -0
- package/packages/file-loaders/test/fixtures/test.csv +4 -0
- package/packages/file-loaders/test/fixtures/test.docx +0 -0
- package/packages/file-loaders/test/fixtures/test.epub +0 -0
- package/packages/file-loaders/test/fixtures/test.md +3 -0
- package/packages/file-loaders/test/fixtures/test.pptx +0 -0
- package/packages/file-loaders/test/fixtures/test.txt +3 -0
- package/packages/file-loaders/test/loaders.test.ts +39 -0
- package/scripts/prebuild.mts +5 -1
- package/src/app/(backend)/trpc/desktop/[trpc]/route.ts +26 -0
- package/src/features/Conversation/Messages/Assistant/Tool/Render/Arguments/ObjectEntity.tsx +81 -0
- package/src/features/Conversation/Messages/Assistant/Tool/Render/Arguments/ValueCell.tsx +43 -0
- package/src/features/Conversation/Messages/Assistant/Tool/Render/Arguments/index.tsx +120 -0
- package/src/features/Conversation/Messages/Assistant/Tool/Render/CustomRender.tsx +75 -2
- package/src/features/Conversation/Messages/Assistant/Tool/Render/KeyValueEditor.tsx +214 -0
- package/src/features/User/UserPanel/useMenu.tsx +8 -1
- package/src/libs/agent-runtime/google/index.ts +3 -0
- package/src/libs/trpc/client/desktop.ts +14 -0
- package/src/locales/default/common.ts +2 -0
- package/src/locales/default/electron.ts +34 -0
- package/src/locales/default/index.ts +2 -0
- package/src/locales/default/tool.ts +25 -0
- package/src/server/routers/desktop/index.ts +9 -0
- package/src/server/routers/desktop/pgTable.ts +43 -0
- package/src/services/electron/autoUpdate.ts +17 -0
- package/src/services/electron/file.ts +31 -0
- package/src/services/electron/localFileService.ts +39 -0
- package/src/services/electron/remoteServer.ts +40 -0
- package/src/store/chat/index.ts +1 -1
- package/src/store/chat/slices/builtinTool/actions/index.ts +3 -1
- package/src/store/chat/slices/builtinTool/actions/localFile.ts +129 -0
- package/src/store/chat/slices/builtinTool/initialState.ts +2 -0
- package/src/store/chat/slices/builtinTool/selectors.ts +2 -0
- package/src/store/chat/slices/plugin/action.ts +3 -3
- package/src/store/chat/store.ts +2 -0
- package/src/store/electron/actions/sync.ts +117 -0
- package/src/store/electron/index.ts +1 -0
- package/src/store/electron/initialState.ts +18 -0
- package/src/store/electron/selectors/index.ts +1 -0
- package/src/store/electron/selectors/sync.ts +9 -0
- package/src/store/electron/store.ts +29 -0
- package/src/tools/index.ts +8 -0
- package/src/tools/local-files/Render/ListFiles/Result.tsx +42 -0
- package/src/tools/local-files/Render/ListFiles/index.tsx +68 -0
- package/src/tools/local-files/Render/ReadLocalFile/ReadFileSkeleton.tsx +50 -0
- package/src/tools/local-files/Render/ReadLocalFile/ReadFileView.tsx +197 -0
- package/src/tools/local-files/Render/ReadLocalFile/index.tsx +31 -0
- package/src/tools/local-files/Render/ReadLocalFile/style.ts +37 -0
- package/src/tools/local-files/Render/SearchFiles/Result.tsx +42 -0
- package/src/tools/local-files/Render/SearchFiles/SearchQuery/SearchView.tsx +77 -0
- package/src/tools/local-files/Render/SearchFiles/SearchQuery/index.tsx +72 -0
- package/src/tools/local-files/Render/SearchFiles/index.tsx +32 -0
- package/src/tools/local-files/Render/index.tsx +36 -0
- package/src/tools/local-files/components/FileItem.tsx +117 -0
- package/src/tools/local-files/index.ts +149 -0
- package/src/tools/local-files/systemRole.ts +46 -0
- package/src/tools/local-files/type.ts +33 -0
- package/src/tools/renders.ts +3 -0
- package/packages/electron-client-ipc/src/events/search.ts +0 -4
- package/src/features/Conversation/Messages/Assistant/Tool/Render/Arguments.tsx +0 -165
- /package/packages/electron-client-ipc/src/types/{file.ts → upload.ts} +0 -0
@@ -0,0 +1,149 @@
|
|
1
|
+
import { BuiltinToolManifest } from '@/types/tool';
|
2
|
+
|
3
|
+
import { systemPrompt } from './systemRole';
|
4
|
+
|
5
|
+
export const LocalFilesApiName = {
|
6
|
+
listLocalFiles: 'listLocalFiles',
|
7
|
+
readLocalFile: 'readLocalFile',
|
8
|
+
searchLocalFiles: 'searchLocalFiles',
|
9
|
+
writeFile: 'writeFile',
|
10
|
+
};
|
11
|
+
|
12
|
+
export const LocalFilesManifest: BuiltinToolManifest = {
|
13
|
+
api: [
|
14
|
+
{
|
15
|
+
description:
|
16
|
+
'List files and folders in a specified directory. Input should be a path. Output is a JSON array of file/folder names.',
|
17
|
+
name: LocalFilesApiName.listLocalFiles,
|
18
|
+
parameters: {
|
19
|
+
properties: {
|
20
|
+
path: {
|
21
|
+
description: 'The directory path to list',
|
22
|
+
type: 'string',
|
23
|
+
},
|
24
|
+
},
|
25
|
+
required: ['path'],
|
26
|
+
type: 'object',
|
27
|
+
},
|
28
|
+
},
|
29
|
+
{
|
30
|
+
description:
|
31
|
+
'Read the content of a specific file. Input should be the file path. Output is the file content as a string.',
|
32
|
+
name: LocalFilesApiName.readLocalFile,
|
33
|
+
parameters: {
|
34
|
+
properties: {
|
35
|
+
path: {
|
36
|
+
description: 'The file path to read',
|
37
|
+
type: 'string',
|
38
|
+
},
|
39
|
+
},
|
40
|
+
required: ['path'],
|
41
|
+
type: 'object',
|
42
|
+
},
|
43
|
+
},
|
44
|
+
{
|
45
|
+
description:
|
46
|
+
'Search for files within the workspace based on a query string and optional filter options. Input should include the search query and any filter options. Output is a JSON array of matching file paths.',
|
47
|
+
name: LocalFilesApiName.searchLocalFiles,
|
48
|
+
parameters: {
|
49
|
+
properties: {
|
50
|
+
contentContains: {
|
51
|
+
description: 'The file content must contain this string',
|
52
|
+
type: 'string',
|
53
|
+
},
|
54
|
+
createdAfter: {
|
55
|
+
description:
|
56
|
+
'Files created after this date (ISO 8601 format, e.g., 2023-10-26T10:00:00Z)',
|
57
|
+
format: 'date-time',
|
58
|
+
type: 'string',
|
59
|
+
},
|
60
|
+
createdBefore: {
|
61
|
+
description: 'Files created before this date (ISO 8601 format)',
|
62
|
+
format: 'date-time',
|
63
|
+
type: 'string',
|
64
|
+
},
|
65
|
+
exclude: {
|
66
|
+
description: 'Array of file or directory paths to exclude',
|
67
|
+
items: {
|
68
|
+
type: 'string',
|
69
|
+
},
|
70
|
+
type: 'array',
|
71
|
+
},
|
72
|
+
fileTypes: {
|
73
|
+
description: 'Array of file types to include (e.g., "public.image", "txt")',
|
74
|
+
items: {
|
75
|
+
type: 'string',
|
76
|
+
},
|
77
|
+
type: 'array',
|
78
|
+
},
|
79
|
+
keywords: {
|
80
|
+
description: 'The search keywords string (can include partial names or keywords)',
|
81
|
+
type: 'string',
|
82
|
+
},
|
83
|
+
limit: {
|
84
|
+
description: 'Limit the number of results returned',
|
85
|
+
type: 'number',
|
86
|
+
},
|
87
|
+
liveUpdate: {
|
88
|
+
description: 'Whether to update search results live (if supported)',
|
89
|
+
type: 'boolean',
|
90
|
+
},
|
91
|
+
modifiedAfter: {
|
92
|
+
description: 'Files modified after this date (ISO 8601 format)',
|
93
|
+
format: 'date-time',
|
94
|
+
type: 'string',
|
95
|
+
},
|
96
|
+
modifiedBefore: {
|
97
|
+
description: 'Files modified before this date (ISO 8601 format)',
|
98
|
+
format: 'date-time',
|
99
|
+
type: 'string',
|
100
|
+
},
|
101
|
+
onlyIn: {
|
102
|
+
description: 'Limit the search to this specific directory path',
|
103
|
+
type: 'string',
|
104
|
+
},
|
105
|
+
sortBy: {
|
106
|
+
description: 'Sort results by',
|
107
|
+
enum: ['name', 'date', 'size'],
|
108
|
+
type: 'string',
|
109
|
+
},
|
110
|
+
sortDirection: {
|
111
|
+
description: 'Sort direction',
|
112
|
+
enum: ['asc', 'desc'],
|
113
|
+
type: 'string',
|
114
|
+
},
|
115
|
+
},
|
116
|
+
required: ['keywords'],
|
117
|
+
type: 'object',
|
118
|
+
},
|
119
|
+
},
|
120
|
+
// TODO: Add writeFile API definition later
|
121
|
+
// {
|
122
|
+
// description:
|
123
|
+
// 'Write content to a specific file. Input should be the file path and content. Overwrites existing file or creates a new one.',
|
124
|
+
// name: LocalFilesApiName.writeFile,
|
125
|
+
// parameters: {
|
126
|
+
// properties: {
|
127
|
+
// path: {
|
128
|
+
// description: 'The file path to write to',
|
129
|
+
// type: 'string',
|
130
|
+
// },
|
131
|
+
// content: {
|
132
|
+
// description: 'The content to write',
|
133
|
+
// type: 'string',
|
134
|
+
// },
|
135
|
+
// },
|
136
|
+
// required: ['path', 'content'],
|
137
|
+
// type: 'object',
|
138
|
+
// },
|
139
|
+
// },
|
140
|
+
],
|
141
|
+
identifier: 'lobe-local-files',
|
142
|
+
meta: {
|
143
|
+
avatar: '📁',
|
144
|
+
title: 'Local Files',
|
145
|
+
},
|
146
|
+
// Use a simplified system role for now
|
147
|
+
systemRole: systemPrompt(),
|
148
|
+
type: 'builtin',
|
149
|
+
};
|
@@ -0,0 +1,46 @@
|
|
1
|
+
export const systemPrompt =
|
2
|
+
() => `You have a Local Files tool with capabilities to interact with the user's local file system. You can list directories, read file contents, search for files, and potentially write files.
|
3
|
+
|
4
|
+
<core_capabilities>
|
5
|
+
1. List files and folders in a directory (listFiles)
|
6
|
+
2. Read the content of a specific file (readFile)
|
7
|
+
3. Search for files based on a query and various filter options (searchFiles)
|
8
|
+
4. Write content to a specific file (writeFile) - // TODO: Implement later
|
9
|
+
</core_capabilities>
|
10
|
+
|
11
|
+
<workflow>
|
12
|
+
1. Understand the user's request regarding local files (listing, reading, searching, writing).
|
13
|
+
2. Select the appropriate tool (listFiles, readFile, searchFiles, writeFile).
|
14
|
+
3. Execute the file operation based on the provided path, query, and filter options.
|
15
|
+
4. Present the results (directory listing, file content, search results) or confirmation of the write operation.
|
16
|
+
</workflow>
|
17
|
+
|
18
|
+
<tool_usage_guidelines>
|
19
|
+
- For listing directory contents: Use 'listFiles' with the target directory path.
|
20
|
+
- For reading a file: Use 'readFile' with the exact file path.
|
21
|
+
- For searching files: Use 'searchFiles' with the 'query' parameter (search string). You can optionally add the following filter parameters to narrow down the search:
|
22
|
+
- 'contentContains': Find files whose content includes specific text.
|
23
|
+
- 'createdAfter' / 'createdBefore': Filter by creation date.
|
24
|
+
- 'modifiedAfter' / 'modifiedBefore': Filter by modification date.
|
25
|
+
- 'fileTypes': Filter by file type (e.g., "public.image", "txt").
|
26
|
+
- 'onlyIn': Limit the search to a specific directory.
|
27
|
+
- 'exclude': Exclude specific files or directories.
|
28
|
+
- 'limit': Limit the number of results returned.
|
29
|
+
- 'sortBy' / 'sortDirection': Sort the results.
|
30
|
+
- 'detailed': Get more detailed output information.
|
31
|
+
- For writing to a file: Use 'writeFile' with the file path and the content to be written. Be cautious as this might overwrite existing files.
|
32
|
+
</tool_usage_guidelines>
|
33
|
+
|
34
|
+
<security_considerations>
|
35
|
+
- Always confirm with the user before performing write operations, especially if it involves overwriting existing files.
|
36
|
+
- Do not attempt to access files outside the user's designated workspace or allowed directories unless explicitly permitted.
|
37
|
+
- Handle file paths carefully to avoid unintended access or errors.
|
38
|
+
</security_considerations>
|
39
|
+
|
40
|
+
<response_format>
|
41
|
+
- When listing files, provide a clear list of files and folders.
|
42
|
+
- When reading files, present the content accurately.
|
43
|
+
- When searching files, return a list of matching files, including relevant metadata if detailed information was requested.
|
44
|
+
- When writing files, confirm the success or failure of the operation.
|
45
|
+
</response_format>
|
46
|
+
`;
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import { LocalFileItem, LocalReadFileResult } from '@lobechat/electron-client-ipc';
|
2
|
+
|
3
|
+
export interface FileResult {
|
4
|
+
contentType?: string;
|
5
|
+
createdTime: Date;
|
6
|
+
isDirectory: boolean;
|
7
|
+
lastAccessTime: Date;
|
8
|
+
// Spotlight specific metadata
|
9
|
+
metadata?: {
|
10
|
+
[key: string]: any;
|
11
|
+
};
|
12
|
+
modifiedTime: Date;
|
13
|
+
name: string;
|
14
|
+
path: string;
|
15
|
+
size: number;
|
16
|
+
type: string;
|
17
|
+
}
|
18
|
+
|
19
|
+
export interface LocalFileSearchState {
|
20
|
+
searchResults: LocalFileItem[];
|
21
|
+
}
|
22
|
+
|
23
|
+
export interface LocalFileListState {
|
24
|
+
listResults: LocalFileItem[];
|
25
|
+
}
|
26
|
+
|
27
|
+
export interface LocalReadFileState {
|
28
|
+
fileContent: LocalReadFileResult;
|
29
|
+
}
|
30
|
+
|
31
|
+
export interface LocalReadFilesState {
|
32
|
+
filesContent: LocalReadFileResult[];
|
33
|
+
}
|
package/src/tools/renders.ts
CHANGED
@@ -2,10 +2,13 @@ import { BuiltinRender } from '@/types/tool';
|
|
2
2
|
|
3
3
|
import { DalleManifest } from './dalle';
|
4
4
|
import DalleRender from './dalle/Render';
|
5
|
+
import { LocalFilesManifest } from './local-files';
|
6
|
+
import LocalFilesRender from './local-files/Render';
|
5
7
|
import { WebBrowsingManifest } from './web-browsing';
|
6
8
|
import WebBrowsing from './web-browsing/Render';
|
7
9
|
|
8
10
|
export const BuiltinToolsRenders: Record<string, BuiltinRender> = {
|
9
11
|
[DalleManifest.identifier]: DalleRender as BuiltinRender,
|
10
12
|
[WebBrowsingManifest.identifier]: WebBrowsing as BuiltinRender,
|
13
|
+
[LocalFilesManifest.identifier]: LocalFilesRender as BuiltinRender,
|
11
14
|
};
|
@@ -1,165 +0,0 @@
|
|
1
|
-
import { Highlighter, copyToClipboard } from '@lobehub/ui';
|
2
|
-
import { App } from 'antd';
|
3
|
-
import { createStyles } from 'antd-style';
|
4
|
-
import { parse } from 'partial-json';
|
5
|
-
import { memo, useMemo } from 'react';
|
6
|
-
import { useTranslation } from 'react-i18next';
|
7
|
-
|
8
|
-
import { useIsMobile } from '@/hooks/useIsMobile';
|
9
|
-
import { useYamlArguments } from '@/hooks/useYamlArguments';
|
10
|
-
import { shinyTextStylish } from '@/styles/loading';
|
11
|
-
|
12
|
-
const useStyles = createStyles(({ css, token }) => ({
|
13
|
-
arrayRow: css`
|
14
|
-
&:not(:first-child) {
|
15
|
-
border-block-start: 1px dotted ${token.colorBorderSecondary};
|
16
|
-
}
|
17
|
-
`,
|
18
|
-
colon: css`
|
19
|
-
color: ${token.colorTextTertiary};
|
20
|
-
`,
|
21
|
-
container: css`
|
22
|
-
padding-block: 4px;
|
23
|
-
padding-inline: 12px;
|
24
|
-
border-radius: ${token.borderRadiusLG}px;
|
25
|
-
|
26
|
-
font-family: ${token.fontFamilyCode};
|
27
|
-
font-size: 13px;
|
28
|
-
line-height: 1.5;
|
29
|
-
|
30
|
-
background: ${token.colorFillQuaternary};
|
31
|
-
`,
|
32
|
-
copyable: css`
|
33
|
-
cursor: pointer;
|
34
|
-
width: 100%;
|
35
|
-
margin-block: 2px;
|
36
|
-
padding: 4px;
|
37
|
-
|
38
|
-
&:hover {
|
39
|
-
border-radius: 6px;
|
40
|
-
background: ${token.colorFillTertiary};
|
41
|
-
}
|
42
|
-
`,
|
43
|
-
key: css`
|
44
|
-
color: ${token.colorTextTertiary};
|
45
|
-
`,
|
46
|
-
row: css`
|
47
|
-
display: flex;
|
48
|
-
align-items: baseline;
|
49
|
-
|
50
|
-
&:not(:first-child) {
|
51
|
-
border-block-start: 1px dotted ${token.colorBorderSecondary};
|
52
|
-
}
|
53
|
-
`,
|
54
|
-
shineText: shinyTextStylish(token),
|
55
|
-
value: css`
|
56
|
-
color: ${token.colorTextSecondary};
|
57
|
-
`,
|
58
|
-
}));
|
59
|
-
|
60
|
-
interface ObjectDisplayProps {
|
61
|
-
data: Record<string, any>;
|
62
|
-
shine?: boolean;
|
63
|
-
}
|
64
|
-
|
65
|
-
const ObjectDisplay = memo(({ data, shine }: ObjectDisplayProps) => {
|
66
|
-
const { styles, cx } = useStyles();
|
67
|
-
const { t } = useTranslation('common');
|
68
|
-
|
69
|
-
const { message } = App.useApp();
|
70
|
-
const isMobile = useIsMobile();
|
71
|
-
|
72
|
-
const formatValue = (value: any): string | string[] => {
|
73
|
-
if (Array.isArray(value)) {
|
74
|
-
return value.map((v) => (typeof v === 'object' ? JSON.stringify(v) : v));
|
75
|
-
}
|
76
|
-
|
77
|
-
if (typeof value === 'object' && value !== null) {
|
78
|
-
return Object.entries(value)
|
79
|
-
.map(([k, v]) => `${k}: ${typeof v === 'object' ? JSON.stringify(v) : v}`)
|
80
|
-
.join(', ');
|
81
|
-
}
|
82
|
-
return String(value);
|
83
|
-
};
|
84
|
-
|
85
|
-
const hasMinWidth = Object.keys(data).length > 1;
|
86
|
-
if (Object.keys(data).length === 0) return null;
|
87
|
-
|
88
|
-
return (
|
89
|
-
<div className={styles.container}>
|
90
|
-
{Object.entries(data).map(([key, value]) => {
|
91
|
-
const formatedValue = formatValue(value);
|
92
|
-
return (
|
93
|
-
<div className={styles.row} key={key}>
|
94
|
-
<span
|
95
|
-
className={styles.key}
|
96
|
-
style={{ minWidth: hasMinWidth ? (isMobile ? 60 : 140) : undefined }}
|
97
|
-
>
|
98
|
-
{key}
|
99
|
-
</span>
|
100
|
-
<span className={styles.colon}>:</span>
|
101
|
-
<div className={cx(shine ? styles.shineText : styles.value)} style={{ width: '100%' }}>
|
102
|
-
{typeof formatedValue === 'string' ? (
|
103
|
-
<div
|
104
|
-
className={styles.copyable}
|
105
|
-
onClick={async () => {
|
106
|
-
await copyToClipboard(formatedValue);
|
107
|
-
message.success(t('copySuccess'));
|
108
|
-
}}
|
109
|
-
>
|
110
|
-
{formatedValue}
|
111
|
-
</div>
|
112
|
-
) : (
|
113
|
-
formatedValue.map((v, i) => (
|
114
|
-
<div
|
115
|
-
className={styles.arrayRow}
|
116
|
-
key={i}
|
117
|
-
onClick={async () => {
|
118
|
-
await copyToClipboard(v);
|
119
|
-
message.success(t('copySuccess'));
|
120
|
-
}}
|
121
|
-
>
|
122
|
-
<div className={styles.copyable}>{v}</div>
|
123
|
-
</div>
|
124
|
-
))
|
125
|
-
)}
|
126
|
-
</div>
|
127
|
-
</div>
|
128
|
-
);
|
129
|
-
})}
|
130
|
-
</div>
|
131
|
-
);
|
132
|
-
});
|
133
|
-
|
134
|
-
export interface ArgumentsProps {
|
135
|
-
arguments?: string;
|
136
|
-
shine?: boolean;
|
137
|
-
}
|
138
|
-
|
139
|
-
const Arguments = memo<ArgumentsProps>(({ arguments: args = '', shine }) => {
|
140
|
-
const requestArgs = useMemo(() => {
|
141
|
-
try {
|
142
|
-
const obj = parse(args);
|
143
|
-
|
144
|
-
if (Object.keys(obj).length === 0) return {};
|
145
|
-
|
146
|
-
return obj;
|
147
|
-
} catch {
|
148
|
-
return args;
|
149
|
-
}
|
150
|
-
}, [args]);
|
151
|
-
|
152
|
-
const yaml = useYamlArguments(args);
|
153
|
-
|
154
|
-
return typeof requestArgs === 'string' ? (
|
155
|
-
!!yaml && (
|
156
|
-
<Highlighter language={'yaml'} showLanguage={false}>
|
157
|
-
{yaml}
|
158
|
-
</Highlighter>
|
159
|
-
)
|
160
|
-
) : (
|
161
|
-
<ObjectDisplay data={requestArgs} shine={shine} />
|
162
|
-
);
|
163
|
-
});
|
164
|
-
|
165
|
-
export default Arguments;
|
File without changes
|