3434 */
3535
3636import React from "react" ;
37+ import classNames from "classnames" ;
3738import { observer } from "mobx-react" ;
3839
3940import { ToolsPermission } from "../../../../../../../../enums" ;
@@ -48,6 +49,7 @@ import {
4849} from "../../../../../../../../components/modal-dialog" ;
4950
5051import styles from "../../../../ChatMessageBody.module.scss" ;
52+ import chatStyles from "../../../../../chat-container/ChatContainer.module.scss" ;
5153import { ToolCall } from "../tool-call" ;
5254import { isMobile } from "../../../../../../../../utils" ;
5355import { useCommonTranslation } from "../../../../../../../../utils/i18n" ;
@@ -67,26 +69,57 @@ export const ToolCallConfirmDialog = observer(
6769 toolsConfirmQueue,
6870 addToToolsConfirmQueue,
6971 removeFromToolsConfirmQueue,
72+ generateDocxToolName,
73+ generateFormToolName,
74+ generatePresentationToolName,
7075 } = useMessageStore ( ) ;
7176 const { aiApi } = useApi ( ) ;
7277 const t = useCommonTranslation ( ) ;
7378
74- const onClickAction = ( decision : ToolsPermission ) => {
79+ const isGenerateTool =
80+ content . name === generateDocxToolName ||
81+ content . name === generateFormToolName ||
82+ content . name === generatePresentationToolName ;
83+
84+ const onClickAction = async ( decision : ToolsPermission ) => {
7585 if ( content . callId ) {
76- aiApi . updateToolsPermission (
77- content . callId ,
78- alwaysAllow && decision === ToolsPermission . Allow
79- ? ToolsPermission . AlwaysAllow
80- : decision ,
81- ) ;
86+ if ( isGenerateTool ) {
87+ const allow = decision === ToolsPermission . Allow ;
88+ const result = await aiApi . updateToolFileDecision (
89+ content . callId ,
90+ allow ,
91+ ) ;
92+
93+ if ( allow && typeof result ?. id === "number" ) {
94+ const searchParams = new URLSearchParams ( ) ;
95+ searchParams . append ( "fileId" , String ( result . id ) ) ;
96+ searchParams . append ( "withTool" , "true" ) ;
97+
98+ window . open (
99+ `${ window . location . origin } /doceditor?${ searchParams . toString ( ) } ` ,
100+ "_blank" ,
101+ ) ;
102+ }
103+ } else {
104+ aiApi . updateToolsPermission (
105+ content . callId ,
106+ alwaysAllow && decision === ToolsPermission . Allow
107+ ? ToolsPermission . AlwaysAllow
108+ : decision ,
109+ ) ;
110+ }
82111 }
83112
84113 onClose ( ) ;
85114 } ;
86115
87116 const onCloseAction = ( ) => {
88117 if ( content . callId ) {
89- aiApi . updateToolsPermission ( content . callId , ToolsPermission . Deny ) ;
118+ if ( isGenerateTool ) {
119+ aiApi . updateToolFileDecision ( content . callId , false ) ;
120+ } else {
121+ aiApi . updateToolsPermission ( content . callId , ToolsPermission . Deny ) ;
122+ }
90123 }
91124
92125 onClose ( ) ;
@@ -114,40 +147,52 @@ export const ToolCallConfirmDialog = observer(
114147 </ ModalDialog . Header >
115148
116149 < ModalDialog . Body >
117- < div className = { styles . toolCallManage } >
150+ < div
151+ className = { classNames ( styles . toolCallManage , chatStyles . chatTokens ) }
152+ >
118153 < Text > { t ( "AIWouldLikeToUseThisTool" ) } </ Text >
119154 < ToolCall
120155 content = { content }
121156 status = { ToolCallStatus . Confirmation }
122157 placement = { ToolCallPlacement . ConfirmDialog }
123158 />
124159 < div >
125- < Text > { t ( "ReviewAction" ) } </ Text >
126- < Text > { t ( "CannotGuaranteeSecurity" ) } </ Text >
160+ { isGenerateTool ? (
161+ < Text > { t ( "AIGenerateDocumentDescription" ) } </ Text >
162+ ) : (
163+ < >
164+ < Text > { t ( "ReviewAction" ) } </ Text >
165+ < Text > { t ( "CannotGuaranteeSecurity" ) } </ Text >
166+ </ >
167+ ) }
127168 </ div >
128169 </ div >
129170 </ ModalDialog . Body >
130171
131172 < ModalDialog . Footer >
132- < div className = { styles . toolCallFooter } >
133- < Checkbox
134- isChecked = { alwaysAllow }
135- onChange = { ( e ) => setAlwaysAllow ( e . target . checked ) }
136- label = { t ( "AlwaysAllowToolCall" ) }
137- data-testid = "always-allow-checkbox"
138- />
173+ < div
174+ className = { classNames ( styles . toolCallFooter , chatStyles . chatTokens ) }
175+ >
176+ { ! isGenerateTool ? (
177+ < Checkbox
178+ isChecked = { alwaysAllow }
179+ onChange = { ( e ) => setAlwaysAllow ( e . target . checked ) }
180+ label = { t ( "AlwaysAllowToolCall" ) }
181+ data-testid = "always-allow-checkbox"
182+ />
183+ ) : null }
139184 < div className = { styles . buttonsBlockContainer } >
140185 < Button
141186 primary
142- label = { t ( "Allow" ) }
187+ label = { isGenerateTool ? t ( "Create" ) : t ( "Allow" ) }
143188 onClick = { ( ) => onClickAction ( ToolsPermission . Allow ) }
144189 scale = { isMobile ( ) }
145190 size = { ButtonSize . normal }
146191 data-testid = "allow-button"
147192 />
148193 < Button
149194 className = { styles . denyButton }
150- label = { t ( "Deny" ) }
195+ label = { isGenerateTool ? t ( "CancelButton" ) : t ( "Deny" ) }
151196 onClick = { ( ) => onClickAction ( ToolsPermission . Deny ) }
152197 size = { ButtonSize . normal }
153198 scale = { isMobile ( ) }
0 commit comments