🙌 OpenHands: AI-Driven Development
feat: V1 client types (#11216)
sp.wack1e8851b24412
diff --git a/frontend/src/types/v1/core/base/action.ts b/frontend/src/types/v1/core/base/action.tsnew file mode 100644index 0000000000..3147332696--- /dev/null+++ b/frontend/src/types/v1/core/base/action.ts@@ -0,0 +1,183 @@+import { ActionBase } from "./base";+import { TaskItem } from "./common";++interface MCPToolAction extends ActionBase<"MCPToolAction"> {+ /**+ * Dynamic data fields from the tool call+ */+ data: Record<string, unknown>;+}++interface FinishAction extends ActionBase<"FinishAction"> {+ /**+ * Final message to send to the user+ */+ message: string;+}++interface ThinkAction extends ActionBase<"ThinkAction"> {+ /**+ * The thought to log+ */+ thought: string;+}++interface ExecuteBashAction extends ActionBase<"ExecuteBashAction"> {+ /**+ * The bash command to execute. Can be empty string to view additional logs when previous exit code is `-1`. Can be `C-c` (Ctrl+C) to interrupt the currently running process.+ */+ command: string;+ /**+ * If True, the command is an input to the running process. If False, the command is a bash command to be executed in the terminal. Default is False.+ */+ is_input: boolean;+ /**+ * Optional. Sets a maximum time limit (in seconds) for running the command. If the command takes longer than this limit, you’ll be asked whether to continue or stop it.+ */+ timeout: number | null;+ /**+ * If True, reset the terminal by creating a new session. Used only when the terminal becomes unresponsive. Note that all previously set environment variables and session state will be lost after reset. Cannot be used with is_input=True.+ */+ reset: boolean;+}++interface StrReplaceEditorAction extends ActionBase<"StrReplaceEditorAction"> {+ /**+ * The commands to run. Allowed options are: `view`, `create`, `str_replace`, `insert`, `undo_edit`.+ */+ command: "view" | "create" | "str_replace" | "insert" | "undo_edit";+ /**+ * Absolute path to file or directory.+ */+ path: string;+ /**+ * Required parameter of `create` command, with the content of the file to be created.+ */+ file_text: string | null;+ /**+ * Required parameter of `str_replace` command containing the string in `path` to replace.+ */+ old_str: string | null;+ /**+ * Optional parameter of `str_replace` command containing the new string (if not given, no string will be added). Required parameter of `insert` command containing the string to insert.+ */+ new_str: string | null;+ /**+ * Required parameter of `insert` command. The `new_str` will be inserted AFTER the line `insert_line` of `path`. Must be >= 1.+ */+ insert_line: number | null;+ /**+ * Optional parameter of `view` command when `path` points to a file. If none is given, the full file is shown. If provided, the file will be shown in the indicated line number range, e.g. [11, 12] will show lines 11 and 12. Indexing at 1 to start. Setting `[start_line, -1]` shows all lines from `start_line` to the end of the file.+ */+ view_range: [number, number] | null;+}++interface TaskTrackerAction extends ActionBase<"TaskTrackerAction"> {+ /**+ * The command to execute. `view` shows the current task list. `plan` creates or updates the task list based on provided requirements and progress. Always `view` the current list before making changes.+ */+ command: "view" | "plan";+ /**+ * The full task list. Required parameter of `plan` command.+ */+ task_list: TaskItem[];+}++interface BrowserNavigateAction extends ActionBase<"BrowserNavigateAction"> {+ /**+ * The URL to navigate to+ */+ url: string;+ /**+ * Whether to open in a new tab. Default: False+ */+ new_tab: boolean;+}++interface BrowserClickAction extends ActionBase<"BrowserClickAction"> {+ /**+ * The index of the element to click (from browser_get_state)+ */+ index: number;+ /**+ * Whether to open any resulting navigation in a new tab. Default: False+ */+ new_tab: boolean;+}++interface BrowserTypeAction extends ActionBase<"BrowserTypeAction"> {+ /**+ * The index of the input element (from browser_get_state)+ */+ index: number;+ /**+ * The text to type+ */+ text: string;+}++interface BrowserGetStateAction extends ActionBase<"BrowserGetStateAction"> {+ /**+ * Whether to include a screenshot of the current page. Default: False+ */+ include_screenshot: boolean;+}++interface BrowserGetContentAction+ extends ActionBase<"BrowserGetContentAction"> {+ /**+ * Whether to include links in the content (default: False)+ */+ extract_links: boolean;+ /**+ * Character index to start from in the page content (default: 0)+ */+ start_from_char: number;+}++interface BrowserScrollAction extends ActionBase<"BrowserScrollAction"> {+ /**+ * Direction to scroll. Options: 'up', 'down'. Default: 'down'+ */+ direction: "up" | "down";+}++interface BrowserGoBackAction extends ActionBase<"BrowserGoBackAction"> {+ // No additional properties - this action has no parameters+}++interface BrowserListTabsAction extends ActionBase<"BrowserListTabsAction"> {+ // No additional properties - this action has no parameters+}++interface BrowserSwitchTabAction extends ActionBase<"BrowserSwitchTabAction"> {+ /**+ * 4 Character Tab ID of the tab to switch to (from browser_list_tabs)+ */+ tab_id: string;+}++interface BrowserCloseTabAction extends ActionBase<"BrowserCloseTabAction"> {+ /**+ * 4 Character Tab ID of the tab to close (from browser_list_tabs)+ */+ tab_id: string;+}++export type Action =+ | MCPToolAction+ | FinishAction+ | ThinkAction+ | ExecuteBashAction+ | StrReplaceEditorAction+ | TaskTrackerAction+ | BrowserNavigateAction+ | BrowserClickAction+ | BrowserTypeAction+ | BrowserGetStateAction+ | BrowserGetContentAction+ | BrowserScrollAction+ | BrowserGoBackAction+ | BrowserListTabsAction+ | BrowserSwitchTabAction+ | BrowserCloseTabAction;diff --git a/frontend/src/types/v1/core/base/base.ts b/frontend/src/types/v1/core/base/base.tsnew file mode 100644index 0000000000..e7e806ae39--- /dev/null+++ b/frontend/src/types/v1/core/base/base.ts@@ -0,0 +1,36 @@+type EventType =+ | "MCPTool"+ | "Finish"+ | "Think"+ | "ExecuteBash"+ | "StrReplaceEditor"+ | "TaskTracker";++type ActionOnlyType =+ | "BrowserNavigate"+ | "BrowserClick"+ | "BrowserType"+ | "BrowserGetState"+ | "BrowserGetContent"+ | "BrowserScroll"+ | "BrowserGoBack"+ | "BrowserListTabs"+ | "BrowserSwitchTab"+ | "BrowserCloseTab";++type ObservationOnlyType = "Browser";++type ActionEventType = `${ActionOnlyType}Action` | `${EventType}Action`;+type ObservationEventType =+ | `${ObservationOnlyType}Observation`+ | `${EventType}Observation`;++export interface ActionBase<T extends ActionEventType = ActionEventType> {+ kind: T;+}++export interface ObservationBase<+ T extends ObservationEventType = ObservationEventType,+> {+ kind: T;+}diff --git a/frontend/src/types/v1/core/base/common.ts b/frontend/src/types/v1/core/base/common.tsnew file mode 100644index 0000000000..2215764cc0--- /dev/null+++ b/frontend/src/types/v1/core/base/common.ts@@ -0,0 +1,77 @@+export interface TaskItem {+ /**+ * A brief title for the task.+ */+ title: string;+ /**+ * Additional details or notes about the task.+ */+ notes: string;+ /**+ * The current status of the task. One of 'todo', 'in_progress', or 'done'.+ */+ status: "todo" | "in_progress" | "done";+}++export interface CmdOutputMetadata {+ /**+ * The exit code of the last executed command+ */+ exit_code: number;+ /**+ * The process ID of the last executed command+ */+ pid: number;+ /**+ * The username of the current user+ */+ username: string | null;+ /**+ * The hostname of the machine+ */+ hostname: string | null;+ /**+ * The current working directory+ */+ working_dir: string | null;+ /**+ * The path to the current Python interpreter, if any+ */+ py_interpreter_path: string | null;+ /**+ * Prefix to add to command output+ */+ prefix: string;+ /**+ * Suffix to add to command output+ */+ suffix: string;+}++// Type aliases for event and tool call IDs+export type EventID = string;+export type ToolCallID = string;++// Source type for events+export type SourceType = "agent" | "user" | "environment";++// Security risk levels+export enum SecurityRisk {+ UNKNOWN = "UNKNOWN",+ LOW = "LOW",+ MEDIUM = "MEDIUM",+ HIGH = "HIGH",+}++// Content types for LLM messages+export interface TextContent {+ type: "text";+ text: string;+ cache_prompt?: boolean;+}++export interface ImageContent {+ type: "image";+ image_urls: string[];+ cache_prompt?: boolean;+}diff --git a/frontend/src/types/v1/core/base/event.ts b/frontend/src/types/v1/core/base/event.tsnew file mode 100644index 0000000000..7ed3c9bc7a--- /dev/null+++ b/frontend/src/types/v1/core/base/event.ts@@ -0,0 +1,79 @@+import {+ EventID,+ SourceType,+ ToolCallID,+ TextContent,+ ImageContent,+} from "./common";++// Base event interface - fundamental properties for all events+export interface BaseEvent {+ /**+ * Unique event id (ULID/UUID)+ */+ id: EventID;++ /**+ * Event timestamp (ISO string)+ */+ timestamp: string;++ /**+ * The source of this event+ */+ source: SourceType;+}++// LLM Message structure+export interface Message {+ role: "user" | "system" | "assistant" | "tool";+ content: (TextContent | ImageContent)[];+ cache_enabled?: boolean;+ vision_enabled?: boolean;+ tool_calls?: ChatCompletionMessageToolCall[];+ reasoning_content?: string | null;+ thinking_blocks?: (ThinkingBlock | RedactedThinkingBlock)[];+ name?: string;+ tool_call_id?: ToolCallID;+}++// Tool call structure from LiteLLM+export interface ChatCompletionMessageToolCall {+ id: string;+ type: "function";+ function: {+ name: string;+ arguments: string;+ };+}++// Tool parameter structure from LiteLLM+export interface ChatCompletionToolParam {+ type: "function";+ function: {+ name: string;+ description: string;+ parameters: Record<string, unknown>;+ };+}++// Thinking blocks for Anthropic extended thinking feature+export interface ThinkingBlock {+ type: "thinking";+ /**+ * The thinking content+ */+ thinking: string;+ /**+ * Cryptographic signature for the thinking block+ */+ signature: string;+}++export interface RedactedThinkingBlock {+ type: "redacted_thinking";+ /**+ * The redacted thinking content+ */+ data: string;+}diff --git a/frontend/src/types/v1/core/base/index.ts b/frontend/src/types/v1/core/base/index.tsnew file mode 100644index 0000000000..07292f3ed7--- /dev/null+++ b/frontend/src/types/v1/core/base/index.ts@@ -0,0 +1,6 @@+// Export all base types+export * from "./action";+export * from "./base";+export * from "./common";+export * from "./event";+export * from "./observation";diff --git a/frontend/src/types/v1/core/base/observation.ts b/frontend/src/types/v1/core/base/observation.tsnew file mode 100644index 0000000000..df4ab5c88c--- /dev/null+++ b/frontend/src/types/v1/core/base/observation.ts@@ -0,0 +1,136 @@+import { ObservationBase } from "./base";+import {+ CmdOutputMetadata,+ TaskItem,+ TextContent,+ ImageContent,+} from "./common";++interface MCPToolObservation extends ObservationBase<"MCPToolObservation"> {+ /**+ * Content returned from the MCP tool converted to LLM Ready TextContent or ImageContent+ */+ content: Array<TextContent | ImageContent>;+ /**+ * Whether the call resulted in an error+ */+ is_error: boolean;+ /**+ * Name of the tool that was called+ */+ tool_name: string;+}++interface FinishObservation extends ObservationBase<"FinishObservation"> {+ /**+ * Final message sent to the user+ */+ message: string;+}++interface ThinkObservation extends ObservationBase<"ThinkObservation"> {+ /**+ * Confirmation message. DEFAULT: "Your thought has been logged."+ */+ content: string;+}++interface BrowserObservation extends ObservationBase<"BrowserObservation"> {+ /**+ * The output message from the browser operation+ */+ output: string;+ /**+ * Error message if any+ */+ error: string | null;+ /**+ * Base64 screenshot data if available+ */+ screenshot_data: string | null;+}++interface ExecuteBashObservation+ extends ObservationBase<"ExecuteBashObservation"> {+ /**+ * The raw output from the tool.+ */+ output: string;+ /**+ * The bash command that was executed. Can be empty string if the observation is from a previous command that hit soft timeout and is not yet finished.+ */+ command: string | null;+ /**+ * The exit code of the command. -1 indicates the process hit the soft timeout and is not yet finished.+ */+ exit_code: number | null;+ /**+ * Whether there was an error during command execution.+ */+ error: boolean;+ /**+ * Whether the command execution timed out.+ */+ timeout: boolean;+ /**+ * Additional metadata captured from PS1 after command execution.+ */+ metadata: CmdOutputMetadata;+}++interface StrReplaceEditorObservation+ extends ObservationBase<"StrReplaceEditorObservation"> {+ /**+ * The commands to run. Allowed options are: `view`, `create`, `str_replace`, `insert`, `undo_edit`.+ */+ command: "view" | "create" | "str_replace" | "insert" | "undo_edit";+ /**+ * The output message from the tool for the LLM to see.+ */+ output: string;+ /**+ * The file path that was edited.+ */+ path: string | null;+ /**+ * Indicates if the file previously existed. If not, it was created.+ */+ prev_exist: boolean;+ /**+ * The content of the file before the edit.+ */+ old_content: string | null;+ /**+ * The content of the file after the edit.+ */+ new_content: string | null;+ /**+ * Error message if any.+ */+ error: string | null;+}++interface TaskTrackerObservation+ extends ObservationBase<"TaskTrackerObservation"> {+ /**+ * The formatted task list or status message.+ */+ content: string;+ /**+ * The command that was executed.+ */+ command: string;+ /**+ * The current task list.+ */+ task_list: TaskItem[];+}++export type Observation =+ | MCPToolObservation+ | FinishObservation+ | ThinkObservation+ | BrowserObservation+ | ExecuteBashObservation+ | StrReplaceEditorObservation+ | TaskTrackerObservation;diff --git a/frontend/src/types/v1/core/events/action-event.ts b/frontend/src/types/v1/core/events/action-event.tsnew file mode 100644index 0000000000..0c5e30c81f--- /dev/null+++ b/frontend/src/types/v1/core/events/action-event.ts@@ -0,0 +1,61 @@+import { Action } from "../base/action";+import { EventID, ToolCallID, SecurityRisk, TextContent } from "../base/common";+import {+ BaseEvent,+ ChatCompletionMessageToolCall,+ ThinkingBlock,+ RedactedThinkingBlock,+} from "../base/event";++export interface ActionEvent extends BaseEvent {+ /**+ * The thought process of the agent before taking this action+ */+ thought: TextContent[];++ /**+ * Intermediate reasoning/thinking content from reasoning models+ */+ reasoning_content?: string | null;++ /**+ * Anthropic thinking blocks from the LLM response+ */+ thinking_blocks: (ThinkingBlock | RedactedThinkingBlock)[];++ /**+ * Single action (tool call) returned by LLM+ */+ action: Action;++ /**+ * The name of the tool being called+ */+ tool_name: string;++ /**+ * The unique id returned by LLM API for this tool call+ */+ tool_call_id: ToolCallID;++ /**+ * The tool call received from the LLM response. We keep a copy of it+ * so it is easier to construct it into LLM message.+ * This could be different from `action`: e.g., `tool_call` may contain+ * `security_risk` field predicted by LLM when LLM risk analyzer is enabled,+ * while `action` does not.+ */+ tool_call: ChatCompletionMessageToolCall;++ /**+ * Groups related actions from same LLM response. This helps in tracking+ * and managing results of parallel function calling from the same LLM+ * response.+ */+ llm_response_id: EventID;++ /**+ * The LLM's assessment of the safety risk of this action+ */+ security_risk: SecurityRisk;+}diff --git a/frontend/src/types/v1/core/events/condensation-event.ts b/frontend/src/types/v1/core/events/condensation-event.tsnew file mode 100644index 0000000000..3cad34435d--- /dev/null+++ b/frontend/src/types/v1/core/events/condensation-event.ts@@ -0,0 +1,46 @@+import { EventID } from "../base/common";+import { BaseEvent } from "../base/event";++// Condensation event - indicates conversation history condensation is happening+export interface CondensationEvent extends BaseEvent {+ /**+ * The source is always "environment" for condensation events+ */+ source: "environment";++ /**+ * The IDs of the events that are being forgotten (removed from the View given to the LLM)+ */+ forgotten_event_ids: EventID[];++ /**+ * An optional summary of the events being forgotten+ */+ summary?: string;++ /**+ * An optional offset to the start of the resulting view indicating where the summary should be inserted+ */+ summary_offset?: number;+}++// Condensation request event - used to request a condensation of conversation history+export interface CondensationRequestEvent extends BaseEvent {+ /**+ * The source is always "environment" for condensation request events+ */+ source: "environment";+}++// Condensation summary event - represents a summary generated by a condenser+export interface CondensationSummaryEvent extends BaseEvent {+ /**+ * The source is always "environment" for condensation summary events+ */+ source: "environment";++ /**+ * The summary text+ */+ summary: string;+}diff --git a/frontend/src/types/v1/core/events/conversation-state-event.ts b/frontend/src/types/v1/core/events/conversation-state-event.tsnew file mode 100644index 0000000000..9e52cbc633--- /dev/null+++ b/frontend/src/types/v1/core/events/conversation-state-event.ts@@ -0,0 +1,22 @@+import { BaseEvent } from "../base/event";++// Conversation state update event - contains conversation state updates+export interface ConversationStateUpdateEvent extends BaseEvent {+ /**+ * The source is always "environment" for conversation state update events+ */+ source: "environment";++ /**+ * Unique key for this state update event.+ * Can be "full_state" for full state snapshots or field names for partial updates.+ */+ key: string;++ /**+ * Serialized conversation state updates.+ * For "full_state" key, this contains the complete conversation state.+ * For field-specific keys, this contains the updated field value.+ */+ value: unknown;+}diff --git a/frontend/src/types/v1/core/events/index.ts b/frontend/src/types/v1/core/events/index.tsnew file mode 100644index 0000000000..e3d3ee6cb4--- /dev/null+++ b/frontend/src/types/v1/core/events/index.ts@@ -0,0 +1,8 @@+// Export all event types+export * from "./action-event";+export * from "./condensation-event";+export * from "./conversation-state-event";+export * from "./message-event";+export * from "./observation-event";+export * from "./pause-event";+export * from "./system-event";diff --git a/frontend/src/types/v1/core/events/message-event.ts b/frontend/src/types/v1/core/events/message-event.tsnew file mode 100644index 0000000000..be89631645--- /dev/null+++ b/frontend/src/types/v1/core/events/message-event.ts@@ -0,0 +1,19 @@+import { TextContent } from "../base/common";+import { BaseEvent, Message } from "../base/event";++export interface MessageEvent extends BaseEvent {+ /**+ * The exact LLM message for this message event+ */+ llm_message: Message;++ /**+ * List of activated microagent names+ */+ activated_microagents: string[];++ /**+ * List of content added by agent context+ */+ extended_content: TextContent[];+}diff --git a/frontend/src/types/v1/core/events/observation-event.ts b/frontend/src/types/v1/core/events/observation-event.tsnew file mode 100644index 0000000000..011108372e--- /dev/null+++ b/frontend/src/types/v1/core/events/observation-event.ts@@ -0,0 +1,70 @@+import { EventID, ToolCallID } from "../base/common";+import { BaseEvent } from "../base/event";+import { Observation } from "../base/observation";++// Base interface for observation events+export interface ObservationBaseEvent extends BaseEvent {+ /**+ * The source is always "environment" for observation events+ */+ source: "environment";++ /**+ * The tool name that this observation is responding to+ */+ tool_name: string;++ /**+ * The tool call id that this observation is responding to+ */+ tool_call_id: ToolCallID;+}++// Main observation event interface+export interface ObservationEvent extends ObservationBaseEvent {+ /**+ * The observation (tool call) sent to LLM+ */+ observation: Observation;++ /**+ * The action id that this observation is responding to+ */+ action_id: EventID;+}++// User rejection observation event+export interface UserRejectObservation extends ObservationBaseEvent {+ /**+ * Reason for rejecting the action+ */+ rejection_reason: string;++ /**+ * The action id that this observation is responding to+ */+ action_id: EventID;+}++// Agent error event+export interface AgentErrorEvent extends BaseEvent {+ /**+ * The source is always "agent" for agent error events+ */+ source: "agent";++ /**+ * The tool name that this observation is responding to+ */+ tool_name: string;++ /**+ * The tool call id that this observation is responding to+ */+ tool_call_id: ToolCallID;++ /**+ * The error message from the scaffold+ */+ error: string;+}diff --git a/frontend/src/types/v1/core/events/pause-event.ts b/frontend/src/types/v1/core/events/pause-event.tsnew file mode 100644index 0000000000..487ee60ce3--- /dev/null+++ b/frontend/src/types/v1/core/events/pause-event.ts@@ -0,0 +1,9 @@+import { BaseEvent } from "../base/event";++// Pause event - indicates that agent execution was paused by user request+export interface PauseEvent extends BaseEvent {+ /**+ * The source is always "user" for pause events+ */+ source: "user";+}diff --git a/frontend/src/types/v1/core/events/system-event.ts b/frontend/src/types/v1/core/events/system-event.tsnew file mode 100644index 0000000000..a4a7953281--- /dev/null+++ b/frontend/src/types/v1/core/events/system-event.ts@@ -0,0 +1,20 @@+import { TextContent } from "../base/common";+import { BaseEvent, ChatCompletionToolParam } from "../base/event";++// System prompt event interface+export interface SystemPromptEvent extends BaseEvent {+ /**+ * The source is always "agent" for system prompt events+ */+ source: "agent";++ /**+ * The system prompt text+ */+ system_prompt: TextContent;++ /**+ * List of tools in OpenAI tool format+ */+ tools: ChatCompletionToolParam[];+}diff --git a/frontend/src/types/v1/core/index.ts b/frontend/src/types/v1/core/index.tsnew file mode 100644index 0000000000..569d5e1cc1--- /dev/null+++ b/frontend/src/types/v1/core/index.ts@@ -0,0 +1,10 @@+// Export all core types++// Base types (primitive types like Action, Observation, common interfaces)+export * from "./base";++// Event types (main events that extend BaseEvent)+export * from "./events";++// Union type for all OpenHands events+export * from "./openhands-event";diff --git a/frontend/src/types/v1/core/openhands-event.ts b/frontend/src/types/v1/core/openhands-event.tsnew file mode 100644index 0000000000..909f5221c0--- /dev/null+++ b/frontend/src/types/v1/core/openhands-event.ts@@ -0,0 +1,34 @@+// Import all event types+import {+ ActionEvent,+ MessageEvent,+ ObservationEvent,+ UserRejectObservation,+ AgentErrorEvent,+ SystemPromptEvent,+ CondensationEvent,+ CondensationRequestEvent,+ CondensationSummaryEvent,+ ConversationStateUpdateEvent,+ PauseEvent,+} from "./events/index";++/**+ * Union type representing all possible OpenHands events.+ * This includes all main event types that can occur in the system.+ */+export type OpenHandsEvent =+ // Core action and observation events+ | ActionEvent+ | MessageEvent+ | ObservationEvent+ | UserRejectObservation+ | AgentErrorEvent+ | SystemPromptEvent+ // Conversation management events+ | CondensationEvent+ | CondensationRequestEvent+ | CondensationSummaryEvent+ | ConversationStateUpdateEvent+ // Control events+ | PauseEvent;