plugin-git-manager 1.2.26 → 1.2.28

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.
Files changed (108) hide show
  1. package/README.md +133 -108
  2. package/client-v2.d.ts +2 -2
  3. package/client-v2.js +1 -1
  4. package/client.d.ts +3 -3
  5. package/client.js +1 -1
  6. package/dist/client/{326.90c276058682b536.js → 313.d38fc1d40c4589b9.js} +1 -1
  7. package/dist/client/900.a48beac7e2ebee7d.js +10 -0
  8. package/dist/client/index.js +1 -1
  9. package/dist/client-v2/156.445366026c1cc9a8.js +10 -0
  10. package/dist/client-v2/{326.42b7b53651ffab3a.js → 313.3c867179c3a1e817.js} +1 -1
  11. package/dist/client-v2/434.19c7579c06b9077c.js +10 -0
  12. package/dist/client-v2/900.e6155002a9c97e7f.js +10 -0
  13. package/dist/client-v2/928.bba701b5a1ece58e.js +10 -0
  14. package/dist/client-v2/index.js +1 -1
  15. package/dist/externalVersion.js +9 -8
  16. package/dist/locale/en-US.json +307 -297
  17. package/dist/locale/vi-VN.json +295 -292
  18. package/dist/locale/zh-CN.json +61 -51
  19. package/dist/node_modules/simple-git/dist/cjs/index.js +25 -25
  20. package/dist/node_modules/simple-git/package.json +1 -1
  21. package/dist/node_modules/zod/index.cjs +1 -1
  22. package/dist/node_modules/zod/package.json +1 -1
  23. package/dist/server/actions/git-actions.js +90 -36
  24. package/dist/server/actions/gitlab-api.js +4 -2
  25. package/dist/server/actions/poller.js +5 -2
  26. package/dist/server/actions/review.js +20 -10
  27. package/dist/server/plugin.js +6 -4
  28. package/dist/server/poller.js +46 -45
  29. package/dist/server/request-method-policy.js +75 -0
  30. package/dist/server/services/registry-content-service.js +23 -10
  31. package/dist/server/utils/get-repo-account.js +3 -2
  32. package/dist/server/utils/url-security.js +24 -0
  33. package/package.json +61 -43
  34. package/server.d.ts +2 -2
  35. package/server.js +1 -1
  36. package/src/client/__tests__/RunReviewButton.test.tsx +73 -0
  37. package/src/client/ai-context.tsx +114 -114
  38. package/src/client/components/AIEmployeeSelect.tsx +63 -63
  39. package/src/client/components/CommitHistory.tsx +374 -374
  40. package/src/client/components/FileExplorer.tsx +386 -386
  41. package/src/client/components/GitAccounts.tsx +179 -179
  42. package/src/client/components/GitManagerSettings.tsx +160 -160
  43. package/src/client/components/GitOperations.tsx +220 -220
  44. package/src/client/components/LLMModelSelect.tsx +63 -63
  45. package/src/client/components/LLMServiceSelect.tsx +58 -58
  46. package/src/client/components/MarkdownView.tsx +80 -80
  47. package/src/client/components/MergeRequests.tsx +790 -790
  48. package/src/client/components/PollingStatus.tsx +225 -225
  49. package/src/client/components/RepositoryConfig.tsx +335 -335
  50. package/src/client/components/RepositoryPermissions.tsx +123 -123
  51. package/src/client/components/ReviewFlows.tsx +303 -303
  52. package/src/client/components/ReviewHistory.tsx +566 -566
  53. package/src/client/components/RunReviewButton.tsx +63 -55
  54. package/src/client/context/GitManagerContext.tsx +92 -92
  55. package/src/client/index.tsx +91 -82
  56. package/src/client/locale.ts +9 -9
  57. package/src/client/promptTemplates.ts +31 -31
  58. package/src/client-v2/ai-context.tsx +99 -0
  59. package/src/client-v2/components/SubtreeSplits.tsx +547 -547
  60. package/src/client-v2/index.tsx +1 -1
  61. package/src/client-v2/locale.ts +8 -8
  62. package/src/client-v2/plugin.tsx +67 -39
  63. package/src/index.ts +2 -2
  64. package/src/locale/en-US.json +307 -297
  65. package/src/locale/vi-VN.json +295 -292
  66. package/src/locale/zh-CN.json +61 -51
  67. package/src/server/__tests__/git-actions.test.ts +24 -24
  68. package/src/server/__tests__/git-security.test.ts +170 -0
  69. package/src/server/__tests__/plugin-url-security.test.ts +17 -17
  70. package/src/server/__tests__/poller-lifecycle.test.ts +71 -0
  71. package/src/server/__tests__/poller.test.ts +37 -37
  72. package/src/server/__tests__/repository-access.test.ts +752 -752
  73. package/src/server/__tests__/review.test.ts +137 -137
  74. package/src/server/__tests__/role-permissions.test.ts +147 -147
  75. package/src/server/__tests__/smoke.test.ts +139 -17
  76. package/src/server/__tests__/subtree.test.ts +85 -85
  77. package/src/server/actions/git-actions.ts +540 -480
  78. package/src/server/actions/gitlab-api.ts +422 -411
  79. package/src/server/actions/poller.ts +39 -27
  80. package/src/server/actions/review.ts +1388 -1369
  81. package/src/server/actions/role-permissions.ts +321 -321
  82. package/src/server/actions/subtree.ts +508 -508
  83. package/src/server/ai-tools.ts +319 -319
  84. package/src/server/collections/gitAccounts.ts +56 -56
  85. package/src/server/collections/gitCodeReviews.ts +199 -199
  86. package/src/server/collections/gitRepositories.ts +87 -87
  87. package/src/server/collections/gitReviewFlows.ts +108 -108
  88. package/src/server/collections/gitSubtreeConfigs.ts +38 -38
  89. package/src/server/collections/gitSubtreeRuns.ts +30 -30
  90. package/src/server/index.ts +2 -2
  91. package/src/server/migrations/20260508000000-add-auto-review-flow-id.ts +29 -29
  92. package/src/server/migrations/20260712000000-add-git-accounts.ts +198 -198
  93. package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +81 -81
  94. package/src/server/plugin.ts +372 -361
  95. package/src/server/poller.ts +351 -352
  96. package/src/server/repository-access.ts +773 -773
  97. package/src/server/request-method-policy.ts +55 -0
  98. package/src/server/services/__tests__/registry-content-service.test.ts +359 -345
  99. package/src/server/services/registry-content-service.ts +33 -11
  100. package/src/server/utils/__tests__/redact.test.ts +56 -56
  101. package/src/server/utils/__tests__/url-security.test.ts +85 -85
  102. package/src/server/utils/get-repo-account.ts +51 -41
  103. package/src/server/utils/gitlab-url.ts +38 -38
  104. package/src/server/utils/redact.ts +87 -87
  105. package/src/server/utils/url-security.ts +128 -95
  106. package/dist/client/900.acf7d1fa22f95e71.js +0 -10
  107. package/dist/client-v2/434.7a27051db18526c0.js +0 -10
  108. package/dist/client-v2/900.f32b9dc85249fc0a.js +0 -10
@@ -1,220 +1,220 @@
1
- import React, { useState, useCallback, useEffect } from 'react';
2
- import { Button, Space, Card, Typography, Tag, Empty, message, Spin, Descriptions, List, Badge, theme } from 'antd';
3
- import {
4
- CloudDownloadOutlined,
5
- SyncOutlined,
6
- BranchesOutlined,
7
- CheckCircleOutlined,
8
- WarningOutlined,
9
- FileAddOutlined,
10
- EditOutlined,
11
- DeleteOutlined,
12
- QuestionCircleOutlined,
13
- } from '@ant-design/icons';
14
- import { useApp } from '@nocobase/client-v2';
15
- import { useGitManager } from '../context/GitManagerContext';
16
- import { useT } from '../locale';
17
-
18
- const { Text } = Typography;
19
- const { useToken } = theme;
20
-
21
- const FILE_STATUS_MAP: Record<string, { color: string; icon: React.ReactNode; label: string }> = {
22
- not_added: { color: 'green', icon: <FileAddOutlined />, label: 'New' },
23
- modified: { color: 'blue', icon: <EditOutlined />, label: 'Modified' },
24
- deleted: { color: 'red', icon: <DeleteOutlined />, label: 'Deleted' },
25
- renamed: { color: 'orange', icon: <EditOutlined />, label: 'Renamed' },
26
- conflicted: { color: 'red', icon: <WarningOutlined />, label: 'Conflict' },
27
- created: { color: 'green', icon: <FileAddOutlined />, label: 'Created' },
28
- };
29
-
30
- export const GitOperations: React.FC = () => {
31
- const t = useT();
32
- const { token } = useToken();
33
- const api = useApp().apiClient;
34
- const { selectedRepo, refreshRepos } = useGitManager();
35
- const [actionLoading, setActionLoading] = useState<string | null>(null);
36
- const [statusData, setStatusData] = useState<any>(null);
37
- const [lastResult, setLastResult] = useState<{ action: string; success: boolean; message: string } | null>(null);
38
-
39
- const loadStatus = useCallback(async () => {
40
- if (!selectedRepo || selectedRepo.status !== 'connected') {
41
- setStatusData(null);
42
- return;
43
- }
44
- setActionLoading('status');
45
- try {
46
- const { data } = await api.request({
47
- url: 'gitManager:status',
48
- method: 'post',
49
- params: { repositoryId: selectedRepo.id },
50
- });
51
- const responseData = data?.data?.data || data?.data;
52
- setStatusData(responseData);
53
- } catch (error) {
54
- console.warn('Failed to load git status:', error);
55
- setStatusData(null);
56
- } finally {
57
- setActionLoading(null);
58
- }
59
- }, [api, selectedRepo]);
60
-
61
- useEffect(() => {
62
- loadStatus();
63
- }, [loadStatus]);
64
-
65
- const execAction = useCallback(
66
- async (action: string) => {
67
- if (!selectedRepo) return;
68
- setActionLoading(action);
69
- setLastResult(null);
70
- try {
71
- const { data } = await api.request({
72
- url: `gitManager:${action}`,
73
- method: 'post',
74
- params: { repositoryId: selectedRepo.id },
75
- });
76
- setLastResult({ action, success: true, message: t('{{action}} completed successfully', { action }) });
77
- message.success(t('{{action}} completed', { action }));
78
- const responseData = data?.data?.data || data?.data;
79
- if (action === 'status') setStatusData(responseData);
80
- if (action === 'fetch' || action === 'pull') await loadStatus();
81
- await refreshRepos();
82
- } catch (err: any) {
83
- const msg = err?.response?.data?.errors?.[0]?.message || t('{{action}} failed', { action });
84
- setLastResult({ action, success: false, message: msg });
85
- message.error(msg);
86
- } finally {
87
- setActionLoading(null);
88
- }
89
- },
90
- [api, selectedRepo, refreshRepos, loadStatus],
91
- );
92
-
93
- if (!selectedRepo) {
94
- return <Empty description={t('No repository selected')} />;
95
- }
96
- if (selectedRepo.status !== 'connected') {
97
- return <Empty description={t('Repository not cloned yet')} />;
98
- }
99
-
100
- const allChangedFiles = statusData
101
- ? [
102
- ...(statusData.not_added?.map((f: string) => ({ file: f, status: 'not_added' })) || []),
103
- ...(statusData.modified?.map((f: string) => ({ file: f, status: 'modified' })) || []),
104
- ...(statusData.deleted?.map((f: string) => ({ file: f, status: 'deleted' })) || []),
105
- ...(statusData.renamed?.map((f: any) => ({ file: typeof f === 'string' ? f : f.to, status: 'renamed' })) || []),
106
- ...(statusData.conflicted?.map((f: string) => ({ file: f, status: 'conflicted' })) || []),
107
- ...(statusData.created?.map((f: string) => ({ file: f, status: 'created' })) || []),
108
- ]
109
- : [];
110
-
111
- return (
112
- <div>
113
- <Space size="middle" wrap style={{ marginBottom: 24 }}>
114
- <Button
115
- size="large"
116
- icon={<SyncOutlined />}
117
- loading={actionLoading === 'fetch'}
118
- onClick={() => execAction('fetch')}
119
- >
120
- {t('Fetch')}
121
- </Button>
122
- <Button
123
- size="large"
124
- type="primary"
125
- icon={<CloudDownloadOutlined />}
126
- loading={actionLoading === 'pull'}
127
- onClick={() => execAction('pull')}
128
- >
129
- {t('Pull')}
130
- </Button>
131
- <Button size="large" icon={<BranchesOutlined />} loading={actionLoading === 'status'} onClick={loadStatus}>
132
- {t('Status')}
133
- </Button>
134
- </Space>
135
-
136
- {lastResult && (
137
- <Card
138
- size="small"
139
- style={{
140
- marginBottom: 16,
141
- borderColor: lastResult.success ? token.colorSuccessBorder : token.colorErrorBorder,
142
- }}
143
- >
144
- <Space>
145
- {lastResult.success ? (
146
- <CheckCircleOutlined style={{ color: token.colorSuccess }} />
147
- ) : (
148
- <WarningOutlined style={{ color: token.colorError }} />
149
- )}
150
- <Text strong>{lastResult.action}</Text>
151
- <Text>{lastResult.message}</Text>
152
- </Space>
153
- </Card>
154
- )}
155
-
156
- {statusData && (
157
- <Card title={t('Working Directory Status')} size="small">
158
- <Descriptions column={3} size="small" style={{ marginBottom: 16 }}>
159
- <Descriptions.Item label="Branch">
160
- <Tag icon={<BranchesOutlined />} color="blue">
161
- {statusData.current}
162
- </Tag>
163
- </Descriptions.Item>
164
- <Descriptions.Item label="Tracking">
165
- <Text>{statusData.tracking || 'N/A'}</Text>
166
- </Descriptions.Item>
167
- <Descriptions.Item label="Changes">
168
- <Space>
169
- {statusData.ahead > 0 && (
170
- <Badge count={`${statusData.ahead} ahead`} style={{ backgroundColor: token.colorPrimary }} />
171
- )}
172
- {statusData.behind > 0 && (
173
- <Badge count={`${statusData.behind} behind`} style={{ backgroundColor: token.colorWarning }} />
174
- )}
175
- {statusData.ahead === 0 && statusData.behind === 0 && (
176
- <Tag color="green" icon={<CheckCircleOutlined />}>
177
- Up to date
178
- </Tag>
179
- )}
180
- </Space>
181
- </Descriptions.Item>
182
- </Descriptions>
183
-
184
- {allChangedFiles.length > 0 ? (
185
- <>
186
- <Text strong style={{ display: 'block', marginBottom: 8 }}>
187
- {allChangedFiles.length} changed file(s)
188
- </Text>
189
- <List
190
- size="small"
191
- dataSource={allChangedFiles}
192
- renderItem={(item: any) => {
193
- const info = FILE_STATUS_MAP[item.status] || {
194
- color: 'default',
195
- icon: <QuestionCircleOutlined />,
196
- label: item.status,
197
- };
198
- return (
199
- <List.Item style={{ padding: '4px 0' }}>
200
- <Space>
201
- <Tag color={info.color} style={{ minWidth: 80, textAlign: 'center' }}>
202
- {info.icon} {info.label}
203
- </Tag>
204
- <Text code style={{ fontSize: 13 }}>
205
- {item.file}
206
- </Text>
207
- </Space>
208
- </List.Item>
209
- );
210
- }}
211
- />
212
- </>
213
- ) : (
214
- <Text type="secondary">Working directory clean</Text>
215
- )}
216
- </Card>
217
- )}
218
- </div>
219
- );
220
- };
1
+ import React, { useState, useCallback, useEffect } from 'react';
2
+ import { Button, Space, Card, Typography, Tag, Empty, message, Spin, Descriptions, List, Badge, theme } from 'antd';
3
+ import {
4
+ CloudDownloadOutlined,
5
+ SyncOutlined,
6
+ BranchesOutlined,
7
+ CheckCircleOutlined,
8
+ WarningOutlined,
9
+ FileAddOutlined,
10
+ EditOutlined,
11
+ DeleteOutlined,
12
+ QuestionCircleOutlined,
13
+ } from '@ant-design/icons';
14
+ import { useApp } from '@nocobase/client-v2';
15
+ import { useGitManager } from '../context/GitManagerContext';
16
+ import { useT } from '../locale';
17
+
18
+ const { Text } = Typography;
19
+ const { useToken } = theme;
20
+
21
+ const FILE_STATUS_MAP: Record<string, { color: string; icon: React.ReactNode; label: string }> = {
22
+ not_added: { color: 'green', icon: <FileAddOutlined />, label: 'New' },
23
+ modified: { color: 'blue', icon: <EditOutlined />, label: 'Modified' },
24
+ deleted: { color: 'red', icon: <DeleteOutlined />, label: 'Deleted' },
25
+ renamed: { color: 'orange', icon: <EditOutlined />, label: 'Renamed' },
26
+ conflicted: { color: 'red', icon: <WarningOutlined />, label: 'Conflict' },
27
+ created: { color: 'green', icon: <FileAddOutlined />, label: 'Created' },
28
+ };
29
+
30
+ export const GitOperations: React.FC = () => {
31
+ const t = useT();
32
+ const { token } = useToken();
33
+ const api = useApp().apiClient;
34
+ const { selectedRepo, refreshRepos } = useGitManager();
35
+ const [actionLoading, setActionLoading] = useState<string | null>(null);
36
+ const [statusData, setStatusData] = useState<any>(null);
37
+ const [lastResult, setLastResult] = useState<{ action: string; success: boolean; message: string } | null>(null);
38
+
39
+ const loadStatus = useCallback(async () => {
40
+ if (!selectedRepo || selectedRepo.status !== 'connected') {
41
+ setStatusData(null);
42
+ return;
43
+ }
44
+ setActionLoading('status');
45
+ try {
46
+ const { data } = await api.request({
47
+ url: 'gitManager:status',
48
+ method: 'post',
49
+ params: { repositoryId: selectedRepo.id },
50
+ });
51
+ const responseData = data?.data?.data || data?.data;
52
+ setStatusData(responseData);
53
+ } catch (error) {
54
+ console.warn('Failed to load git status:', error);
55
+ setStatusData(null);
56
+ } finally {
57
+ setActionLoading(null);
58
+ }
59
+ }, [api, selectedRepo]);
60
+
61
+ useEffect(() => {
62
+ loadStatus();
63
+ }, [loadStatus]);
64
+
65
+ const execAction = useCallback(
66
+ async (action: string) => {
67
+ if (!selectedRepo) return;
68
+ setActionLoading(action);
69
+ setLastResult(null);
70
+ try {
71
+ const { data } = await api.request({
72
+ url: `gitManager:${action}`,
73
+ method: 'post',
74
+ params: { repositoryId: selectedRepo.id },
75
+ });
76
+ setLastResult({ action, success: true, message: t('{{action}} completed successfully', { action }) });
77
+ message.success(t('{{action}} completed', { action }));
78
+ const responseData = data?.data?.data || data?.data;
79
+ if (action === 'status') setStatusData(responseData);
80
+ if (action === 'fetch' || action === 'pull') await loadStatus();
81
+ await refreshRepos();
82
+ } catch (err: any) {
83
+ const msg = err?.response?.data?.errors?.[0]?.message || t('{{action}} failed', { action });
84
+ setLastResult({ action, success: false, message: msg });
85
+ message.error(msg);
86
+ } finally {
87
+ setActionLoading(null);
88
+ }
89
+ },
90
+ [api, selectedRepo, refreshRepos, loadStatus],
91
+ );
92
+
93
+ if (!selectedRepo) {
94
+ return <Empty description={t('No repository selected')} />;
95
+ }
96
+ if (selectedRepo.status !== 'connected') {
97
+ return <Empty description={t('Repository not cloned yet')} />;
98
+ }
99
+
100
+ const allChangedFiles = statusData
101
+ ? [
102
+ ...(statusData.not_added?.map((f: string) => ({ file: f, status: 'not_added' })) || []),
103
+ ...(statusData.modified?.map((f: string) => ({ file: f, status: 'modified' })) || []),
104
+ ...(statusData.deleted?.map((f: string) => ({ file: f, status: 'deleted' })) || []),
105
+ ...(statusData.renamed?.map((f: any) => ({ file: typeof f === 'string' ? f : f.to, status: 'renamed' })) || []),
106
+ ...(statusData.conflicted?.map((f: string) => ({ file: f, status: 'conflicted' })) || []),
107
+ ...(statusData.created?.map((f: string) => ({ file: f, status: 'created' })) || []),
108
+ ]
109
+ : [];
110
+
111
+ return (
112
+ <div>
113
+ <Space size="middle" wrap style={{ marginBottom: 24 }}>
114
+ <Button
115
+ size="large"
116
+ icon={<SyncOutlined />}
117
+ loading={actionLoading === 'fetch'}
118
+ onClick={() => execAction('fetch')}
119
+ >
120
+ {t('Fetch')}
121
+ </Button>
122
+ <Button
123
+ size="large"
124
+ type="primary"
125
+ icon={<CloudDownloadOutlined />}
126
+ loading={actionLoading === 'pull'}
127
+ onClick={() => execAction('pull')}
128
+ >
129
+ {t('Pull')}
130
+ </Button>
131
+ <Button size="large" icon={<BranchesOutlined />} loading={actionLoading === 'status'} onClick={loadStatus}>
132
+ {t('Status')}
133
+ </Button>
134
+ </Space>
135
+
136
+ {lastResult && (
137
+ <Card
138
+ size="small"
139
+ style={{
140
+ marginBottom: 16,
141
+ borderColor: lastResult.success ? token.colorSuccessBorder : token.colorErrorBorder,
142
+ }}
143
+ >
144
+ <Space>
145
+ {lastResult.success ? (
146
+ <CheckCircleOutlined style={{ color: token.colorSuccess }} />
147
+ ) : (
148
+ <WarningOutlined style={{ color: token.colorError }} />
149
+ )}
150
+ <Text strong>{lastResult.action}</Text>
151
+ <Text>{lastResult.message}</Text>
152
+ </Space>
153
+ </Card>
154
+ )}
155
+
156
+ {statusData && (
157
+ <Card title={t('Working Directory Status')} size="small">
158
+ <Descriptions column={3} size="small" style={{ marginBottom: 16 }}>
159
+ <Descriptions.Item label="Branch">
160
+ <Tag icon={<BranchesOutlined />} color="blue">
161
+ {statusData.current}
162
+ </Tag>
163
+ </Descriptions.Item>
164
+ <Descriptions.Item label="Tracking">
165
+ <Text>{statusData.tracking || 'N/A'}</Text>
166
+ </Descriptions.Item>
167
+ <Descriptions.Item label="Changes">
168
+ <Space>
169
+ {statusData.ahead > 0 && (
170
+ <Badge count={`${statusData.ahead} ahead`} style={{ backgroundColor: token.colorPrimary }} />
171
+ )}
172
+ {statusData.behind > 0 && (
173
+ <Badge count={`${statusData.behind} behind`} style={{ backgroundColor: token.colorWarning }} />
174
+ )}
175
+ {statusData.ahead === 0 && statusData.behind === 0 && (
176
+ <Tag color="green" icon={<CheckCircleOutlined />}>
177
+ Up to date
178
+ </Tag>
179
+ )}
180
+ </Space>
181
+ </Descriptions.Item>
182
+ </Descriptions>
183
+
184
+ {allChangedFiles.length > 0 ? (
185
+ <>
186
+ <Text strong style={{ display: 'block', marginBottom: 8 }}>
187
+ {allChangedFiles.length} changed file(s)
188
+ </Text>
189
+ <List
190
+ size="small"
191
+ dataSource={allChangedFiles}
192
+ renderItem={(item: any) => {
193
+ const info = FILE_STATUS_MAP[item.status] || {
194
+ color: 'default',
195
+ icon: <QuestionCircleOutlined />,
196
+ label: item.status,
197
+ };
198
+ return (
199
+ <List.Item style={{ padding: '4px 0' }}>
200
+ <Space>
201
+ <Tag color={info.color} style={{ minWidth: 80, textAlign: 'center' }}>
202
+ {info.icon} {info.label}
203
+ </Tag>
204
+ <Text code style={{ fontSize: 13 }}>
205
+ {item.file}
206
+ </Text>
207
+ </Space>
208
+ </List.Item>
209
+ );
210
+ }}
211
+ />
212
+ </>
213
+ ) : (
214
+ <Text type="secondary">Working directory clean</Text>
215
+ )}
216
+ </Card>
217
+ )}
218
+ </div>
219
+ );
220
+ };
@@ -1,63 +1,63 @@
1
- import React, { useEffect, useState } from 'react';
2
- import { Select } from 'antd';
3
- import { useApp } from '@nocobase/client-v2';
4
-
5
- export const LLMModelSelect: React.FC<{
6
- llmService?: string;
7
- value?: string;
8
- onChange?: (value: string) => void;
9
- allowClear?: boolean;
10
- size?: 'small' | 'middle' | 'large';
11
- style?: React.CSSProperties;
12
- placeholder?: string;
13
- }> = ({ llmService, value, onChange, allowClear = true, size, style, placeholder }) => {
14
- const api = useApp().apiClient;
15
- const [models, setModels] = useState<{ id: string }[]>([]);
16
- const [loading, setLoading] = useState(false);
17
-
18
- useEffect(() => {
19
- let cancelled = false;
20
- if (!llmService) {
21
- setModels([]);
22
- return;
23
- }
24
-
25
- setLoading(true);
26
- api
27
- .request({ url: 'ai:listModels', params: { llmService } })
28
- .then((res) => {
29
- if (cancelled) return;
30
- const list = res?.data?.data || [];
31
- setModels(Array.isArray(list) ? list : []);
32
- })
33
- .catch(() => {
34
- if (!cancelled) setModels([]);
35
- })
36
- .finally(() => {
37
- if (!cancelled) setLoading(false);
38
- });
39
-
40
- return () => {
41
- cancelled = true;
42
- };
43
- }, [api, llmService]);
44
-
45
- return (
46
- <Select
47
- value={value}
48
- onChange={onChange}
49
- allowClear={allowClear}
50
- loading={loading}
51
- size={size}
52
- style={style}
53
- placeholder={placeholder || 'Select LLM Model'}
54
- options={models.map((m) => ({
55
- value: m.id,
56
- label: m.id,
57
- }))}
58
- showSearch
59
- optionFilterProp="label"
60
- disabled={!llmService}
61
- />
62
- );
63
- };
1
+ import React, { useEffect, useState } from 'react';
2
+ import { Select } from 'antd';
3
+ import { useApp } from '@nocobase/client-v2';
4
+
5
+ export const LLMModelSelect: React.FC<{
6
+ llmService?: string;
7
+ value?: string;
8
+ onChange?: (value: string) => void;
9
+ allowClear?: boolean;
10
+ size?: 'small' | 'middle' | 'large';
11
+ style?: React.CSSProperties;
12
+ placeholder?: string;
13
+ }> = ({ llmService, value, onChange, allowClear = true, size, style, placeholder }) => {
14
+ const api = useApp().apiClient;
15
+ const [models, setModels] = useState<{ id: string }[]>([]);
16
+ const [loading, setLoading] = useState(false);
17
+
18
+ useEffect(() => {
19
+ let cancelled = false;
20
+ if (!llmService) {
21
+ setModels([]);
22
+ return;
23
+ }
24
+
25
+ setLoading(true);
26
+ api
27
+ .request({ url: 'ai:listModels', params: { llmService } })
28
+ .then((res) => {
29
+ if (cancelled) return;
30
+ const list = res?.data?.data || [];
31
+ setModels(Array.isArray(list) ? list : []);
32
+ })
33
+ .catch(() => {
34
+ if (!cancelled) setModels([]);
35
+ })
36
+ .finally(() => {
37
+ if (!cancelled) setLoading(false);
38
+ });
39
+
40
+ return () => {
41
+ cancelled = true;
42
+ };
43
+ }, [api, llmService]);
44
+
45
+ return (
46
+ <Select
47
+ value={value}
48
+ onChange={onChange}
49
+ allowClear={allowClear}
50
+ loading={loading}
51
+ size={size}
52
+ style={style}
53
+ placeholder={placeholder || 'Select LLM Model'}
54
+ options={models.map((m) => ({
55
+ value: m.id,
56
+ label: m.id,
57
+ }))}
58
+ showSearch
59
+ optionFilterProp="label"
60
+ disabled={!llmService}
61
+ />
62
+ );
63
+ };