All communication consists of messages that are one line of human-readable UTF-8 text (with no terminating newline), optionally followed by a single newline and arbitrary (potentially even binary) data. The WebSocket distinction between 'text' and 'binary' frames has no meaning for us for messages that don't contain additional binary data; such messages can be either 'binary' or 'text' from the WebSocket point of view even if we require them (the single line) to be UTF-8. In other words, an implementation is free to send such a single-line message as a WebSocket 'binary' frame, and the receiving implementation must treat that equally as if it was a 'text' frame. The WebSocket protocol says that 'text' frames are to be "interpreted" as UTF-8, so it is probably best to indeed use 'binary' frames for messages that contain optional non-UTF-8 data. The protocol is not a request-response one. Messages may be sent in either direction at any time, either in response to some message, or spontaneously. For 'tile' messages, the client may send a bunch of tile requests without waiting for return messages. The server may send tiles proactively (guessing what the client might need). Etc. The original intent was that the parameters of the messages can be in any order, as they are in a name=value form anyway and the name indicates which parameter is which. Sadly, this was not explicitly mentioned in this document, or tested by unit tests. So now we have code here and there that assumes that parameters are in a specific order anyway, thus losing the benefits of the named parameters. Oh well. When the document is password protected, it already implies that the document didn't load, and that with the proper password we should try again. Similarly for when the password given is wrong. However, if loading fails and it isn't a password-related failure, faileddocloading error is returned and in this case the client handles it as a final error (that requires reloading to retry). client -> server ================ A convention: Messages that have the first token (keyword) in UPPERCASE are related to debugging and tracing of the client and server software and not related to the user's actions. DEBUG The rest of the message (without the DEBUG keyword), possibly multiple lines, is logged by the server as LOG_DBG. ERROR The rest of the message (without the ERROR keyword), possibly multiple lines, is logged by the server as LOG_ERR. TRACEEVENT name= ph= ts= ... [ args= ] Timestamps and durations are in microseconds, from performance.now(), multiplied by 1000, and rouded to an integer. name is a string of non-space characters. ts is the timestamp when the trace event was generated. ph is one of the following, and the rest of the parameters depend on what it is. 'i': An "Instant" event. 'S', 'F': The start and finish of an "Async" event. In addition to the name, the messages have an "id" parameter, a unique number that must be the same for the 'S' and 'F' messages. 'X': A "complete" event. The "dur" parameter is the duration between the beginning of the thing being timed and the time when the 'X' message was emitted, also in microseconds. args is an optional parameter, and its value is a JSON string where the keys and values are strings with no spaces in them. tileprocessed wids= Previously sent tile (server -> client) arrived and processed by the client. We send a list of wire-ids back for tiles that have been received. downloadas name= id= format= options= Exports the current document to the desired format and returns a download URL The id identifies the request on the client. id can take following values: * 'print': When request for download is basically for print purposes * 'slideshow': When request for download is for showing slideshow * 'export': Just a simple download remotedocsubscribe source= remotedocunsubscribe source= Subscribes the sending view to, or unsubscribes it from, live events about the remote document bound to the given persistent link. A view names a remote document by its persistent link alone, and the address the server reaches it at stays with the server. The subscription belongs to that one view and is opened with that view's own access token for the remote document; the token comes from that view's UserPrivateInfo in CheckFileInfo, or from a POST to /cool/links. A view without a token for the source is refused, and so is a persistent link no remote link is bound to. A remotelinkremove of the persistent link drops the document for every view, and the subscriptions to it go down with it. A view holds at most one subscription per source. The command is handled inside wsd and never given to this document's kit. Requires the remote_links feature to be enabled. remotelinkresolve source= Asks this view's storage for the document behind one of the persistent links the open document's pages record, over a POST to /linkaccess. A view asks for the sources it finds on the document once, when it joins; afterwards, and for the sources later editing names, this command is the only thing that asks, so a user who sees a source reported as missing can have it looked for again. Requires the remote_links feature and SupportsLinkAccess. remotelinkremove source= Drops the remote link bound to the given persistent link from the list of this document, for every view. The subscriptions to it go down with it, and the fresh list goes out to all views. The link is named by its persistent link, the value the document's pages store, and not by the address the storage resolved it to. Answered with an error of kind 'notfound' when no remote link is bound to it. Requires the remote_links feature to be enabled. remotedoccommand source= Routes a read-only client command to the remote document the current document is subscribed to, bound to the given persistent link. The inner command is an ordinary client command line, for example "getslidesections" or "tilecombine ...". The command is handled inside wsd and sent to the remote over the headless session; it is never given to this document's kit. Only non-modifying commands are accepted. The remote's replies come back as remotedoccommandresult: messages. Requires a live subscription to the source. getchildid Requests the child id so that it knows where the files needs to be sent when it is inserted in the document gettextselection mimetype= Request selection's content, which is returned via 'textselectioncontent', if the selection is text-only and relatively small. However, for selections containing images and other embedded objects, or if the selection is a large text blob, the response is 'complexselection'. paste mimetype= Paste content at the current cursor position. aichat: Send chat messages to the AI assistant. The JSON payload contains: - messages: Array of chat messages in OpenAI format [{role, content}, ...] - requestId: Unique identifier for matching the response The server proxies the request to the configured AI provider and returns the result via 'aichatresult' message. If the AI provider returns an image, the result will contain imageData instead of content. aichatcancel: Cancel an in-progress AI chat request. is the identifier from the original 'aichat' message. executescript