Skip to content

Commit 5468afe

Browse files
committed
fix: simplify buildUserMessageContent function logic avoid backend
repeating npm-app's work 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent 4125dec commit 5468afe

File tree

1 file changed

+10
-29
lines changed

1 file changed

+10
-29
lines changed

backend/src/run-agent-step.ts

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -58,39 +58,20 @@ function buildUserMessageContent(
5858
params: Record<string, any> | undefined,
5959
content?: Array<TextPart | ImagePart>,
6060
): string | Array<TextPart | ImagePart> {
61+
// If we have content, return it as-is (client should have already combined prompt + content)
62+
if (content && content.length > 0) {
63+
if (content.length === 1 && content[0].type === 'text') {
64+
return asUserMessage(content[0].text)
65+
}
66+
return content
67+
}
68+
69+
// Only prompt/params, combine and return as simple text
6170
const textParts = buildArray([
6271
prompt,
6372
params && JSON.stringify(params, null, 2),
6473
])
65-
const combinedText = textParts.join('\n\n')
66-
67-
if (!content || content.length === 0) {
68-
// Only prompt/params, return as simple text
69-
return asUserMessage(combinedText)
70-
}
71-
72-
// If we have both content and prompt/params, combine them
73-
const allParts = [...content]
74-
75-
// Find the first text part and prepend our combined text, or add it as a new text part
76-
const firstTextPartIndex = allParts.findIndex((part) => part.type === 'text')
77-
if (firstTextPartIndex !== -1) {
78-
// Prepend to existing text part
79-
const textPart = allParts[firstTextPartIndex]
80-
if (textPart.type === 'text') {
81-
allParts[firstTextPartIndex] = {
82-
type: 'text' as const,
83-
text: buildArray([combinedText, textPart.text]).join('\n\n'),
84-
}
85-
}
86-
} else {
87-
// Add as new text part at the beginning
88-
allParts.unshift({ type: 'text' as const, text: combinedText })
89-
}
90-
91-
return allParts.length === 1 && allParts[0].type === 'text'
92-
? asUserMessage(allParts[0].text)
93-
: allParts
74+
return asUserMessage(textParts.join('\n\n'))
9475
}
9576

9677
export interface AgentOptions {

0 commit comments

Comments
 (0)