Skip to content

Commit

Permalink
fix: Add WriteObservation and ReadObservation types and update succes…
Browse files Browse the repository at this point in the history
…s determination logic
  • Loading branch information
openhands-agent committed Dec 9, 2024
1 parent f534cd6 commit 2011f55
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
13 changes: 10 additions & 3 deletions frontend/src/state/chat-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
OpenHandsObservation,
CommandObservation,
IPythonObservation,
WriteObservation,
ReadObservation,
} from "#/types/core/observations";
import { OpenHandsAction } from "#/types/core/actions";
import { OpenHandsEventType } from "#/types/core/base";
Expand Down Expand Up @@ -142,9 +144,14 @@ export const chatSlice = createSlice({
// For IPython, we consider it successful if there's no error message
const ipythonObs = observation.payload as IPythonObservation;
causeMessage.success = !ipythonObs.message.toLowerCase().includes("error");

Check failure on line 146 in frontend/src/state/chat-slice.ts

View workflow job for this annotation

GitHub Actions / Lint frontend

Replace `.toLowerCase()` with `⏎··········.toLowerCase()⏎··········`
} else if (observationID === "write" || observationID === "read") {
// For file operations, we consider them successful if there's no error message
causeMessage.success = !observation.payload.message.toLowerCase().includes("error");
} else if (observationID === "write") {
// For write operations, we consider them successful if there's no error message
const writeObs = observation.payload as WriteObservation;
causeMessage.success = !writeObs.message.toLowerCase().includes("error");

Check failure on line 150 in frontend/src/state/chat-slice.ts

View workflow job for this annotation

GitHub Actions / Lint frontend

Replace `.toLowerCase()` with `⏎··········.toLowerCase()⏎··········`
} else if (observationID === "read") {
// For read operations, we consider them successful if there's no error message
const readObs = observation.payload as ReadObservation;
causeMessage.success = !readObs.message.toLowerCase().includes("error");
}

if (observationID === "run" || observationID === "run_ipython") {
Expand Down
17 changes: 17 additions & 0 deletions frontend/src/types/core/observations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ export interface BrowseObservation extends OpenHandsObservationEvent<"browse"> {
};
}

export interface WriteObservation extends OpenHandsObservationEvent<"write"> {
source: "agent";
extras: {
path: string;
content: string;
};
}

export interface ReadObservation extends OpenHandsObservationEvent<"read"> {
source: "agent";
extras: {
path: string;
};
}

export interface ErrorObservation extends OpenHandsObservationEvent<"error"> {
source: "user";
extras: {
Expand All @@ -65,4 +80,6 @@ export type OpenHandsObservation =
| IPythonObservation
| DelegateObservation
| BrowseObservation
| WriteObservation
| ReadObservation
| ErrorObservation;

0 comments on commit 2011f55

Please sign in to comment.