Skip to content

Commit 2bfb2ba

Browse files
fix: Convert initial_message from string to Message object format
- Update CreateConversationRequest interface to use Message type instead of string - Convert string initialMessage to proper Message object in RemoteConversation.create - Add Message import to conversation models - Fixes 422 error when creating conversations with initial messages Co-authored-by: openhands <openhands@all-hands.dev>
1 parent 3228a8e commit 2bfb2ba

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/conversation/remote-conversation.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,18 @@ export class RemoteConversation {
204204
timeout: 60000,
205205
});
206206

207+
// Convert string initialMessage to Message object if provided
208+
let initialMessage: Message | undefined;
209+
if (options.initialMessage) {
210+
initialMessage = {
211+
role: 'user',
212+
content: [{ type: 'text', text: options.initialMessage }],
213+
};
214+
}
215+
207216
const request: CreateConversationRequest = {
208217
agent,
209-
initial_message: options.initialMessage,
218+
initial_message: initialMessage,
210219
max_iterations: options.maxIterations || 50,
211220
stuck_detection: options.stuckDetection ?? true,
212221
workspace: options.workspace || { type: 'local', working_dir: '/tmp' },

src/models/conversation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ConfirmationPolicyBase,
1010
ConversationStats,
1111
AgentBase,
12+
Message,
1213
} from '../types/base';
1314

1415
export interface ConversationInfo {
@@ -40,7 +41,7 @@ export interface ConfirmationResponseRequest {
4041

4142
export interface CreateConversationRequest {
4243
agent: AgentBase;
43-
initial_message?: string;
44+
initial_message?: Message;
4445
max_iterations: number;
4546
stuck_detection: boolean;
4647
workspace: any;

0 commit comments

Comments
 (0)