fix(acp): parse session/update content as ContentBlock, not string
The ACP spec defines session/update content as a ContentBlock object
({type, text}) but we decoded it as a string. This dropped every
agent_message_chunk and left prompt responses empty. E2E against the
real opencode acp binary surfaced the bug.
- internal/acp/messages.go: add ContentBlock struct; Update.Content is
now ContentBlock.
- internal/acp/client.go: handleNotification extracts Text when
Content.Type == "text"; other types are logged at debug and dropped.
- internal/acp/client_test.go: NDJSON framing test sends content as a
ContentBlock object and reads .Text.
- README.md: document /acp/* routes + CODESPACE_OPENCODE_ARGS env.
Verified end-to-end: POST /acp/prompt returns text="Hi there!", 4
messages in history (1 user + 3 agent chunks), 0 invalid session/update
log entries.
Conversation: 019f357d-4236-7010-949c-e61067618d42
This commit is contained in:
+10
-2
@@ -237,9 +237,17 @@ func (c *Client) handleNotification(method string, params json.RawMessage) {
|
||||
}
|
||||
switch up.Update.SessionUpdate {
|
||||
case "agent_message_chunk":
|
||||
c.history.Add("agent", up.Update.Content)
|
||||
if up.Update.Content.Type == "text" {
|
||||
c.history.Add("agent", up.Update.Content.Text)
|
||||
} else {
|
||||
c.lg.Debug("acp drop non-text agent chunk", "workspace_id", c.workspaceID, "type", up.Update.Content.Type)
|
||||
}
|
||||
case "user_message_chunk":
|
||||
c.history.Add("user", up.Update.Content)
|
||||
if up.Update.Content.Type == "text" {
|
||||
c.history.Add("user", up.Update.Content.Text)
|
||||
} else {
|
||||
c.lg.Debug("acp drop non-text user chunk", "workspace_id", c.workspaceID, "type", up.Update.Content.Type)
|
||||
}
|
||||
default:
|
||||
c.lg.Debug("acp drop update", "workspace_id", c.workspaceID, "type", up.Update.SessionUpdate)
|
||||
}
|
||||
|
||||
@@ -115,11 +115,11 @@ func TestNDJSONFramingHandlesSplitLines(t *testing.T) {
|
||||
got <- struct {
|
||||
method string
|
||||
content string
|
||||
}{method, up.Update.Content}
|
||||
}{method, up.Update.Content.Text}
|
||||
}
|
||||
|
||||
line1 := `{"jsonrpc":"2.0","method":"session/update","params":{"sessionId":"s1","update":{"sessionUpdate":"agent_message_chunk","content":"hello"}}}`
|
||||
line2 := `{"jsonrpc":"2.0","method":"session/update","params":{"sessionId":"s1","update":{"sessionUpdate":"agent_message_chunk","content":" world"}}}`
|
||||
line1 := `{"jsonrpc":"2.0","method":"session/update","params":{"sessionId":"s1","update":{"sessionUpdate":"agent_message_chunk","content":{"type":"text","text":"hello"}}}}`
|
||||
line2 := `{"jsonrpc":"2.0","method":"session/update","params":{"sessionId":"s1","update":{"sessionUpdate":"agent_message_chunk","content":{"type":"text","text":" world"}}}}`
|
||||
|
||||
// Send one complete line plus a partial second line.
|
||||
sub.send([]byte(line1 + "\n" + line2[:len(line2)-2]))
|
||||
|
||||
@@ -93,10 +93,16 @@ type SessionUpdateParams struct {
|
||||
type Update struct {
|
||||
SessionUpdate string `json:"sessionUpdate"`
|
||||
MessageID string `json:"messageId,omitempty"`
|
||||
Content string `json:"content,omitempty"`
|
||||
Content ContentBlock `json:"content,omitempty"`
|
||||
ToolCallID string `json:"toolCallId,omitempty"`
|
||||
}
|
||||
|
||||
// ContentBlock is a content payload in session/update notifications.
|
||||
type ContentBlock struct {
|
||||
Type string `json:"type"`
|
||||
Text string `json:"text,omitempty"`
|
||||
}
|
||||
|
||||
// FSReadParams is sent by the agent to read a workspace file.
|
||||
type FSReadParams struct {
|
||||
Path string `json:"path"`
|
||||
|
||||
Reference in New Issue
Block a user