π OpenHands: AI-Driven Development
Feat changed "is_confirmed" to "confirmation_state" (#4508)
tofarree2c2ff2b8d2
diff --git a/frontend/src/components/modals/security/invariant/Invariant.tsx b/frontend/src/components/modals/security/invariant/Invariant.tsxindex 8372ae4743..afb6bf2cb3 100644--- a/frontend/src/components/modals/security/invariant/Invariant.tsx+++ b/frontend/src/components/modals/security/invariant/Invariant.tsx@@ -171,7 +171,7 @@ function SecurityInvariant(): JSX.Element {{logs.map((log: SecurityAnalyzerLog, index: number) => (<divkey={index}- className={`mb-2 p-2 rounded-lg ${log.confirmed_changed && log.is_confirmed === "confirmed" ? "border-green-800" : "border-red-800"}`}+ className={`mb-2 p-2 rounded-lg ${log.confirmed_changed && log.confirmation_state === "confirmed" ? "border-green-800" : "border-red-800"}`}style={{backgroundColor: "rgba(128, 128, 128, 0.2)",borderWidth: log.confirmed_changed ? "2px" : "0",@@ -179,7 +179,7 @@ function SecurityInvariant(): JSX.Element {><p className="text-sm relative break-words">{log.content}- {(log.is_confirmed === "awaiting_confirmation" ||+ {(log.confirmation_state === "awaiting_confirmation" ||log.confirmed_changed) && (<IoAlertCircle className="absolute top-0 right-0" />)}diff --git a/frontend/src/services/actions.ts b/frontend/src/services/actions.tsindex 238bcdc3d9..46b6aad851 100644--- a/frontend/src/services/actions.ts+++ b/frontend/src/services/actions.ts@@ -60,10 +60,7 @@ const messageActions = {if (message.args.thought) {store.dispatch(addAssistantMessage(message.args.thought));}- if (- !message.args.is_confirmed ||- message.args.is_confirmed !== "rejected"- ) {+ if (message.args.confirmation_state !== "rejected") {store.dispatch(appendJupyterInput(message.args.code));}},@@ -91,7 +88,7 @@ export function handleActionMessage(message: ActionMessage) {if ((message.action === ActionType.RUN ||message.action === ActionType.RUN_IPYTHON) &&- message.args.is_confirmed === "awaiting_confirmation"+ message.args.confirmation_state === "awaiting_confirmation") {if (message.args.thought) {store.dispatch(addAssistantMessage(message.args.thought));diff --git a/frontend/src/state/securityAnalyzerSlice.ts b/frontend/src/state/securityAnalyzerSlice.tsindex c56f53f9cf..22ecb09959 100644--- a/frontend/src/state/securityAnalyzerSlice.ts+++ b/frontend/src/state/securityAnalyzerSlice.ts@@ -11,7 +11,7 @@ export type SecurityAnalyzerLog = {id: number;content: string;security_risk: ActionSecurityRisk;- is_confirmed?: "awaiting_confirmation" | "confirmed" | "rejected";+ confirmation_state?: "awaiting_confirmation" | "confirmed" | "rejected";confirmed_changed: boolean;};@@ -32,20 +32,20 @@ export const securityAnalyzerSlice = createSlice({action.payload.args.content ||action.payload.message,security_risk: action.payload.args.security_risk as ActionSecurityRisk,- is_confirmed: action.payload.args.is_confirmed,+ confirmation_state: action.payload.args.confirmation_state,confirmed_changed: false,};const existingLog = state.logs.find((stateLog) =>stateLog.id === log.id ||- (stateLog.is_confirmed === "awaiting_confirmation" &&+ (stateLog.confirmation_state === "awaiting_confirmation" &&stateLog.content === log.content),);if (existingLog) {- if (existingLog.is_confirmed !== log.is_confirmed) {- existingLog.is_confirmed = log.is_confirmed;+ if (existingLog.confirmation_state !== log.confirmation_state) {+ existingLog.confirmation_state = log.confirmation_state;existingLog.confirmed_changed = true;}} else {diff --git a/frontend/src/types/core/actions.ts b/frontend/src/types/core/actions.tsindex b19657b614..a94c2da3ef 100644--- a/frontend/src/types/core/actions.ts+++ b/frontend/src/types/core/actions.ts@@ -12,7 +12,7 @@ export interface CommandAction extends OpenHandsActionEvent<"run"> {source: "agent";args: {command: string;- is_confirmed: "confirmed" | "rejected" | "awaiting_confirmation";+ confirmation_state: "confirmed" | "rejected" | "awaiting_confirmation";thought: string;hidden?: boolean;};@@ -32,7 +32,7 @@ export interface IPythonAction extends OpenHandsActionEvent<"run_ipython"> {source: "agent";args: {code: string;- is_confirmed: "confirmed" | "rejected" | "awaiting_confirmation";+ confirmation_state: "confirmed" | "rejected" | "awaiting_confirmation";kernel_init_code: string;thought: string;};diff --git a/openhands/controller/agent_controller.py b/openhands/controller/agent_controller.pyindex 3bd2f48426..b6fbe2892a 100644--- a/openhands/controller/agent_controller.py+++ b/openhands/controller/agent_controller.py@@ -224,7 +224,8 @@ class AgentController:"""if (self._pending_action- and getattr(self._pending_action, 'is_confirmed', None)+ and hasattr(self._pending_action, 'confirmation_state')+ and self._pending_action.confirmation_state== ActionConfirmationStatus.AWAITING_CONFIRMATION):return@@ -329,9 +330,10 @@ class AgentController:if hasattr(self._pending_action, 'thought'):self._pending_action.thought = '' # type: ignore[union-attr]if new_state == AgentState.USER_CONFIRMED:- self._pending_action.is_confirmed = ActionConfirmationStatus.CONFIRMED # type: ignore[attr-defined]+ confirmation_state = ActionConfirmationStatus.CONFIRMEDelse:- self._pending_action.is_confirmed = ActionConfirmationStatus.REJECTED # type: ignore[attr-defined]+ confirmation_state = ActionConfirmationStatus.REJECTED+ self._pending_action.confirmation_state = confirmation_state # type: ignore[attr-defined]self.event_stream.add_event(self._pending_action, EventSource.AGENT)self.state.agent_state = new_state@@ -452,12 +454,15 @@ class AgentController:if self.state.confirmation_mode and (type(action) is CmdRunAction or type(action) is IPythonRunCellAction):- action.is_confirmed = ActionConfirmationStatus.AWAITING_CONFIRMATION+ action.confirmation_state = (+ ActionConfirmationStatus.AWAITING_CONFIRMATION+ )self._pending_action = actionif not isinstance(action, NullAction):if (- getattr(action, 'is_confirmed', None)+ hasattr(action, 'confirmation_state')+ and action.confirmation_state== ActionConfirmationStatus.AWAITING_CONFIRMATION):await self.set_agent_state_to(AgentState.AWAITING_USER_CONFIRMATION)diff --git a/openhands/events/action/commands.py b/openhands/events/action/commands.pyindex 94fe1d5f5d..5a7e1fef52 100644--- a/openhands/events/action/commands.py+++ b/openhands/events/action/commands.py@@ -28,7 +28,7 @@ class CmdRunAction(Action):hidden: bool = Falseaction: str = ActionType.RUNrunnable: ClassVar[bool] = True- is_confirmed: ActionConfirmationStatus = ActionConfirmationStatus.CONFIRMED+ confirmation_state: ActionConfirmationStatus = ActionConfirmationStatus.CONFIRMEDsecurity_risk: ActionSecurityRisk | None = None@property@@ -49,7 +49,7 @@ class IPythonRunCellAction(Action):thought: str = ''action: str = ActionType.RUN_IPYTHONrunnable: ClassVar[bool] = True- is_confirmed: ActionConfirmationStatus = ActionConfirmationStatus.CONFIRMED+ confirmation_state: ActionConfirmationStatus = ActionConfirmationStatus.CONFIRMEDsecurity_risk: ActionSecurityRisk | None = Nonekernel_init_code: str = '' # code to run in the kernel (if the kernel is restarted)diff --git a/openhands/events/serialization/event.py b/openhands/events/serialization/event.pyindex 36883ae436..ee15ab6955 100644--- a/openhands/events/serialization/event.py+++ b/openhands/events/serialization/event.py@@ -93,7 +93,7 @@ def event_to_memory(event: 'Event', max_message_chars: int) -> dict:if 'args' in d:d['args'].pop('blocking', None)d['args'].pop('keep_prompt', None)- d['args'].pop('is_confirmed', None)+ d['args'].pop('confirmation_state', None)if 'extras' in d:remove_fields(d['extras'], DELETE_FROM_MEMORY_EXTRAS)diff --git a/openhands/runtime/base.py b/openhands/runtime/base.pyindex 2646c06768..a2de0c4829 100644--- a/openhands/runtime/base.py+++ b/openhands/runtime/base.py@@ -140,8 +140,9 @@ class Runtime(FileEditRuntimeMixin):if not action.runnable:return NullObservation('')if (- hasattr(action, 'is_confirmed')- and action.is_confirmed == ActionConfirmationStatus.AWAITING_CONFIRMATION+ hasattr(action, 'confirmation_state')+ and action.confirmation_state+ == ActionConfirmationStatus.AWAITING_CONFIRMATION):return NullObservation('')action_type = action.action # type: ignore[attr-defined]@@ -152,8 +153,8 @@ class Runtime(FileEditRuntimeMixin):f'Action {action_type} is not supported in the current runtime.')if (- hasattr(action, 'is_confirmed')- and action.is_confirmed == ActionConfirmationStatus.REJECTED+ getattr(action, 'confirmation_state', None)+ == ActionConfirmationStatus.REJECTED):return UserRejectObservation('Action has been rejected by the user! Waiting for further user input.'diff --git a/openhands/runtime/impl/eventstream/eventstream_runtime.py b/openhands/runtime/impl/eventstream/eventstream_runtime.pyindex 358e3c0907..25a4291283 100644--- a/openhands/runtime/impl/eventstream/eventstream_runtime.py+++ b/openhands/runtime/impl/eventstream/eventstream_runtime.py@@ -441,8 +441,8 @@ class EventStreamRuntime(Runtime):if not action.runnable:return NullObservation('')if (- hasattr(action, 'is_confirmed')- and action.is_confirmed+ hasattr(action, 'confirmation_state')+ and action.confirmation_state== ActionConfirmationStatus.AWAITING_CONFIRMATION):return NullObservation('')@@ -454,8 +454,8 @@ class EventStreamRuntime(Runtime):f'Action {action_type} is not supported in the current runtime.')if (- hasattr(action, 'is_confirmed')- and action.is_confirmed == ActionConfirmationStatus.REJECTED+ getattr(action, 'confirmation_state', None)+ == ActionConfirmationStatus.REJECTED):return UserRejectObservation('Action has been rejected by the user! Waiting for further user input.'diff --git a/openhands/security/invariant/analyzer.py b/openhands/security/invariant/analyzer.pyindex 9d8b280716..7d6548be9d 100644--- a/openhands/security/invariant/analyzer.py+++ b/openhands/security/invariant/analyzer.py@@ -9,6 +9,7 @@ from fastapi.responses import JSONResponsefrom openhands.core.logger import openhands_logger as loggerfrom openhands.events.action.action import (Action,+ ActionConfirmationStatus,ActionSecurityRisk,)from openhands.events.event import Event, EventSource@@ -137,8 +138,9 @@ class InvariantAnalyzer(SecurityAnalyzer):return (risk is not Noneand risk < self.settings.get('RISK_SEVERITY', ActionSecurityRisk.MEDIUM)- and hasattr(event, 'is_confirmed')- and event.is_confirmed == 'awaiting_confirmation'+ and hasattr(event, 'confirmation_state')+ and event.confirmation_state+ == ActionConfirmationStatus.AWAITING_CONFIRMATION)async def confirm(self, event: Event) -> None:diff --git a/openhands/server/listen.py b/openhands/server/listen.pyindex defbd0d42b..3da804c91a 100644--- a/openhands/server/listen.py+++ b/openhands/server/listen.py@@ -279,7 +279,7 @@ async def websocket_endpoint(websocket: WebSocket):```- Run a command:```json- {"action": "run", "args": {"command": "ls -l", "thought": "", "is_confirmed": "confirmed"}}+ {"action": "run", "args": {"command": "ls -l", "thought": "", "confirmation_state": "confirmed"}}```- Run an IPython command:```jsondiff --git a/tests/unit/test_action_serialization.py b/tests/unit/test_action_serialization.pyindex df8fba1e02..87ea93531c 100644--- a/tests/unit/test_action_serialization.py+++ b/tests/unit/test_action_serialization.py@@ -49,7 +49,7 @@ def serialization_deserialization(if 'args' in original_memory_dict:original_memory_dict['args'].pop('keep_prompt', None)original_memory_dict['args'].pop('blocking', None)- original_memory_dict['args'].pop('is_confirmed', None)+ original_memory_dict['args'].pop('confirmation_state', None)# the rest should matchassert (@@ -103,7 +103,7 @@ def test_cmd_run_action_serialization_deserialization():'thought': '','keep_prompt': True,'hidden': False,- 'is_confirmed': ActionConfirmationStatus.CONFIRMED,+ 'confirmation_state': ActionConfirmationStatus.CONFIRMED,},}serialization_deserialization(original_action_dict, CmdRunAction)diff --git a/tests/unit/test_security.py b/tests/unit/test_security.pyindex ccfa6c6080..4f0aa4dc39 100644--- a/tests/unit/test_security.py+++ b/tests/unit/test_security.py@@ -222,7 +222,7 @@ def test_unsafe_bash_command(temp_dir: str):arguments={'code': "print('hello')",'kernel_init_code': '',- 'is_confirmed': ActionConfirmationStatus.CONFIRMED,+ 'confirmation_state': ActionConfirmationStatus.CONFIRMED,},),),@@ -267,7 +267,7 @@ def test_unsafe_bash_command(temp_dir: str):'command': 'ls','hidden': False,'keep_prompt': True,- 'is_confirmed': ActionConfirmationStatus.CONFIRMED,+ 'confirmation_state': ActionConfirmationStatus.CONFIRMED,},),),