Skip to content

Commit d18e20d

Browse files
authored
Feat/2.3.0 beta2 (#1826)
2 parents 3e277da + bc09bbc commit d18e20d

17 files changed

Lines changed: 185 additions & 116 deletions

File tree

src/backend/bisheng/database/models/user_group.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import datetime
22
from typing import List, Optional
33

4-
from sqlalchemy import Column, DateTime, delete, text
4+
from sqlalchemy import Column, DateTime, delete, text, INT
55
from sqlmodel import Field, select
66

77
from bisheng.common.models.base import SQLModelSerializable
@@ -30,7 +30,7 @@ class UserGroupBase(SQLModelSerializable):
3030

3131

3232
class UserGroup(UserGroupBase, table=True):
33-
id: Optional[int] = Field(default=None, primary_key=True)
33+
id: Optional[int] = Field(default=None, sa_column=Column(INT, primary_key=True, autoincrement=True))
3434

3535

3636
class UserGroupRead(UserGroupBase):

src/backend/bisheng/user/domain/models/user_role.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import List, Optional
33

44
from pydantic import BaseModel
5-
from sqlalchemy import Column, DateTime, text, delete
5+
from sqlalchemy import Column, DateTime, text, delete,INT
66
from sqlmodel import Field, select
77

88
from bisheng.common.models.base import SQLModelSerializable
@@ -28,7 +28,7 @@ class UserRoleBase(SQLModelSerializable):
2828

2929

3030
class UserRole(UserRoleBase, table=True):
31-
id: Optional[int] = Field(default=None, primary_key=True)
31+
id: Optional[int] = Field(default=None, sa_column=Column(INT, primary_key=True, autoincrement=True))
3232

3333

3434
class UserRoleRead(UserRoleBase):

src/frontend/client/src/components/Chat/Messages/MessagesView.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,11 @@ export default function MessagesView({
9191
className="flex items-center h-8 justify-center gap-2 rounded-2xl bg-blue-100 px-4 py-1 font-medium text-blue-main hover:bg-blue-200"
9292
disabled={readOnly}
9393
onClick={() => {
94-
newConvo();
95-
navigate('/c/new');
94+
document.getElementById('create-convo-btn')?.click();
95+
// hack
96+
setTimeout(() => {
97+
document.getElementById('create-convo-btn')?.click();
98+
}, 300);
9699
}}
97100
aria-label={localize('com_ui_new_chat')}
98101
>

src/frontend/client/src/components/Conversations/Convo.tsx

Lines changed: 83 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
import { Check, X } from 'lucide-react';
2-
import type { FocusEvent, KeyboardEvent, MouseEvent } from 'react';
3-
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4-
import { useNavigate, useParams } from 'react-router-dom';
5-
import { useRecoilValue } from 'recoil';
6-
import { NotificationSeverity } from '~/common';
7-
import { useGetEndpointsQuery, useUpdateConversationMutation } from '~/data-provider';
8-
import type { TConversation } from '~/data-provider/data-provider/src';
9-
import { Constants } from '~/data-provider/data-provider/src';
10-
import { useLocalize, useMediaQuery, useNavigateToConvo } from '~/hooks';
11-
import { useToastContext } from '~/Providers';
12-
import store from '~/store';
13-
import { cn } from '~/utils';
14-
import { ConvoOptions } from './ConvoOptions';
1+
import { Check, X } from "lucide-react";
2+
import type { FocusEvent, KeyboardEvent, MouseEvent } from "react";
3+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4+
import { useNavigate, useParams } from "react-router-dom";
5+
import { useRecoilValue } from "recoil";
6+
import { NotificationSeverity } from "~/common";
7+
import {
8+
useGetEndpointsQuery,
9+
useUpdateConversationMutation,
10+
} from "~/data-provider";
11+
import type { TConversation } from "~/data-provider/data-provider/src";
12+
import { Constants } from "~/data-provider/data-provider/src";
13+
import { useLocalize, useMediaQuery, useNavigateToConvo } from "~/hooks";
14+
import { useToastContext } from "~/Providers";
15+
import store from "~/store";
16+
import { cn } from "~/utils";
17+
import { ConvoOptions } from "./ConvoOptions";
1518

1619
type KeyEvent = KeyboardEvent<HTMLInputElement>;
1720

@@ -30,8 +33,13 @@ export default function Conversation({
3033
}: ConversationProps) {
3134
const params = useParams();
3235

33-
const currentConvoId = useMemo(() => params.conversationId, [params.conversationId]);
34-
const updateConvoMutation = useUpdateConversationMutation(currentConvoId ?? '');
36+
const currentConvoId = useMemo(
37+
() => params.conversationId,
38+
[params.conversationId]
39+
);
40+
const updateConvoMutation = useUpdateConversationMutation(
41+
currentConvoId ?? ""
42+
);
3543
const activeConvos = useRecoilValue(store.allConversationsSelector);
3644
const { data: endpointsConfig } = useGetEndpointsQuery();
3745
const { navigateWithLastTools } = useNavigateToConvo();
@@ -41,7 +49,7 @@ export default function Conversation({
4149
const [titleInput, setTitleInput] = useState(title);
4250
const [renaming, setRenaming] = useState(false);
4351
const [isPopoverActive, setIsPopoverActive] = useState(false);
44-
const isSmallScreen = useMediaQuery('(max-width: 768px)');
52+
const isSmallScreen = useMediaQuery("(max-width: 768px)");
4553
const localize = useLocalize();
4654
const navigate = useNavigate();
4755

@@ -60,14 +68,14 @@ export default function Conversation({
6068
toggleNav();
6169

6270
// set document title
63-
if (typeof title === 'string' && title.length > 0) {
71+
if (typeof title === "string" && title.length > 0) {
6472
// document.title = title;
6573
}
6674

6775
/* Note: Latest Message should not be reset if existing convo */
6876
navigateWithLastTools(
6977
conversation,
70-
!(conversationId ?? '') || conversationId === Constants.NEW_CONVO,
78+
!(conversationId ?? "") || conversationId === Constants.NEW_CONVO
7179
);
7280
};
7381

@@ -84,43 +92,57 @@ export default function Conversation({
8492
}, [renaming]);
8593

8694
const onRename = useCallback(
87-
(e: MouseEvent<HTMLButtonElement> | FocusEvent<HTMLInputElement> | KeyEvent) => {
95+
(
96+
e: MouseEvent<HTMLButtonElement> | FocusEvent<HTMLInputElement> | KeyEvent
97+
) => {
8898
e.preventDefault();
8999
setRenaming(false);
90100
if (titleInput === title) {
91101
return;
92102
}
93-
if (typeof conversationId !== 'string' || conversationId === '') {
103+
if (typeof conversationId !== "string" || conversationId === "") {
94104
return;
95105
}
96106

97107
updateConvoMutation.mutate(
98-
{ conversationId, title: titleInput ?? '', flowType: conversation.flowType },
108+
{
109+
conversationId,
110+
title: titleInput ?? "",
111+
flowId: conversation.flowId,
112+
flowType: conversation.flowType,
113+
},
99114
{
100115
onError: () => {
101116
setTitleInput(title);
102117
showToast({
103-
message: 'Failed to rename conversation',
118+
message: "Failed to rename conversation",
104119
severity: NotificationSeverity.ERROR,
105120
showIcon: true,
106121
});
107122
},
108-
},
123+
}
109124
);
110125
},
111-
[title, titleInput, conversationId, showToast, conversation, updateConvoMutation],
126+
[
127+
title,
128+
titleInput,
129+
conversationId,
130+
showToast,
131+
conversation,
132+
updateConvoMutation,
133+
]
112134
);
113135

114136
const handleKeyDown = useCallback(
115137
(e: KeyEvent) => {
116-
if (e.key === 'Escape') {
138+
if (e.key === "Escape") {
117139
setTitleInput(title);
118140
setRenaming(false);
119-
} else if (e.key === 'Enter') {
141+
} else if (e.key === "Enter") {
120142
onRename(e);
121143
}
122144
},
123-
[title, onRename],
145+
[title, onRename]
124146
);
125147

126148
const cancelRename = useCallback(
@@ -129,25 +151,25 @@ export default function Conversation({
129151
setTitleInput(title);
130152
setRenaming(false);
131153
},
132-
[title],
154+
[title]
133155
);
134156

135157
const isActiveConvo: boolean = useMemo(
136158
() =>
137159
currentConvoId === conversationId ||
138160
(isLatestConvo &&
139-
currentConvoId === 'new' &&
161+
currentConvoId === "new" &&
140162
activeConvos[0] != null &&
141-
activeConvos[0] !== 'new'),
142-
[currentConvoId, conversationId, isLatestConvo, activeConvos],
163+
activeConvos[0] !== "new"),
164+
[currentConvoId, conversationId, isLatestConvo, activeConvos]
143165
);
144166

145167
return (
146168
<div
147169
className={cn(
148-
'group relative mt-2 flex h-10 w-full items-center rounded-lg hover:bg-[#EBEFF8]',
149-
isActiveConvo ? 'bg-[#EBEFF8]' : '',
150-
isSmallScreen ? 'h-12' : '',
170+
"group relative mt-2 flex h-10 w-full items-center rounded-lg hover:bg-[#EBEFF8]",
171+
isActiveConvo ? "bg-[#EBEFF8]" : "",
172+
isSmallScreen ? "h-12" : ""
151173
)}
152174
>
153175
{renaming ? (
@@ -156,15 +178,19 @@ export default function Conversation({
156178
ref={inputRef}
157179
type="text"
158180
className="w-full rounded bg-transparent p-0.5 text-sm leading-tight focus-visible:outline-none"
159-
value={titleInput ?? ''}
181+
value={titleInput ?? ""}
160182
onChange={(e) => setTitleInput(e.target.value)}
161183
onKeyDown={handleKeyDown}
162-
aria-label={`${localize('com_ui_rename')} ${localize('com_ui_chat')}`}
184+
aria-label={`${localize("com_ui_rename")} ${localize(
185+
"com_ui_chat"
186+
)}`}
163187
/>
164188
<div className="flex gap-1">
165189
<button
166190
onClick={cancelRename}
167-
aria-label={`${localize('com_ui_cancel')} ${localize('com_ui_rename')}`}
191+
aria-label={`${localize("com_ui_cancel")} ${localize(
192+
"com_ui_rename"
193+
)}`}
168194
>
169195
<X
170196
aria-hidden={true}
@@ -173,7 +199,9 @@ export default function Conversation({
173199
</button>
174200
<button
175201
onClick={onRename}
176-
aria-label={`${localize('com_ui_submit')} ${localize('com_ui_rename')}`}
202+
aria-label={`${localize("com_ui_submit")} ${localize(
203+
"com_ui_rename"
204+
)}`}
177205
>
178206
<Check
179207
aria-hidden={true}
@@ -189,10 +217,10 @@ export default function Conversation({
189217
data-testid="convo-item"
190218
onClick={clickHandler}
191219
className={cn(
192-
'flex grow cursor-pointer items-center gap-2 overflow-hidden whitespace-nowrap break-all rounded-lg px-2 py-2',
193-
isActiveConvo ? 'bg-[#EBEFF8]' : '',
220+
"flex grow cursor-pointer items-center gap-2 overflow-hidden whitespace-nowrap break-all rounded-lg px-2 py-2",
221+
isActiveConvo ? "bg-[#EBEFF8]" : ""
194222
)}
195-
title={title ?? ''}
223+
title={title ?? ""}
196224
>
197225
{/* <EndpointIcon
198226
conversation={conversation}
@@ -210,7 +238,16 @@ export default function Conversation({
210238
}}
211239
alt={conversation?.flowType}
212240
>
213-
<img src={__APP_ENV__.BASE_URL + (conversation?.flowType === 20 ? "/assets/linsi.png" : "/assets/talk.png")} className='size-6 inline-block mr-2.5' alt="" />
241+
<img
242+
src={
243+
__APP_ENV__.BASE_URL +
244+
(conversation?.flowType === 20
245+
? "/assets/linsi.png"
246+
: "/assets/talk.png")
247+
}
248+
className="size-6 inline-block mr-2.5"
249+
alt=""
250+
/>
214251
{title}
215252
</div>
216253
{isActiveConvo ? (
@@ -222,10 +259,10 @@ export default function Conversation({
222259
)}
223260
<div
224261
className={cn(
225-
'mr-2',
262+
"mr-2",
226263
isPopoverActive || isActiveConvo
227-
? 'flex'
228-
: 'hidden group-focus-within:flex group-hover:flex',
264+
? "flex"
265+
: "hidden group-focus-within:flex group-hover:flex"
229266
)}
230267
>
231268
{!renaming && (

src/frontend/client/src/components/Nav/NewChat.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ export default function NewChat({
8585
const clickHandler = (event: React.MouseEvent<HTMLAnchorElement>) => {
8686
if (event.button === 0 && !(event.ctrlKey || event.metaKey)) {
8787
event.preventDefault();
88+
newConvo();
89+
navigate('/c/new');
90+
toggleNav();
8891
queryClient.setQueryData<TMessage[]>(
8992
[QueryKeys.messages, conversation?.conversationId ?? Constants.NEW_CONVO],
9093
[],
9194
);
92-
newConvo();
93-
navigate('/c/new');
94-
toggleNav();
9595
}
9696
};
9797

@@ -117,6 +117,7 @@ export default function NewChat({
117117
</Button>
118118
{/* 新建btn */}
119119
<Button
120+
id="create-convo-btn"
120121
variant="outline" className="shadow-sm h-10 rounded-xl px-3 flex-shrink-0"
121122
onClick={clickHandler}
122123
aria-label={localize('com_ui_new_chat')}

src/frontend/client/src/locales/en/translation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,7 @@
10381038
"403": "No permission to perform this action",
10391039
"404": "Resource not found",
10401040
"500": "Server error",
1041+
"503": "System is busy, please wait.",
10411042
"10001": "SFT service not found",
10421043
"10002": "Invalid operation",
10431044
"10003": "Resource download failed",
@@ -1110,7 +1111,7 @@
11101111
"10532": "Workflow version upgraded. Contact owner to re-edit",
11111112
"10540": "Server thread limit reached. Please try again later",
11121113
"10541": "Workflow execution failed: {{exception}}",
1113-
"10599": "No write permission",
1114+
"10599": "No permission to view",
11141115
"10600": "Incorrect username or password",
11151116
"10601": "Password expired. Please update it",
11161117
"10602": "Password not set. Contact admin to reset",

src/frontend/client/src/locales/ja/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,7 @@
958958
"403": "操作権限がありません",
959959
"404": "リソースが見つかりません",
960960
"500": "サーバーエラー",
961+
"503": "ただいまシステムが混み合っております。少々お待ちください。",
961962
"10001": "SFTサービスが見つかりません",
962963
"10002": "無効な操作です",
963964
"10003": "リソースのダウンロードに失敗しました",

src/frontend/client/src/locales/zh-Hans/translation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,7 @@
958958
"403": "暂无操作权限",
959959
"404": "资源不存在",
960960
"500": "服务器错误",
961+
"503": "系统正忙,请稍候",
961962
"10001": "未找到SFT服务",
962963
"10002": "无效操作",
963964
"10003": "资源下载失败",
@@ -1030,7 +1031,7 @@
10301031
"10532": "工作流版本已升级,请联系创建者重新编排",
10311032
"10540": "服务器线程数已满,请稍候再试",
10321033
"10541": "工作流任务执行失败:{{exception}}",
1033-
"10599": "没有应用写权限",
1034+
"10599": "暂无查看权限",
10341035
"10600": "账号或密码错误",
10351036
"10601": "您的密码已过期,请及时修改",
10361037
"10602": "用户尚未设置密码,请先联系管理员重置密码",

0 commit comments

Comments
 (0)