Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
bit-pm
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
燕伟桐
bit-pm
Commits
a4702f90
提交
a4702f90
authored
4月 18, 2025
作者:
Will Chen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean up proposal logic
上级
639b3a32
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
72 行增加
和
59 行删除
+72
-59
ChatInput.tsx
src/components/chat/ChatInput.tsx
+18
-14
HomeChatInput.tsx
src/components/chat/HomeChatInput.tsx
+3
-1
useProposal.ts
src/hooks/useProposal.ts
+30
-26
useStreamChat.ts
src/hooks/useStreamChat.ts
+12
-4
proposal_handlers.ts
src/ipc/handlers/proposal_handlers.ts
+1
-12
schemas.ts
src/lib/schemas.ts
+7
-1
home.tsx
src/pages/home.tsx
+1
-1
没有找到文件。
src/components/chat/ChatInput.tsx
浏览文件 @
a4702f90
...
...
@@ -274,10 +274,11 @@ function mapActionToButton(action: SuggestedAction) {
<
Button
variant=
"outline"
size=
"sm"
className=
"rounded-xl"
key=
{
action
.
id
}
onClick=
{
restartApp
}
>
Restart
A
pp
Restart
a
pp
</
Button
>
);
default
:
...
...
@@ -292,8 +293,21 @@ function mapActionToButton(action: SuggestedAction) {
function
ActionProposalActions
({
proposal
}:
{
proposal
:
ActionProposal
})
{
return
(
<
div
className=
"p-2 pb-0"
>
{
proposal
.
actions
.
map
((
action
)
=>
mapActionToButton
(
action
))
}
<
div
className=
"border-b border-border p-2 flex items-center justify-between"
>
<
div
className=
"flex items-center space-x-2"
>
{
proposal
.
actions
.
map
((
action
)
=>
mapActionToButton
(
action
))
}
</
div
>
<
AutoApproveSwitch
/>
</
div
>
);
}
function
AutoApproveSwitch
()
{
// const [autoApprove, setAutoApprove] = useAtom(autoApproveAtom);
return
(
<
div
className=
"flex items-center space-x-2"
>
<
Switch
id=
"auto-approve"
/>
<
Label
htmlFor=
"auto-approve"
>
Auto-approve
</
Label
>
</
div
>
);
}
...
...
@@ -376,17 +390,7 @@ function ChatInputActions({
Reject
</
Button
>
<
div
className=
"flex items-center space-x-1 ml-auto"
>
{
/* Basic HTML checkbox styled to look like a toggle */
}
<
input
type=
"checkbox"
id=
"auto-approve"
checked=
{
autoApprove
}
onChange=
{
(
e
)
=>
setAutoApprove
(
e
.
target
.
checked
)
}
className=
"relative peer shrink-0 appearance-none w-8 h-4 border border-input rounded-full bg-input checked:bg-primary cursor-pointer after:absolute after:w-3 after:h-3 after:top-[1px] after:left-[2px] after:bg-background after:rounded-full after:transition-all checked:after:translate-x-4 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50"
/>
<
label
htmlFor=
"auto-approve"
className=
"text-xs cursor-pointer"
>
Auto-approve
</
label
>
<
AutoApproveSwitch
/>
</
div
>
</
div
>
</
div
>
...
...
src/components/chat/HomeChatInput.tsx
浏览文件 @
a4702f90
...
...
@@ -11,7 +11,9 @@ export function HomeChatInput({ onSubmit }: { onSubmit: () => void }) {
const
[
inputValue
,
setInputValue
]
=
useAtom
(
homeChatInputValueAtom
);
const
textareaRef
=
useRef
<
HTMLTextAreaElement
>
(
null
);
const
{
settings
,
updateSettings
,
isAnyProviderSetup
}
=
useSettings
();
const
{
streamMessage
,
isStreaming
,
setIsStreaming
}
=
useStreamChat
();
// eslint-disable-line @typescript-eslint/no-unused-vars
const
{
streamMessage
,
isStreaming
,
setIsStreaming
}
=
useStreamChat
({
hasChatId
:
false
,
});
// eslint-disable-line @typescript-eslint/no-unused-vars
const
adjustHeight
=
()
=>
{
const
textarea
=
textareaRef
.
current
;
...
...
src/hooks/useProposal.ts
浏览文件 @
a4702f90
...
...
@@ -8,35 +8,39 @@ export function useProposal(chatId?: number | undefined) {
const
[
isLoading
,
setIsLoading
]
=
useState
<
boolean
>
(
false
);
const
[
error
,
setError
]
=
useState
<
string
|
null
>
(
null
);
const
fetchProposal
=
useCallback
(
async
()
=>
{
if
(
chatId
===
undefined
)
{
setProposalResult
(
null
);
setIsLoading
(
false
);
const
fetchProposal
=
useCallback
(
async
(
overrideChatId
?:
number
)
=>
{
chatId
=
overrideChatId
??
chatId
;
if
(
chatId
===
undefined
)
{
setProposalResult
(
null
);
setIsLoading
(
false
);
setError
(
null
);
return
;
}
setIsLoading
(
true
);
setError
(
null
);
return
;
}
setIsLoading
(
true
);
setError
(
null
);
setProposalResult
(
null
);
// Reset on new fetch
try
{
// Type assertion might be needed depending on how IpcClient is typed
const
result
=
(
await
IpcClient
.
getInstance
().
getProposal
(
chatId
))
as
ProposalResult
|
null
;
setProposalResult
(
null
);
// Reset on new fetch
try
{
// Type assertion might be needed depending on how IpcClient is typed
const
result
=
(
await
IpcClient
.
getInstance
().
getProposal
(
chatId
))
as
ProposalResult
|
null
;
if
(
result
)
{
setProposalResult
(
result
);
}
else
{
setProposalResult
(
null
);
// Explicitly set to null if IPC returns null
if
(
result
)
{
setProposalResult
(
result
);
}
else
{
setProposalResult
(
null
);
// Explicitly set to null if IPC returns null
}
}
catch
(
err
:
any
)
{
console
.
error
(
"Error fetching proposal:"
,
err
);
setError
(
err
.
message
||
"Failed to fetch proposal"
);
setProposalResult
(
null
);
// Clear proposal data on error
}
finally
{
setIsLoading
(
false
);
}
}
catch
(
err
:
any
)
{
console
.
error
(
"Error fetching proposal:"
,
err
);
setError
(
err
.
message
||
"Failed to fetch proposal"
);
setProposalResult
(
null
);
// Clear proposal data on error
}
finally
{
setIsLoading
(
false
);
}
},
[
chatId
]);
// Depend on chatId
},
[
chatId
]
);
// Depend on chatId
useEffect
(()
=>
{
fetchProposal
();
...
...
src/hooks/useStreamChat.ts
浏览文件 @
a4702f90
...
...
@@ -22,7 +22,9 @@ export function getRandomString() {
return
Math
.
random
().
toString
(
36
).
substring
(
2
,
15
);
}
export
function
useStreamChat
()
{
export
function
useStreamChat
({
hasChatId
=
true
,
}:
{
hasChatId
?:
boolean
}
=
{})
{
const
[
messages
,
setMessages
]
=
useAtom
(
chatMessagesAtom
);
const
[
isStreaming
,
setIsStreaming
]
=
useAtom
(
isStreamingAtom
);
const
[
error
,
setError
]
=
useAtom
(
chatErrorAtom
);
...
...
@@ -32,8 +34,14 @@ export function useStreamChat() {
const
{
refreshApp
}
=
useLoadApp
(
selectedAppId
);
const
setStreamCount
=
useSetAtom
(
chatStreamCountAtom
);
const
{
refreshVersions
}
=
useLoadVersions
(
selectedAppId
);
const
{
id
:
chatId
}
=
useSearch
({
from
:
"/chat"
});
const
{
refreshProposal
}
=
useProposal
(
chatId
);
let
chatId
:
number
|
undefined
;
if
(
hasChatId
)
{
const
{
id
}
=
useSearch
({
from
:
"/chat"
});
chatId
=
id
;
}
let
{
refreshProposal
}
=
hasChatId
?
useProposal
(
chatId
)
:
useProposal
();
const
streamMessage
=
useCallback
(
async
({
prompt
,
...
...
@@ -93,7 +101,7 @@ export function useStreamChat() {
if
(
response
.
updatedFiles
)
{
setIsPreviewOpen
(
true
);
}
refreshProposal
();
refreshProposal
(
chatId
);
// Keep the same as below
setIsStreaming
(
false
);
...
...
src/ipc/handlers/proposal_handlers.ts
浏览文件 @
a4702f90
...
...
@@ -51,18 +51,7 @@ const getProposalHandler = async (
return
null
;
}
if
(
latestAssistantMessage
?.
approvalState
===
"approved"
)
{
return
{
proposal
:
{
type
:
"action-proposal"
,
actions
:
[
{
id
:
"restart-app"
,
},
],
},
chatId
:
chatId
,
messageId
:
latestAssistantMessage
.
id
,
};
return
null
;
}
if
(
latestAssistantMessage
?.
content
&&
latestAssistantMessage
.
id
)
{
...
...
src/lib/schemas.ts
浏览文件 @
a4702f90
...
...
@@ -127,7 +127,13 @@ export interface ActionProposal {
actions
:
SuggestedAction
[];
}
export
type
Proposal
=
CodeProposal
|
ActionProposal
;
export
interface
TipProposal
{
type
:
"tip-proposal"
;
title
:
string
;
description
:
string
;
}
export
type
Proposal
=
CodeProposal
|
ActionProposal
|
TipProposal
;
export
interface
ProposalResult
{
proposal
:
Proposal
;
...
...
src/pages/home.tsx
浏览文件 @
a4702f90
...
...
@@ -20,7 +20,7 @@ export default function HomePage() {
const
{
settings
,
isAnyProviderSetup
}
=
useSettings
();
const
setIsPreviewOpen
=
useSetAtom
(
isPreviewOpenAtom
);
const
[
isLoading
,
setIsLoading
]
=
useState
(
false
);
const
{
streamMessage
}
=
useStreamChat
();
const
{
streamMessage
}
=
useStreamChat
(
{
hasChatId
:
false
}
);
// Get the appId from search params
const
appId
=
search
.
appId
?
Number
(
search
.
appId
)
:
null
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论