Skip to content

Commit

Permalink
Fix TypeScript and linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
openhands-agent committed Dec 1, 2024
1 parent c3c1df8 commit 981a7d1
Showing 1 changed file with 102 additions and 58 deletions.
160 changes: 102 additions & 58 deletions frontend/src/services/observations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,80 +52,124 @@ export function handleObservationMessage(message: ObservationMessage) {
}
if (!message.extras?.hidden) {
// Convert the message to the appropriate observation type
const observation = message.observation;
const { observation } = message;
const baseObservation = {
...message,
source: "agent" as const
source: "agent" as const,
};

switch (observation) {
case "agent_state_changed":
store.dispatch(addAssistantObservation({
...baseObservation,
observation: "agent_state_changed" as const,
extras: {
agent_state: (message.extras.agent_state as AgentState) || "idle"
}
}));
store.dispatch(
addAssistantObservation({
...baseObservation,
observation: "agent_state_changed" as const,
extras: {
agent_state: (message.extras.agent_state as AgentState) || "idle",
},
}),
);
break;
case "run":
store.dispatch(addAssistantObservation({
...baseObservation,
observation: "run" as const,
extras: {
command: String(message.extras.command || ""),
command_id: Number(message.extras.command_id || 0),
exit_code: Number(message.extras.exit_code || 0),
hidden: Boolean(message.extras.hidden)
}
}));
store.dispatch(
addAssistantObservation({
...baseObservation,
observation: "run" as const,
extras: {
command: String(message.extras.command || ""),
command_id: Number(message.extras.command_id || 0),
exit_code: Number(message.extras.exit_code || 0),
hidden: Boolean(message.extras.hidden),
},
}),
);
break;
case "run_ipython":
store.dispatch(addAssistantObservation({
...baseObservation,
observation: "run_ipython" as const,
extras: {
code: String(message.extras.code || "")
}
}));
store.dispatch(
addAssistantObservation({
...baseObservation,
observation: "run_ipython" as const,
extras: {
code: String(message.extras.code || ""),
},
}),
);
break;
case "delegate":
store.dispatch(addAssistantObservation({
...baseObservation,
observation: "delegate" as const,
extras: {
outputs: typeof message.extras.outputs === 'object' ? message.extras.outputs as Record<string, unknown> : {}
}
}));
store.dispatch(
addAssistantObservation({
...baseObservation,
observation: "delegate" as const,
extras: {
outputs:
typeof message.extras.outputs === "object"
? (message.extras.outputs as Record<string, unknown>)
: {},
},
}),
);
break;
case "browse":
store.dispatch(addAssistantObservation({
...baseObservation,
observation: "browse" as const,
extras: {
url: String(message.extras.url || ""),
screenshot: String(message.extras.screenshot || ""),
error: Boolean(message.extras.error),
open_page_urls: Array.isArray(message.extras.open_page_urls) ? message.extras.open_page_urls : [],
active_page_index: Number(message.extras.active_page_index || 0),
dom_object: typeof message.extras.dom_object === 'object' ? message.extras.dom_object as Record<string, unknown> : {},
axtree_object: typeof message.extras.axtree_object === 'object' ? message.extras.axtree_object as Record<string, unknown> : {},
extra_element_properties: typeof message.extras.extra_element_properties === 'object' ? message.extras.extra_element_properties as Record<string, unknown> : {},
last_browser_action: String(message.extras.last_browser_action || ""),
last_browser_action_error: message.extras.last_browser_action_error,
focused_element_bid: String(message.extras.focused_element_bid || "")
}
}));
store.dispatch(
addAssistantObservation({
...baseObservation,
observation: "browse" as const,
extras: {
url: String(message.extras.url || ""),
screenshot: String(message.extras.screenshot || ""),
error: Boolean(message.extras.error),
open_page_urls: Array.isArray(message.extras.open_page_urls)
? message.extras.open_page_urls
: [],
active_page_index: Number(message.extras.active_page_index || 0),
dom_object:
typeof message.extras.dom_object === "object"
? (message.extras.dom_object as Record<string, unknown>)
: {},
axtree_object:
typeof message.extras.axtree_object === "object"
? (message.extras.axtree_object as Record<string, unknown>)
: {},
extra_element_properties:
typeof message.extras.extra_element_properties === "object"
? (message.extras.extra_element_properties as Record<
string,
unknown
>)
: {},
last_browser_action: String(
message.extras.last_browser_action || "",
),
last_browser_action_error:
message.extras.last_browser_action_error,
focused_element_bid: String(
message.extras.focused_element_bid || "",
),
},
}),
);
break;
case "error":
store.dispatch(addAssistantObservation({
...baseObservation,
observation: "error" as const,
source: "user" as const,
extras: {
error_id: message.extras.error_id
}
}));
store.dispatch(
addAssistantObservation({
...baseObservation,
observation: "error" as const,
source: "user" as const,
extras: {
error_id: message.extras.error_id,
},
}),
);
break;
default:
// For any unhandled observation types, dispatch a generic observation
store.dispatch(
addAssistantObservation({
...baseObservation,
observation: observation as const,
extras: message.extras,
}),
);
break;
}
}
Expand Down

0 comments on commit 981a7d1

Please sign in to comment.