Replace base64-in-JSON file transfers with binary WebSocket frames to
unblock the JS thread when assistant markdown messages contain images.
Receive cost (JSON.parse over multi-MB base64) and persist cost (base64
re-encode to disk) both removed.
- Split daemon-client `exploreFileSystem` into `listDirectory` + `readFile`;
`readFile` returns `{ bytes, mime, size, modifiedAt }`. Encoding stays
private to the seam.
- New `packages/server/src/shared/binary-frames/` module hosts terminal
frames (moved from `terminal-stream-protocol.ts`) and new file-transfer
opcodes (`FileBegin` / `FileChunk` / `FileEnd`) with request-id correlation.
- Add optional `acceptBinary` to `FileExplorerRequestSchema`. New daemons
emit binary frames when set; legacy JSON path remains for old clients.
Compat fallback lives only inside `readFile`.
- New `persistAttachmentFromBytes` writes bytes directly: native via
`expo-file-system` `File.write(Uint8Array)`, web via Blob -> IndexedDB,
desktop via new `write_attachment_bytes` IPC. `persistAttachmentFromBase64`
removed.
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import * as terminalBinaryFrames from "./binary-frames/index.js";
|
|
import * as legacyTerminalStreamProtocol from "./terminal-stream-protocol.js";
|
|
|
|
describe("terminal stream protocol", () => {
|
|
it("keeps the old import path compatible with terminal binary frames", () => {
|
|
expect(legacyTerminalStreamProtocol.TerminalStreamOpcode).toBe(
|
|
terminalBinaryFrames.TerminalStreamOpcode,
|
|
);
|
|
expect(legacyTerminalStreamProtocol.encodeTerminalStreamFrame).toBe(
|
|
terminalBinaryFrames.encodeTerminalStreamFrame,
|
|
);
|
|
expect(legacyTerminalStreamProtocol.decodeTerminalStreamFrame).toBe(
|
|
terminalBinaryFrames.decodeTerminalStreamFrame,
|
|
);
|
|
|
|
const payload = new TextEncoder().encode("hello");
|
|
const encoded = legacyTerminalStreamProtocol.encodeTerminalStreamFrame({
|
|
opcode: legacyTerminalStreamProtocol.TerminalStreamOpcode.Output,
|
|
slot: 7,
|
|
payload,
|
|
});
|
|
|
|
expect(encoded[0]).toBe(terminalBinaryFrames.TerminalStreamOpcode.Output);
|
|
expect(encoded[1]).toBe(7);
|
|
expect(Array.from(encoded.subarray(2))).toEqual(Array.from(payload));
|
|
|
|
const decoded = terminalBinaryFrames.decodeTerminalStreamFrame(encoded);
|
|
expect(decoded).toEqual({
|
|
opcode: legacyTerminalStreamProtocol.TerminalStreamOpcode.Output,
|
|
slot: 7,
|
|
payload,
|
|
});
|
|
});
|
|
});
|