feat: improve the allow tool ui (#1473)
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
|||||||
getTextContent,
|
getTextContent,
|
||||||
getToolRequests,
|
getToolRequests,
|
||||||
getToolResponses,
|
getToolResponses,
|
||||||
getToolConfirmationRequestId,
|
getToolConfirmationContent,
|
||||||
} from '../types/message';
|
} from '../types/message';
|
||||||
import ToolCallConfirmation from './ToolCallConfirmation';
|
import ToolCallConfirmation from './ToolCallConfirmation';
|
||||||
|
|
||||||
@@ -36,7 +36,8 @@ export default function GooseMessage({ message, metadata, messages, append }: Go
|
|||||||
const previousUrls = previousMessage ? extractUrls(getTextContent(previousMessage)) : [];
|
const previousUrls = previousMessage ? extractUrls(getTextContent(previousMessage)) : [];
|
||||||
const urls = toolRequests.length === 0 ? extractUrls(textContent, previousUrls) : [];
|
const urls = toolRequests.length === 0 ? extractUrls(textContent, previousUrls) : [];
|
||||||
|
|
||||||
const [toolConfirmationId, hasToolConfirmation] = getToolConfirmationRequestId(message);
|
const toolConfirmationContent = getToolConfirmationContent(message);
|
||||||
|
const hasToolConfirmation = toolConfirmationContent !== undefined;
|
||||||
|
|
||||||
// Find tool responses that correspond to the tool requests in this message
|
// Find tool responses that correspond to the tool requests in this message
|
||||||
const toolResponsesMap = useMemo(() => {
|
const toolResponsesMap = useMemo(() => {
|
||||||
@@ -72,7 +73,12 @@ export default function GooseMessage({ message, metadata, messages, append }: Go
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{hasToolConfirmation && <ToolCallConfirmation toolConfirmationId={toolConfirmationId} />}
|
{hasToolConfirmation && (
|
||||||
|
<ToolCallConfirmation
|
||||||
|
toolConfirmationId={toolConfirmationContent.id}
|
||||||
|
toolName={toolConfirmationContent.toolName}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{toolRequests.length > 0 && (
|
{toolRequests.length > 0 && (
|
||||||
<div className="goose-message-tool bg-bgApp border border-borderSubtle dark:border-gray-700 rounded-b-2xl px-4 pt-4 pb-2 mt-1">
|
<div className="goose-message-tool bg-bgApp border border-borderSubtle dark:border-gray-700 rounded-b-2xl px-4 pt-4 pb-2 mt-1">
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { ConfirmToolRequest } from '../utils/toolConfirm';
|
import { ConfirmToolRequest } from '../utils/toolConfirm';
|
||||||
|
import { snakeToTitleCase } from '../utils';
|
||||||
|
import Box from './ui/Box';
|
||||||
|
|
||||||
export default function ToolConfirmation({ toolConfirmationId }) {
|
export default function ToolConfirmation({ toolConfirmationId, toolName }) {
|
||||||
const [disabled, setDisabled] = useState(false);
|
const [clicked, setClicked] = useState(false);
|
||||||
|
const [status, setStatus] = useState('');
|
||||||
|
|
||||||
const handleButtonClick = (confirmed) => {
|
const handleButtonClick = (confirmed) => {
|
||||||
setDisabled(true);
|
setClicked(true);
|
||||||
|
setStatus(confirmed ? 'approved' : 'denied');
|
||||||
ConfirmToolRequest(toolConfirmationId, confirmed);
|
ConfirmToolRequest(toolConfirmationId, confirmed);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -14,26 +18,58 @@ export default function ToolConfirmation({ toolConfirmationId }) {
|
|||||||
<div className="goose-message-content bg-bgSubtle rounded-2xl px-4 py-2 rounded-b-none">
|
<div className="goose-message-content bg-bgSubtle rounded-2xl px-4 py-2 rounded-b-none">
|
||||||
Goose would like to call the above tool. Allow?
|
Goose would like to call the above tool. Allow?
|
||||||
</div>
|
</div>
|
||||||
<div className="goose-message-tool bg-bgApp border border-borderSubtle dark:border-gray-700 rounded-b-2xl px-4 pt-4 pb-2 flex gap-4 mt-1">
|
{clicked ? (
|
||||||
<button
|
<div className="goose-message-tool bg-bgApp border border-borderSubtle dark:border-gray-700 rounded-b-2xl px-4 pt-4 pb-2 flex gap-4 mt-1">
|
||||||
className={
|
<div className="flex items-center">
|
||||||
'bg-black text-white dark:bg-white dark:text-black rounded-full px-6 py-2 transition'
|
{status === 'approved' && (
|
||||||
}
|
<svg
|
||||||
onClick={() => handleButtonClick(true)}
|
className="w-5 h-5 text-gray-500"
|
||||||
disabled={disabled}
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
>
|
fill="none"
|
||||||
Allow tool
|
viewBox="0 0 24 24"
|
||||||
</button>
|
stroke="currentColor"
|
||||||
<button
|
strokeWidth={2}
|
||||||
className={
|
>
|
||||||
'bg-white text-black dark:bg-black dark:text-white border border-gray-300 dark:border-gray-700 rounded-full px-6 py-2 transition'
|
<path strokeLinecap="round" strokeLinejoin="round" d="M5 13l4 4L19 7" />
|
||||||
}
|
</svg>
|
||||||
onClick={() => handleButtonClick(false)}
|
)}
|
||||||
disabled={disabled}
|
{status === 'denied' && (
|
||||||
>
|
<svg
|
||||||
Deny
|
className="w-5 h-5 text-gray-500"
|
||||||
</button>
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
</div>
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth={2}
|
||||||
|
>
|
||||||
|
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
|
||||||
|
</svg>
|
||||||
|
)}
|
||||||
|
<span className="ml-2 text-gray-500 dark:text-gray-400">
|
||||||
|
{snakeToTitleCase(toolName.substring(toolName.lastIndexOf('__') + 2))} is {status}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="goose-message-tool bg-bgApp border border-borderSubtle dark:border-gray-700 rounded-b-2xl px-4 pt-4 pb-2 flex gap-4 mt-1">
|
||||||
|
<button
|
||||||
|
className={
|
||||||
|
'bg-black text-white dark:bg-white dark:text-black rounded-full px-6 py-2 transition'
|
||||||
|
}
|
||||||
|
onClick={() => handleButtonClick(true)}
|
||||||
|
>
|
||||||
|
Allow tool
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={
|
||||||
|
'bg-white text-black dark:bg-black dark:text-white border border-gray-300 dark:border-gray-700 rounded-full px-6 py-2 transition'
|
||||||
|
}
|
||||||
|
onClick={() => handleButtonClick(false)}
|
||||||
|
>
|
||||||
|
Deny
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,20 +187,13 @@ export function getToolResponses(message: Message): ToolResponseMessageContent[]
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getToolConfirmationRequestId(message: Message): [string, boolean] {
|
export function getToolConfirmationContent(
|
||||||
const hasToolConfirmationRequest = message.content.some(
|
message: Message
|
||||||
|
): ToolConfirmationRequestMessageContent {
|
||||||
|
return message.content.find(
|
||||||
(content): content is ToolConfirmationRequestMessageContent =>
|
(content): content is ToolConfirmationRequestMessageContent =>
|
||||||
content.type === 'toolConfirmationRequest'
|
content.type === 'toolConfirmationRequest'
|
||||||
);
|
);
|
||||||
|
|
||||||
const contentId = hasToolConfirmationRequest
|
|
||||||
? message.content.find(
|
|
||||||
(content): content is ToolConfirmationRequestMessageContent =>
|
|
||||||
content.type === 'toolConfirmationRequest'
|
|
||||||
)?.id || ''
|
|
||||||
: '';
|
|
||||||
|
|
||||||
return [contentId, hasToolConfirmationRequest];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hasCompletedToolCalls(message: Message): boolean {
|
export function hasCompletedToolCalls(message: Message): boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user