sourcegraph / cody

Type less, code more: Cody is an AI code assistant that uses advanced search and codebase context to help you write and fix code.
https://cody.dev
Apache License 2.0
2.6k stars 278 forks source link

Agent: add support for clients to receive webview messages as strings #4583

Closed olafurpg closed 3 months ago

olafurpg commented 3 months ago

Previously, agent clients could only receive webview messages as structured JSON objects. This is unnecessarily complicated for clients that don't process the messages, they only forward them to an underlying webview (and treat the webview protocol as an implementation detail).

With this PR, clients can specify that they wish to receive webview messages as strings (JSON-encoded). This change greatly simplifies the the necessary steps to get basic chat working inside a webview (like for the Eclipse plugin).

Fixes CODY-2399 Fixes CODY-2412

Test plan

Manually tested with the Eclipse plugin.

olafurpg commented 3 months ago

Logs from a local run

[Trace - 03:40:46 PM] Sending request 'webview/receiveMessageString - (3)'
Params: {
  "id": "dc6e1cd7-e209-4978-8c1c-007df1a82225",
  "messageStringEncoded": "{\"command\":\"ready\"}"
}
...
[Trace - 03:41:03 PM] Received notification 'webview/postMessageString'
Params: {
  "id": "dc6e1cd7-e209-4978-8c1c-007df1a82225",
  "stringEncodedMessage": "{\"type\":\"transcript\",\"messages\":[{\"text\":\"Hello\",\"editorState\":{\"v\":\"lexical-v0\",\"minReaderV\":\"lexical-v0\",\"lexicalEditorState\":{\"root\":{\"children\":[{\"children\":[{\"detail\":0,\"format\":0,\"mode\":\"normal\",\"style\":\"\",\"text\":\"Hello\",\"type\":\"text\",\"version\":1}],\"direction\":\"ltr\",\"format\":\"\",\"indent\":0,\"type\":\"paragraph\",\"version\":1,\"textFormat\":0}],\"direction\":\"ltr\",\"format\":\"\",\"indent\":0,\"type\":\"root\",\"version\":1}}},\"speaker\":\"human\",\"contextFiles\":[]},{\"speaker\":\"assistant\",\"text\":\"Hello! I\u0027m Claude, an AI assis\",\"model\":\"anthropic/claude-3-sonnet-20240229\"}],\"isMessageInProgress\":true,\"chatID\":\"Mon, 17 Jun 2024 13:40:44 GMT\"}"
}