chat: deliver attachments and cancel runs immediately
Carry browser files as base64 prompt attachments, write them to private temporary files and pass file:// references to OpenCode, and map the user turn's top-level files back into history. Replay a running step on subscribe, forward only a caller-supplied msg_ id, and persist cancel on the run and live step before interrupting the runner.
This commit is contained in:
@@ -433,13 +433,12 @@ export class PipelinesRepository {
|
||||
* prompt behind an in-flight turn (`chat_queued` on the reply), which is the
|
||||
* one signal the composer's queued notice is derived from.
|
||||
*
|
||||
* Note: the server's prompt path (`internal/server/chat_stream.go`) consumes
|
||||
* only `text` today — `files` is accepted on the wire but not yet forwarded to
|
||||
* OpenCode, so a browser attachment is collected, validated and made to block a
|
||||
* failed send, then sent best-effort as the file's own reference string. The
|
||||
* attachment is not yet delivered to the agent; the row note records that.
|
||||
* Browser attachments travel in `attachments` as {name,mime,data} with data
|
||||
* encoded as standard base64. The server writes them to private temporary
|
||||
* files and hands those file:// references to OpenCode; `files` remains the
|
||||
* legacy reference-only field for older clients.
|
||||
*/
|
||||
async chatPrompt(sessionId, text, files = [], operationId = newChatOperationId()) {
|
||||
async chatPrompt(sessionId, text, files = [], operationId = newChatOperationId(), attachments = []) {
|
||||
if (!String(sessionId ?? "").trim()) {
|
||||
throw new ProtocolError("Select a chat session first.");
|
||||
}
|
||||
@@ -454,6 +453,7 @@ export class PipelinesRepository {
|
||||
native_message_id: nativeChatMessageId(operationId),
|
||||
};
|
||||
if (files.length > 0) body.files = files;
|
||||
if (attachments.length > 0) body.attachments = attachments;
|
||||
const response = await this.#client.call({ type: Protocol.CHAT_PROMPT, [ChatKeys.PROMPT]: body });
|
||||
return Boolean(response[ChatKeys.QUEUED]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user