Skip to content

An open-source, self-hosted system for apps built with web technologies.

Use MessagePack across endpoint transports

zohayrslileha8f13e76b784
diff --git a/bun.lock b/bun.lock
index 42fc99a..7ba16a5 100644
--- a/bun.lock
+++ b/bun.lock
@@ -7,6 +7,7 @@
"dependencies": {
"@fontsource/roboto": "^5.3.0",
"@hono/node-server": "^2.1.1",
+ "@msgpack/msgpack": "^3.1.3",
"cfonts": "^3.3.1",
"get-port": "^7.2.0",
"gsap": "^3.15.0",
@@ -16,7 +17,6 @@
"react": "^19.2.8",
"react-dom": "^19.2.8",
"sharp": "^0.35.3",
- "superjson": "^2.2.6",
"uuid": "^14.0.1",
"ws": "^8.21.3",
"zod": "^4.4.3",
@@ -224,6 +224,8 @@
"@keyv/serialize": ["@keyv/[email protected]", "", {}, "sha512-dXn3FZhPv0US+7dtJsIi2R+c7qWYiReoEh5zUntWCf4oSpMNib8FDhSoed6m3QyZdx5hK7iLFkYk3rNxwt8vTA=="],
+ "@msgpack/msgpack": ["@msgpack/[email protected]", "", {}, "sha512-47XIizs9XZXvuJgoaJUIE2lFoID8ugvc0jzSHP+Ptfk8nTbnR8g788wv48N03Kx0UkAv559HWRQ3yzOgzlRNUA=="],
+
"@noble/hashes": ["@noble/[email protected]", "", {}, "sha512-oN+QwyX7VSHotibwubG3kpzbwKrfnyR6OOO+3Nk/53ADL7FmgHHz4TgrbaYKvvOw09u6QTx0oiH1cNCIOuN0CQ=="],
"@oxc-project/types": ["@oxc-project/[email protected]", "", {}, "sha512-nuhZIOLuI6TFQ32I/WnUx+SCPY7SdSKwgnFHydAuoS1+Z4BRcaP+RRJmGzl9lw+0OFF7UmaESf7KQRXaNLHypg=="],
@@ -332,8 +334,6 @@
"convert-source-map": ["[email protected]", "", {}, "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg=="],
- "copy-anything": ["[email protected]", "", { "dependencies": { "is-what": "^5.2.0" } }, "sha512-7Vv6asjS4gMOuILabD3l739tsaxFQmC+a7pLZm02zyvs8p977bL3zEgq3yDk5rn9B0PbYgIv++jmHcuUab4RhA=="],
-
"csstype": ["[email protected]", "", {}, "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ=="],
"debug": ["[email protected]", "", { "dependencies": { "ms": "^2.1.3" }, "peerDependencies": { "supports-color": "*" }, "optionalPeers": ["supports-color"] }, "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA=="],
@@ -382,8 +382,6 @@
"is-number": ["[email protected]", "", { "dependencies": { "kind-of": "^3.0.2" } }, "sha512-4cboCqIpliH+mAvFNegjZQ4kgKc3ZUhQVr3HvWbSh5q3WH2v82ct+T2Y1hdU5Gdtorx/cLifQjqCbL7bpznLTg=="],
- "is-what": ["[email protected]", "", {}, "sha512-oG7cgbmg5kLYae2N5IVd3jm2s+vldjxJzK1pcu9LfpGuQ93MQSzo0okvRna+7y5ifrD+20FE8FvjusyGaz14fw=="],
-
"jiti": ["[email protected]", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ=="],
"js-tokens": ["[email protected]", "", {}, "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="],
@@ -462,8 +460,6 @@
"source-map-js": ["[email protected]", "", {}, "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA=="],
- "superjson": ["[email protected]", "", { "dependencies": { "copy-anything": "^4" } }, "sha512-H+ue8Zo4vJmV2nRjpx86P35lzwDT3nItnIsocgumgr0hHMQ+ZGq5vrERg9kJBo5AWGmxZDhzDo+WVIJqkB0cGA=="],
-
"supports-color": ["[email protected]", "", { "dependencies": { "has-flag": "^4.0.0" } }, "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q=="],
"tailwindcss": ["[email protected]", "", {}, "sha512-gOhV3P7ufE62QDGg1zVaTgCR+EtPv92k2nIhVcVKcLmxT1sUBsQGhnZj175j+MqRt4zLF7ic+sCYjfhxMxj7YQ=="],
diff --git a/package.json b/package.json
index 7a30bd6..3480f42 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "phreshos",
"displayName": "PhreshOS",
- "version": "0.1.13",
+ "version": "0.1.14",
"description": "The PhreshOS server, desktop, and authoritative system runtime.",
"type": "module",
"private": true,
@@ -37,6 +37,7 @@
"dependencies": {
"@fontsource/roboto": "^5.3.0",
"@hono/node-server": "^2.1.1",
+ "@msgpack/msgpack": "^3.1.3",
"cfonts": "^3.3.1",
"get-port": "^7.2.0",
"gsap": "^3.15.0",
@@ -46,7 +47,6 @@
"react": "^19.2.8",
"react-dom": "^19.2.8",
"sharp": "^0.35.3",
- "superjson": "^2.2.6",
"uuid": "^14.0.1",
"ws": "^8.21.3",
"zod": "^4.4.3"
diff --git a/source/client/core/application.ts b/source/client/core/application.ts
index 7a52ce9..cf4668e 100644
--- a/source/client/core/application.ts
+++ b/source/client/core/application.ts
@@ -2,7 +2,7 @@ import ClientLink from "@libs/the-link/plugins/client-link/client-link"
import { type ProxyOutcome, type ProxyRequest, type ProxyResponse, proxyMediaType } from "@server/core/protocol/proxy"
import { storageMediaType, type StorageRequest } from "@server/core/protocol/storage"
import { frame, frameBlob, unframe } from "@libs/framing"
-import superjson from "@libs/superjson"
+import messagepack from "@libs/messagepack"
export default class Application {
@@ -28,9 +28,9 @@ export default class Application {
this.clientLink = new ClientLink(this.doors.link)
- this.clientLink.setSerialize(data => superjson.stringify(data))
+ this.clientLink.setSerialize(messagepack.serialize)
- this.clientLink.setDeserialize(data => superjson.parse(data))
+ this.clientLink.setDeserialize(messagepack.deserialize)
}
// A finite browser body keeps its length, so HTTP/1 can stream it from its
diff --git a/source/client/view/desktop/client-host/client-host.ts b/source/client/view/desktop/client-host/client-host.ts
index 776dcf5..152bb67 100644
--- a/source/client/view/desktop/client-host/client-host.ts
+++ b/source/client/view/desktop/client-host/client-host.ts
@@ -8,6 +8,7 @@ import ClientTraffic from "./client-traffic"
import { type RefObject, useCallback, useEffect, useLayoutEffect, useRef, useState } from "react"
import { AuthManagerContext } from "../../contexts"
import { type LocalWindowHost } from "./local-window"
+import messagepack from "@libs/messagepack"
/**
* The browser boundary between a program pane and the desktop that hosts it.
@@ -290,7 +291,19 @@ export default function useClientHost(desktop: RefObject<HTMLDivElement | null>,
if (source?.contentWindow !== event.source) continue
- boundary.receive(event.data)
+ const [bytes, ...attachments] = event.data as unknown[]
+
+ if (!(bytes instanceof Uint8Array)) return
+
+ let message: unknown
+
+ try { message = messagepack.deserialize(bytes, attachments) }
+
+ catch { return }
+
+ if (!Array.isArray(message)) return
+
+ boundary.receive(message)
return
}
diff --git a/source/client/view/desktop/client-host/client-process-boundary.ts b/source/client/view/desktop/client-host/client-process-boundary.ts
index 3298f7e..8f9d78a 100644
--- a/source/client/view/desktop/client-host/client-process-boundary.ts
+++ b/source/client/view/desktop/client-host/client-process-boundary.ts
@@ -7,6 +7,7 @@ import { failed, succeeded } from "@server/core/outcome"
import { type TrafficKind } from "@server/core/link-manager/auth-manager/process-manager/process-traffic"
import { isPermissionName, type PermissionName } from "@phreshos/core"
import { type LocalWindowHost } from "./local-window"
+import messagepack from "@libs/messagepack"
/** The desktop boundary around one iframe execution endpoint. */
export default class ClientProcessBoundary extends TheLink {
@@ -78,7 +79,7 @@ export default class ClientProcessBoundary extends TheLink {
this.$outbound.forwardTo((route, ...values) => {
- this.element.contentWindow?.postMessage([route, ...values], "*")
+ this.send([route, ...values])
})
}
@@ -272,7 +273,20 @@ export default class ClientProcessBoundary extends TheLink {
public post(route: string, values: unknown[], transfer: Transferable[] = []) {
- this.element.contentWindow?.postMessage([route, ...values], "*", transfer)
+ this.send([route, ...values], transfer)
+ }
+
+ private send(message: unknown[], transfer: Transferable[] = []) {
+
+ const target = this.element.contentWindow
+
+ if (!target) return
+
+ const attachments = nativeAttachments(message, transfer)
+
+ const bytes = messagepack.serialize(message, attachments)
+
+ target.postMessage([bytes, ...attachments], "*", [bytes.buffer, ...transfer])
}
public impossible(subscription: string, reason: string) {
@@ -836,6 +850,54 @@ export default class ClientProcessBoundary extends TheLink {
}
}
+const nativeAttachments = (value: unknown, transfer: readonly Transferable[]) => {
+
+ const attachments: object[] = [...transfer]
+
+ const known = new Set<object>(attachments)
+
+ const visit = (entry: unknown) => {
+
+ if (entry === null || typeof entry !== "object" || known.has(entry)) return
+
+ known.add(entry)
+
+ if (entry instanceof Blob) {
+
+ attachments.push(entry)
+
+ return
+ }
+
+ if (entry instanceof Date || entry instanceof RegExp || entry instanceof URL || entry instanceof Error || entry instanceof ArrayBuffer || ArrayBuffer.isView(entry)) return
+
+ if (entry instanceof Map) {
+
+ for (const [key, item] of entry) {
+
+ visit(key)
+
+ visit(item)
+ }
+
+ return
+ }
+
+ if (entry instanceof Set) {
+
+ for (const item of entry) visit(item)
+
+ return
+ }
+
+ for (const item of Array.isArray(entry) ? entry : Object.values(entry)) visit(item)
+ }
+
+ visit(value)
+
+ return attachments
+}
+
function isPointerPosition(value: unknown): value is { x: number, y: number } {
if (!value || typeof value !== "object") return false
diff --git a/source/client/view/desktop/client-host/host.ts b/source/client/view/desktop/client-host/host.ts
index 4da9b58..8ed8cde 100644
--- a/source/client/view/desktop/client-host/host.ts
+++ b/source/client/view/desktop/client-host/host.ts
@@ -49,9 +49,9 @@ export interface DesktopSize {
* A server half is the other thing and deliberately so: it runs
* arbitrary code already, so vocabulary costs it nothing.
*
- * Answers cross to a sandboxed frame by structured clone, which carries
- * no prototypes and refuses functions — so every word answers with plain
- * values built here, never with an instance the desktop holds.
+ * Answers cross to a sandboxed frame inside MessagePack envelopes. Native
+ * browser capabilities travel only as explicit attachments, so every ordinary
+ * word answers with data built here, never with an instance the desktop holds.
*/
export default function host(authManager: AuthManager, pane: string, desktop: () => DesktopSize, frameOwner: () => string | null, pointer: PointerHost, localWindow: LocalWindowHost) {
@@ -130,8 +130,8 @@ export default function host(authManager: AuthManager, pane: string, desktop: ()
// One process record on every road. Nullable values carry the resolved
// shape as data; the SDK turns them into permanent addressed ends whose
- // exists() reads the latest fact. A frame receives structured data,
- // never the desktop's mutable record.
+ // exists() reads the latest fact. A frame receives MessagePack data, never
+ // the desktop's mutable record.
function record(found: ReturnType<typeof process> | NonNullable<ReturnType<typeof process>["parent"]>) {
return sdkProcess(found, owner(found))
diff --git a/source/libs/messagepack.ts b/source/libs/messagepack.ts
new file mode 100644
index 0000000..d5d458d
--- /dev/null
+++ b/source/libs/messagepack.ts
@@ -0,0 +1,231 @@
+import { decode, encode, ExtensionCodec } from "@msgpack/msgpack"
+
+export type Bytes = Uint8Array<ArrayBuffer>
+
+interface Context {
+
+ incoming?: readonly unknown[]
+
+ outgoing?: ReadonlyMap<object, number>
+}
+
+class Attachment {
+
+ public constructor(public readonly index: number) { }
+}
+
+class BigInteger {
+
+ public constructor(public readonly value: bigint) { }
+}
+
+class Undefined { }
+
+const textEncoder = new TextEncoder()
+
+const textDecoder = new TextDecoder("utf-8", { fatal: true })
+
+const extensions = new ExtensionCodec<Context>()
+
+const serializePrepared = (value: unknown, context: Context) => encode(value, { context, extensionCodec: extensions })
+
+const deserializePrepared = (bytes: Uint8Array, context: Context) => decode(bytes, { context, extensionCodec: extensions })
+
+extensions.register({
+
+ type: 0,
+
+ encode: value => value instanceof Attachment ? uint32(value.index) : null,
+
+ decode: (bytes, _type, context) => {
+
+ const attachment = context.incoming?.[readUint32(bytes)]
+
+ if (attachment === undefined) throw new Error("The MessagePack attachment is absent")
+
+ return attachment
+ }
+})
+
+extensions.register({
+
+ type: 1,
+
+ encode: (value, context) => value instanceof Map ? serializePrepared([...value], context) : null,
+
+ decode: (bytes, _type, context) => new Map(deserializePrepared(bytes, context) as [unknown, unknown][])
+})
+
+extensions.register({
+
+ type: 2,
+
+ encode: (value, context) => value instanceof Set ? serializePrepared([...value], context) : null,
+
+ decode: (bytes, _type, context) => new Set(deserializePrepared(bytes, context) as unknown[])
+})
+
+extensions.register({
+
+ type: 3,
+
+ encode: (value, context) => value instanceof RegExp ? serializePrepared([value.source, value.flags, value.lastIndex], context) : null,
+
+ decode: (bytes, _type, context) => {
+
+ const [source, flags, lastIndex] = deserializePrepared(bytes, context) as [string, string, number]
+
+ const expression = new RegExp(source, flags)
+
+ expression.lastIndex = lastIndex
+
+ return expression
+ }
+})
+
+extensions.register({
+
+ type: 4,
+
+ encode: value => value instanceof URL ? textEncoder.encode(value.href) : null,
+
+ decode: bytes => new URL(textDecoder.decode(bytes))
+})
+
+extensions.register({
+
+ type: 5,
+
+ encode: (value, context) => value instanceof Error ? serializePrepared(prepare({
+
+ cause: value.cause,
+
+ message: value.message,
+
+ name: value.name,
+
+ stack: value.stack
+
+ }, context), context) : null,
+
+ decode: (bytes, _type, context) => {
+
+ const value = deserializePrepared(bytes, context) as { cause?: unknown, message: string, name: string, stack?: string }
+
+ const error = new Error(value.message, { cause: value.cause })
+
+ error.name = value.name
+
+ if (value.stack !== undefined) error.stack = value.stack
+
+ return error
+ }
+})
+
+extensions.register({
+
+ type: 6,
+
+ encode: value => value instanceof BigInteger ? textEncoder.encode(value.value.toString()) : null,
+
+ decode: bytes => BigInt(textDecoder.decode(bytes))
+})
+
+extensions.register({
+
+ type: 7,
+
+ encode: value => value instanceof Undefined ? new Uint8Array() : null,
+
+ decode: () => undefined
+})
+
+export const serialize = (value: unknown, attachments: readonly object[] = []): Bytes => {
+
+ const outgoing = new Map(attachments.map((attachment, index) => [attachment, index]))
+
+ const context = { outgoing }
+
+ return serializePrepared(prepare(value, context), context)
+}
+
+export const deserialize = (bytes: Uint8Array, attachments: readonly unknown[] = []) => {
+
+ return deserializePrepared(bytes, { incoming: attachments })
+}
+
+const prepare = (value: unknown, context: Context): unknown => {
+
+ if (value === undefined) return new Undefined()
+
+ if (typeof value === "bigint") return new BigInteger(value)
+
+ if (typeof value === "function" || typeof value === "symbol") return null
+
+ if (value === null || typeof value !== "object") return value
+
+ const attachment = context.outgoing?.get(value)
+
+ if (attachment !== undefined) return new Attachment(attachment)
+
+ if (value instanceof Date || value instanceof RegExp || value instanceof URL || value instanceof Error) return value
+
+ if (value instanceof ArrayBuffer) return new Uint8Array(value)
+
+ if (ArrayBuffer.isView(value)) return Uint8Array.from(new Uint8Array(value.buffer, value.byteOffset, value.byteLength))
+
+ if (value instanceof Map) return new Map([...value].map(([key, entry]) => [prepare(key, context), prepare(entry, context)]))
+
+ if (value instanceof Set) return new Set([...value].map(entry => prepare(entry, context)))
+
+ if (Array.isArray(value)) return value.map(entry => prepare(entry, context))
+
+ if ("toJSON" in value && typeof value.toJSON === "function") return prepare(value.toJSON(), context)
+
+ return Object.fromEntries(Object.entries(value)
+
+ .filter(([, entry]) => typeof entry !== "function")
+
+ .map(([key, entry]) => [key, prepare(entry, context)]))
+}
+
+const uint32 = (value: number) => {
+
+ const bytes = new Uint8Array(4)
+
+ new DataView(bytes.buffer).setUint32(0, value)
+
+ return bytes
+}
+
+const readUint32 = (bytes: Uint8Array) => {
+
+ if (bytes.byteLength !== 4) throw new Error("The MessagePack attachment reference is invalid")
+
+ return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint32(0)
+}
+
+export type Transmitted<T> =
+ T extends Function | symbol
+ ? null
+ : T extends Map<infer K, infer V>
+ ? Map<Transmitted<K>, Transmitted<V>>
+ : T extends Set<infer U>
+ ? Set<Transmitted<U>>
+ : T extends Date | RegExp | URL | Error
+ ? T
+ : T extends ArrayBuffer | ArrayBufferView
+ ? Uint8Array
+ : T extends { toJSON(): infer R }
+ ? Transmitted<R>
+ : T extends readonly [infer U, ...infer V]
+ ? [Transmitted<U>, ...Transmitted<V>]
+ : T extends readonly []
+ ? []
+ : T extends Array<infer U>
+ ? Array<Transmitted<U>>
+ : T extends object
+ ? { [K in keyof T as Extract<T[K], Function> extends never ? K : never]: Transmitted<T[K]> }
+ : T
+
+export default { deserialize, serialize }
diff --git a/source/libs/superjson.ts b/source/libs/superjson.ts
deleted file mode 100644
index f708bce..0000000
--- a/source/libs/superjson.ts
+++ /dev/null
@@ -1,90 +0,0 @@
-import superjson from "superjson"
-
-/**
- * Convert any JavaScript value to a JSON string with type preservation.
- *
- * @param value The value to stringify
- * @returns JSON string with embedded type metadata
- */
-export const stringify = (value: unknown) => superjson.stringify(resolve(value))
-
-/**
- * Resolve toJSON declarations before SuperJSON walks the value. SuperJSON
- * preserves special types only where its own traversal sees them — and its
- * traversal does not descend into toJSON results, so a Map inside one
- * degrades to a plain object. Resolving first makes the runtime honor what
- * the Transmitted type already promises (case 5). Types SuperJSON carries
- * natively are left untouched — Date and URL have toJSON of their own,
- * and calling it would degrade them to strings.
- */
-const resolve = (value: unknown): unknown => {
-
- if (value === null || typeof value !== "object") return value
-
- if (value instanceof Date || value instanceof RegExp || value instanceof URL || value instanceof Error) return value
-
- if (value instanceof Map) return new Map([...value].map(([key, entry]) => [resolve(key), resolve(entry)]))
-
- if (value instanceof Set) return new Set([...value].map(entry => resolve(entry)))
-
- if (Array.isArray(value)) return value.map(entry => resolve(entry))
-
- if ("toJSON" in value && typeof value.toJSON === "function") return resolve(value.toJSON())
-
- return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, resolve(entry)]))
-}
-
-/**
- * Parse a SuperJSON string back to its original JavaScript value.
- *
- * @param value The SuperJSON string to parse
- * @returns The reconstructed value with preserved types
- */
-export const parse = <Value>(value: string) => superjson.parse<Transmitted<Value>>(value)
-
-/**
- * Type representing a value after SuperJSON serialization.
- *
- * Functions are converted to null, special types (Date, Map, Set, etc.) are preserved,
- * and object function properties are removed while maintaining all other properties.
- *
- * @template T The original type before serialization
- */
-export type Transmitted<T> =
- // Case 1: Functions are converted to null
- T extends Function
- ? null
- // Case 2: Maps are preserved, with key and value types recursively serialized
- : T extends Map<infer K, infer V>
- ? Map<Transmitted<K>, Transmitted<V>> // Recurse into key and value types
- // Case 3: Sets are preserved, with value types recursively serialized
- : T extends Set<infer U>
- ? Set<Transmitted<U>> // Recurse into value type
- // Case 4: Special types (Date, RegExp, URL, Error) are preserved as-is
- : T extends Date | RegExp | URL | Error
- ? T
- // Case 5: Objects with toJSON methods use the return type of toJSON, recursively serialized
- : T extends { toJSON(): infer R }
- ? Transmitted<R>
- // Case 6: Non-empty tuples are preserved, with each element recursively serialized
- : T extends readonly [infer U, ...infer V]
- ? [Transmitted<U>, ...Transmitted<V>]
- // Case 7: Empty tuples remain empty
- : T extends readonly []
- ? []
- // Case 8: Arrays are preserved, with element types recursively serialized
- : T extends Array<infer U>
- ? Array<Transmitted<U>>
- // Case 9: Plain objects have function properties removed, and other properties are recursively serialized
- : T extends object
- ? {
- // Filter out keys where the property is a function
- [K in keyof T as Extract<T[K], Function> extends never ? K : never]: Transmitted<T[K]>
- }
- // Case 10: Primitive values (string, number, boolean, etc.) are unchanged
- : T
-
-/**
- * Default export containing all SuperJSON utilities.
- */
-export default { stringify, parse }
\ No newline at end of file
diff --git a/source/libs/the-link/codec.ts b/source/libs/the-link/codec.ts
new file mode 100644
index 0000000..4f559d7
--- /dev/null
+++ b/source/libs/the-link/codec.ts
@@ -0,0 +1,20 @@
+export type Bytes = Uint8Array<ArrayBuffer>
+
+export type Serialize = (value: unknown) => Bytes
+
+export type Deserialize = (bytes: Bytes) => unknown
+
+const encoder = new TextEncoder()
+
+const decoder = new TextDecoder("utf-8", { fatal: true })
+
+export const defaultSerialize: Serialize = value => {
+
+ const serialized = JSON.stringify(value)
+
+ if (serialized === undefined) throw new TypeError("The value cannot be serialized as JSON")
+
+ return encoder.encode(serialized)
+}
+
+export const defaultDeserialize: Deserialize = bytes => JSON.parse(decoder.decode(bytes))
diff --git a/source/libs/the-link/plugins/client-link/client-link.ts b/source/libs/the-link/plugins/client-link/client-link.ts
index a4f411c..a533fd6 100644
--- a/source/libs/the-link/plugins/client-link/client-link.ts
+++ b/source/libs/the-link/plugins/client-link/client-link.ts
@@ -1,4 +1,7 @@
import Tunnel, { Subscriber } from "../../tunnel"
+import { bytesToText, receiveBytes } from "./transport"
+import { defaultDeserialize, defaultSerialize } from "../../codec"
+import type { Deserialize, Serialize } from "../../codec"
import SocketLink from "./socket-link"
import TheLink from "../../the-link"
import { v4 as uuidv4 } from "uuid"
@@ -12,8 +15,8 @@ import { v4 as uuidv4 } from "uuid"
* connection as a client-side SocketLink. Recoverable WebSocket closures trigger
* a delayed resubscribe with the original connection payload.
*
- * The adapter uses JSON serialization by default, with hooks for custom
- * serialization layers that must match the corresponding ServerLink.
+ * The adapter uses UTF-8 JSON bytes by default, with hooks for custom codecs
+ * that must match the corresponding ServerLink.
*
* @example
* ```typescript
@@ -42,15 +45,9 @@ export default class ClientLink extends TheLink {
*/
private readonly url: string
- /**
- * Converts outbound values into wire-format strings.
- */
- private serialize = <Input>(input: Input): string => JSON.stringify(input)
+ private serialize: Serialize = defaultSerialize
- /**
- * Converts wire-format strings back into typed values.
- */
- private deserialize = <Output>(input: string): Output => JSON.parse(input)
+ private deserialize: Deserialize = defaultDeserialize
/**
* Active WebSocket-backed SocketLink instances keyed by connection UUID.
@@ -76,21 +73,21 @@ export default class ClientLink extends TheLink {
/**
* Configure the serialization function used for HTTP and WebSocket payloads.
*
- * @param serialize Custom function that converts values to strings
+ * @param serialize Custom function that converts values to bytes
*/
- public setSerialize(serialize: typeof this.serialize<unknown>) {
+ public setSerialize(serialize: Serialize) {
- this.serialize = serialize as typeof this.serialize
+ this.serialize = serialize
}
/**
* Configure the deserialization function used for HTTP and WebSocket payloads.
*
- * @param deserialize Custom function that parses values from strings
+ * @param deserialize Custom function that parses values from bytes
*/
- public setDeserialize(deserialize: typeof this.deserialize<unknown>) {
+ public setDeserialize(deserialize: Deserialize) {
- this.deserialize = deserialize as typeof this.deserialize
+ this.deserialize = deserialize
}
/**
@@ -107,7 +104,7 @@ export default class ClientLink extends TheLink {
/**
* Open a WebSocket subscription to the server.
*
- * The connection payload is serialized into the `payload` query parameter.
+ * The connection payload is serialized and encoded into the `payload` query parameter.
* When the server responds with a `subscribe` envelope, this client creates a
* SocketLink and publishes it on the internal `subscribe` event plus the
* UUID-scoped `subscribe:<uuid>` event.
@@ -120,14 +117,16 @@ export default class ClientLink extends TheLink {
const searchParams = new URLSearchParams()
// Include caller-provided connection context in the subscribe request.
- searchParams.set("payload", this.serialize({ current: payload }))
+ searchParams.set("payload", bytesToText(this.serialize({ current: payload })))
const socket = new WebSocket(`${this.url}/subscribe?${searchParams.toString()}`)
+ socket.binaryType = "arraybuffer"
+
const uuid = uuidv4()
// Route the server subscribe envelope through the WebSocket message handler.
- socket.addEventListener("message", (event) => this.webSocketMessageHandler(event, socket, uuid))
+ socket.addEventListener("message", (event) => this.webSocketMessageHandler(event, socket, uuid), { once: true })
// Ensure SocketLink cleanup and reconnect handling when the WebSocket closes.
socket.addEventListener("close", (event) => this.webSocketCloseHandler(event, payload, uuid))
@@ -191,7 +190,7 @@ export default class ClientLink extends TheLink {
if (!response.ok) throw new Error(await response.text())
- return this.deserialize(await response.text())
+ return this.deserialize(new Uint8Array(await response.arrayBuffer()))
}
/**
@@ -209,7 +208,7 @@ export default class ClientLink extends TheLink {
*/
private async webSocketMessageHandler(event: MessageEvent, socket: WebSocket, uuid: string) {
- const result = this.deserialize<{ type: string, data: unknown }>(event.data)
+ const result = this.deserialize(await receiveBytes(event.data)) as { type: string, data: unknown }
if (result.type === "subscribe") {
@@ -278,4 +277,4 @@ export default class ClientLink extends TheLink {
}
}
}
-}
\ No newline at end of file
+}
diff --git a/source/libs/the-link/plugins/client-link/socket-link.ts b/source/libs/the-link/plugins/client-link/socket-link.ts
index e5c9202..e550766 100644
--- a/source/libs/the-link/plugins/client-link/socket-link.ts
+++ b/source/libs/the-link/plugins/client-link/socket-link.ts
@@ -1,4 +1,7 @@
import TheLink from "../../the-link"
+import { receiveBytes } from "./transport"
+import { defaultDeserialize, defaultSerialize } from "../../codec"
+import type { Deserialize, Serialize } from "../../codec"
import Tunnel from "../../tunnel"
/**
@@ -37,15 +40,9 @@ export default class SocketLink<Payload = unknown> extends TheLink {
*/
public readonly payload: Payload
- /**
- * Converts outbound values into wire-format strings.
- */
- private serialize = <Input>(input: Input): string => JSON.stringify(input)
+ private serialize: Serialize = defaultSerialize
- /**
- * Converts wire-format strings back into typed values.
- */
- private deserialize = <Output>(input: string): Output => JSON.parse(input)
+ private deserialize: Deserialize = defaultDeserialize
/**
* Initialize a SocketLink for one browser WebSocket subscription.
@@ -75,21 +72,21 @@ export default class SocketLink<Payload = unknown> extends TheLink {
/**
* Configure the serialization function used for WebSocket payloads.
*
- * @param serialize Custom function that converts values to strings
+ * @param serialize Custom function that converts values to bytes
*/
- public setSerialize(serialize: typeof this.serialize<unknown>) {
+ public setSerialize(serialize: Serialize) {
- this.serialize = serialize as typeof this.serialize
+ this.serialize = serialize
}
/**
* Configure the deserialization function used for WebSocket payloads.
*
- * @param deserialize Custom function that parses values from strings
+ * @param deserialize Custom function that parses values from bytes
*/
- public setDeserialize(deserialize: typeof this.deserialize<unknown>) {
+ public setDeserialize(deserialize: Deserialize) {
- this.deserialize = deserialize as typeof this.deserialize
+ this.deserialize = deserialize
}
/**
@@ -135,7 +132,7 @@ export default class SocketLink<Payload = unknown> extends TheLink {
*/
private async subscribeHandler(event: MessageEvent) {
- const result = this.deserialize<{ type: string, data: [string, ...unknown[]] }>(event.data)
+ const result = this.deserialize(await receiveBytes(event.data)) as { type: string, data: [string, ...unknown[]] }
if (result.type === "message") {
@@ -176,4 +173,4 @@ export default class SocketLink<Payload = unknown> extends TheLink {
await this.$internal.publish("unsubscribe", event.code, event.reason)
}
-}
\ No newline at end of file
+}
diff --git a/source/libs/the-link/plugins/client-link/transport.ts b/source/libs/the-link/plugins/client-link/transport.ts
new file mode 100644
index 0000000..38afc43
--- /dev/null
+++ b/source/libs/the-link/plugins/client-link/transport.ts
@@ -0,0 +1,24 @@
+import type { Bytes } from "../../codec"
+
+export const receiveBytes = async (value: unknown): Promise<Bytes> => {
+
+ if (value instanceof ArrayBuffer) return new Uint8Array(value)
+
+ if (ArrayBuffer.isView(value)) {
+
+ return Uint8Array.from(new Uint8Array(value.buffer, value.byteOffset, value.byteLength))
+ }
+
+ if (value instanceof Blob) return new Uint8Array(await value.arrayBuffer())
+
+ throw new TypeError("The WebSocket message is not binary")
+}
+
+export const bytesToText = (bytes: Bytes) => {
+
+ let binary = ""
+
+ for (const byte of bytes) binary += String.fromCharCode(byte)
+
+ return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "")
+}
diff --git a/source/libs/the-link/plugins/process-link/process-link.ts b/source/libs/the-link/plugins/process-link/process-link.ts
index 37f1102..5974ca0 100644
--- a/source/libs/the-link/plugins/process-link/process-link.ts
+++ b/source/libs/the-link/plugins/process-link/process-link.ts
@@ -1,5 +1,7 @@
import { ChildProcess } from "child_process"
import TheLink from "../../the-link"
+import { defaultDeserialize, defaultSerialize, type Deserialize, type Serialize } from "../../codec"
+import { receiveBytes } from "./transport"
/**
* Process communication adapter using Node.js IPC.
@@ -8,8 +10,7 @@ import TheLink from "../../the-link"
* active IPC channel. Incoming IPC messages are published through the inbound
* tunnel, and outbound tunnel events are sent to the target process.
*
- * Messages use TheLink's array envelope format:
- * `[event, ...values]`.
+ * Messages carry TheLink's `[event, ...values]` envelope as bytes.
*
* @example
* ```typescript
@@ -32,19 +33,27 @@ export default class ProcessLink extends TheLink {
*/
private readonly target: NodeJS.Process | ChildProcess
+ private readonly serialize: Serialize
+
+ private readonly deserialize: Deserialize
+
/**
* Initialize a ProcessLink with a target IPC process.
*
* @param target Process to communicate with, defaults to the current process
* @throws Error when the target does not have an active IPC channel
*/
- public constructor(target: NodeJS.Process | ChildProcess = process) {
+ public constructor(target: NodeJS.Process | ChildProcess = process, serialize: Serialize = defaultSerialize, deserialize: Deserialize = defaultDeserialize) {
super()
// Store the IPC target for message delivery.
this.target = target
+ this.serialize = serialize
+
+ this.deserialize = deserialize
+
if (typeof this.target.send !== "function") throw new Error("IPC channel not available. Ensure the process was spawned with IPC support.")
// Route IPC messages from the target into the local inbound tunnel.
@@ -64,10 +73,16 @@ export default class ProcessLink extends TheLink {
*/
private async messageHandler(message: unknown) {
- if (Array.isArray(message) && typeof message[0] === "string") {
+ let decoded: unknown
+
+ try { decoded = this.deserialize(receiveBytes(message)) }
+
+ catch { return }
+
+ if (Array.isArray(decoded) && typeof decoded[0] === "string") {
// Decode the event envelope after validating its protocol shape.
- const [event, ...values] = message as [string, ...unknown[]]
+ const [event, ...values] = decoded as [string, ...unknown[]]
await this.$inbound.publish(event, ...values)
}
@@ -82,6 +97,6 @@ export default class ProcessLink extends TheLink {
private publishHandler(event: string, ...values: unknown[]) {
// The non-null assertion is guarded by the constructor IPC check.
- this.target.send!([event, ...values])
+ this.target.send!(this.serialize([event, ...values]))
}
-}
\ No newline at end of file
+}
diff --git a/source/libs/the-link/plugins/process-link/transport.ts b/source/libs/the-link/plugins/process-link/transport.ts
new file mode 100644
index 0000000..a0529ca
--- /dev/null
+++ b/source/libs/the-link/plugins/process-link/transport.ts
@@ -0,0 +1,12 @@
+import type { Bytes } from "../../codec"
+
+export const receiveBytes = (value: unknown): Bytes => {
+
+ if (value instanceof Uint8Array) return Uint8Array.from(value)
+
+ if (value instanceof ArrayBuffer) return new Uint8Array(value)
+
+ if (ArrayBuffer.isView(value)) return Uint8Array.from(new Uint8Array(value.buffer, value.byteOffset, value.byteLength))
+
+ throw new TypeError("The process message is not binary")
+}
diff --git a/source/libs/the-link/plugins/server-link/server-link.ts b/source/libs/the-link/plugins/server-link/server-link.ts
index c8be82f..16f9524 100644
--- a/source/libs/the-link/plugins/server-link/server-link.ts
+++ b/source/libs/the-link/plugins/server-link/server-link.ts
@@ -1,5 +1,8 @@
import { UpgradeWebSocket, WSContext, WSEvents } from "hono/ws"
import Tunnel, { Subscriber } from "../../tunnel"
+import { receiveBytes, textToBytes } from "./transport"
+import { defaultDeserialize, defaultSerialize } from "../../codec"
+import type { Deserialize, Serialize } from "../../codec"
import { HonoOptions } from "hono/hono-base"
import SocketLink from "./socket-link"
import { BlankEnv } from "hono/types"
@@ -15,9 +18,8 @@ import { v4 as uuidv4 } from "uuid"
* communication. Each accepted WebSocket connection gets a dedicated
* SocketLink instance, allowing application code to route events per client.
*
- * The adapter uses JSON serialization by default, with hooks for custom
- * serialization layers such as compression, encryption, or type-preserving
- * codecs.
+ * The adapter uses UTF-8 JSON bytes by default, with hooks for custom codecs
+ * such as compression, encryption, or type preservation.
*
* Connection lifecycle events:
* - `subscribe`: Published on the internal tunnel when a socket connects
@@ -56,15 +58,9 @@ export default class ServerLink extends TheLink {
*/
private debugging: boolean = false
- /**
- * Converts outbound values into wire-format strings.
- */
- private serialize = <Input>(input: Input): string => JSON.stringify(input)
+ private serialize: Serialize = defaultSerialize
- /**
- * Converts wire-format strings back into typed values.
- */
- private deserialize = <Output>(input: string): Output => JSON.parse(input)
+ private deserialize: Deserialize = defaultDeserialize
/**
* Active WebSocket-backed SocketLink instances keyed by connection UUID.
@@ -123,21 +119,21 @@ export default class ServerLink extends TheLink {
/**
* Configure the serialization function used for HTTP and WebSocket payloads.
*
- * @param serialize Custom function that converts values to strings
+ * @param serialize Custom function that converts values to bytes
*/
- public setSerialize(serialize: typeof this.serialize<unknown>) {
+ public setSerialize(serialize: Serialize) {
- this.serialize = serialize as typeof this.serialize
+ this.serialize = serialize
}
/**
* Configure the deserialization function used for HTTP and WebSocket payloads.
*
- * @param deserialize Custom function that parses values from strings
+ * @param deserialize Custom function that parses values from bytes
*/
- public setDeserialize(deserialize: typeof this.deserialize<unknown>) {
+ public setDeserialize(deserialize: Deserialize) {
- this.deserialize = deserialize as typeof this.deserialize
+ this.deserialize = deserialize
}
/**
@@ -165,12 +161,14 @@ export default class ServerLink extends TheLink {
try {
// Decode the event envelope from the request body.
- const [event, ...values] = this.deserialize<[string, ...unknown[]]>(await context.req.text())
+ const bytes = new Uint8Array(await context.req.arrayBuffer())
+
+ const [event, ...values] = this.deserialize(bytes) as [string, ...unknown[]]
// Route the client event into the server-side inbound tunnel.
const results = await this.$inbound.publish(event, ...values)
- return context.text(this.serialize(results))
+ return context.body(this.serialize(results))
}
catch (exception) {
@@ -223,15 +221,13 @@ export default class ServerLink extends TheLink {
if (payload === undefined) throw new Error("payload is required")
- const parsedPayload = this.deserialize<{ current: unknown }>(payload)
+ const parsedPayload = this.deserialize(textToBytes(payload)) as { current: unknown }
// Wrap the raw WebSocket in TheLink-compatible socket routing.
const socketLink = new SocketLink(socket, parsedPayload.current)
socketLink.setSerialize(value => this.serialize(value))
- socketLink.setDeserialize(value => this.deserialize(value))
-
// Let application code initialize the connection before notifying the client.
const response = await this.$internal.publishFirst("subscribe", socketLink)
@@ -263,7 +259,7 @@ export default class ServerLink extends TheLink {
if (socketLink) {
// Decode the event payload from the message.
- const [eventName, ...values] = this.deserialize<[string, ...unknown[]]>(event.data)
+ const [eventName, ...values] = this.deserialize(await receiveBytes(event.data)) as [string, ...unknown[]]
try {
@@ -302,4 +298,4 @@ export default class ServerLink extends TheLink {
this.sockets.delete(uuid)
}
}
-}
\ No newline at end of file
+}
diff --git a/source/libs/the-link/plugins/server-link/socket-link.ts b/source/libs/the-link/plugins/server-link/socket-link.ts
index b499133..d12ea67 100644
--- a/source/libs/the-link/plugins/server-link/socket-link.ts
+++ b/source/libs/the-link/plugins/server-link/socket-link.ts
@@ -1,4 +1,6 @@
import TheLink from "../../the-link"
+import { defaultSerialize } from "../../codec"
+import type { Serialize } from "../../codec"
import { WSContext } from "hono/ws"
import Tunnel from "../../tunnel"
@@ -39,15 +41,7 @@ export default class SocketLink<Payload = unknown> extends TheLink {
*/
public readonly payload: Payload
- /**
- * Converts outbound values into wire-format strings.
- */
- private serialize = <Input>(input: Input): string => JSON.stringify(input)
-
- /**
- * Converts wire-format strings back into typed values.
- */
- private deserialize = <Output>(input: string): Output => JSON.parse(input)
+ private serialize: Serialize = defaultSerialize
/**
* Initialize a SocketLink for one accepted WebSocket connection.
@@ -75,21 +69,11 @@ export default class SocketLink<Payload = unknown> extends TheLink {
/**
* Configure the serialization function used for WebSocket payloads.
*
- * @param serialize Custom function that converts values to strings
- */
- public setSerialize(serialize: typeof this.serialize<unknown>) {
-
- this.serialize = serialize as typeof this.serialize
- }
-
- /**
- * Configure the deserialization function used for WebSocket payloads.
- *
- * @param deserialize Custom function that parses values from strings
+ * @param serialize Custom function that converts values to bytes
*/
- public setDeserialize(deserialize: typeof this.deserialize<unknown>) {
+ public setSerialize(serialize: Serialize) {
- this.deserialize = deserialize as typeof this.deserialize
+ this.serialize = serialize
}
/**
@@ -142,4 +126,4 @@ export default class SocketLink<Payload = unknown> extends TheLink {
// Send the event envelope using the same simple event tuple protocol.
this.socket.send(this.serialize({ type: "message", data: [event, ...values] }))
}
-}
\ No newline at end of file
+}
diff --git a/source/libs/the-link/plugins/server-link/transport.ts b/source/libs/the-link/plugins/server-link/transport.ts
new file mode 100644
index 0000000..fa83d00
--- /dev/null
+++ b/source/libs/the-link/plugins/server-link/transport.ts
@@ -0,0 +1,24 @@
+import type { Bytes } from "../../codec"
+
+export const receiveBytes = async (value: unknown): Promise<Bytes> => {
+
+ if (value instanceof ArrayBuffer) return new Uint8Array(value)
+
+ if (ArrayBuffer.isView(value)) {
+
+ return Uint8Array.from(new Uint8Array(value.buffer, value.byteOffset, value.byteLength))
+ }
+
+ if (value instanceof Blob) return new Uint8Array(await value.arrayBuffer())
+
+ throw new TypeError("The WebSocket message is not binary")
+}
+
+export const textToBytes = (value: string): Bytes => {
+
+ const unpadded = value.replaceAll("-", "+").replaceAll("_", "/")
+
+ const binary = atob(unpadded.padEnd(unpadded.length + (4 - unpadded.length % 4) % 4, "="))
+
+ return Uint8Array.from(binary, character => character.charCodeAt(0))
+}
diff --git a/source/server/core/dialog-manager.ts b/source/server/core/dialog-manager.ts
index 44a49db..9e00e91 100644
--- a/source/server/core/dialog-manager.ts
+++ b/source/server/core/dialog-manager.ts
@@ -1,5 +1,5 @@
import { Subscribe } from "@libs/the-link/decorators/escript"
-import { Transmitted } from "@libs/superjson"
+import { Transmitted } from "@libs/messagepack"
import TheLink from "@libs/the-link/the-link"
import { randomUUID } from "node:crypto"
import { type default as Process } from "./link-manager/auth-manager/process-manager/process"
diff --git a/source/server/core/link-manager/auth-manager/auth-manager.ts b/source/server/core/link-manager/auth-manager/auth-manager.ts
index dbe6935..4da2a51 100644
--- a/source/server/core/link-manager/auth-manager/auth-manager.ts
+++ b/source/server/core/link-manager/auth-manager/auth-manager.ts
@@ -3,7 +3,7 @@ import ServedFileManager from "@server/core/served-file-manager"
import DialogManager from "@server/core/dialog-manager"
import ProcessManager from "./process-manager/process-manager"
import ProgramManager from "./program-manager/program-manager"
-import { Transmitted } from "@libs/superjson"
+import { Transmitted } from "@libs/messagepack"
import TheLink from "@libs/the-link/the-link"
import LinkManager from "../link-manager"
import { isPermissionName } from "@phreshos/core"
diff --git a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts b/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts
index 071a647..cb33c18 100644
--- a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts
+++ b/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts
@@ -6,7 +6,7 @@ import Program from "../program-manager/program"
import { Layer } from "../program-manager/config"
import Window, { Position, Size } from "./window"
import TheLink from "@libs/the-link/the-link"
-import { Transmitted } from "@libs/superjson"
+import { Transmitted } from "@libs/messagepack"
import AuthManager from "../auth-manager"
import { signalProcessTree } from "@libs/process-tree"
import Process, { type HostedProcess } from "./process"
diff --git a/source/server/core/link-manager/auth-manager/process-manager/process.ts b/source/server/core/link-manager/auth-manager/process-manager/process.ts
index 5b58fb8..710f2cc 100644
--- a/source/server/core/link-manager/auth-manager/process-manager/process.ts
+++ b/source/server/core/link-manager/auth-manager/process-manager/process.ts
@@ -2,7 +2,7 @@ import { Options } from "../program-manager/program-manager"
import Program from "../program-manager/program"
import Window, { Position, Size } from "./window"
import { ChildProcess } from "node:child_process"
-import { Transmitted } from "@libs/superjson"
+import { Transmitted } from "@libs/messagepack"
import ServerProcessBoundary from "./server-process-boundary"
import HostTraffic from "./host-traffic"
import ClientState from "./client-state"
@@ -53,8 +53,8 @@ export default class Process {
// When this instance began. A process's birth is its construction,
// so nothing hands this over — there is no earlier moment to mean.
//
- // A `Date`, and the link keeps it one: superjson carries dates, and
- // `libs/superjson` leaves them alone rather than letting `toJSON`
+ // A `Date`, and the link keeps it one: MessagePack carries dates, and
+ // `libs/messagepack` leaves them alone rather than letting `toJSON`
// degrade them to strings. The other two roads out of here speak
// plain JSON — a program's channel and this machine's door — so on
// those it arrives as the ISO string a date serialises to. That is
diff --git a/source/server/core/link-manager/auth-manager/process-manager/server-process-boundary.ts b/source/server/core/link-manager/auth-manager/process-manager/server-process-boundary.ts
index 84968bd..4c18441 100644
--- a/source/server/core/link-manager/auth-manager/process-manager/server-process-boundary.ts
+++ b/source/server/core/link-manager/auth-manager/process-manager/server-process-boundary.ts
@@ -7,6 +7,7 @@ import EndpointEvents from "./endpoint-events"
import EndpointServices, { type ServiceScope } from "./endpoint-services"
import type { ServiceKey } from "@phreshos/core"
import Tunnel from "@libs/the-link/tunnel"
+import messagepack from "@libs/messagepack"
/**
* The boundary around one server execution endpoint.
@@ -60,7 +61,7 @@ export default class ServerProcessBoundary extends ProcessLink {
public constructor(child: ChildProcess, clientDeclared: boolean, ended: Ending, unanswered: (values: unknown[], reason: string) => void, hostTraffic: HostTraffic, theme: Tunnel) {
- super(child)
+ super(child, messagepack.serialize, messagepack.deserialize)
this.clientDeclared = clientDeclared
diff --git a/source/server/core/link-manager/auth-manager/process-manager/window.ts b/source/server/core/link-manager/auth-manager/process-manager/window.ts
index 3fcb7d3..36ab6f8 100644
--- a/source/server/core/link-manager/auth-manager/process-manager/window.ts
+++ b/source/server/core/link-manager/auth-manager/process-manager/window.ts
@@ -1,5 +1,5 @@
import { isRelativeValue, type Position, type Size, type Value, type WindowGeometry, type WindowLayer } from "@phreshos/core"
-import { Transmitted } from "@libs/superjson"
+import { Transmitted } from "@libs/messagepack"
/**
* How a process is shown. Every value is either a number of pixels or a
diff --git a/source/server/core/link-manager/auth-manager/program-manager/entry.ts b/source/server/core/link-manager/auth-manager/program-manager/entry.ts
index a5e0d91..1c00823 100644
--- a/source/server/core/link-manager/auth-manager/program-manager/entry.ts
+++ b/source/server/core/link-manager/auth-manager/program-manager/entry.ts
@@ -1,4 +1,4 @@
-import { Transmitted } from "@libs/superjson"
+import { Transmitted } from "@libs/messagepack"
import Program from "./program"
/**
diff --git a/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts b/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts
index 1246c5d..5733f85 100644
--- a/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts
+++ b/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts
@@ -4,7 +4,7 @@ import { spawn } from "node:child_process"
import { randomUUID } from "node:crypto"
import TheLink from "@libs/the-link/the-link"
import SqliteDatabase from "@libs/sqlite-database"
-import { Transmitted } from "@libs/superjson"
+import { Transmitted } from "@libs/messagepack"
import FileManager from "@libs/file-manager"
import FileArea from "@libs/file-area"
import openStore from "@server/core/open-store"
@@ -1071,6 +1071,9 @@ export default class ProgramManager extends TheLink {
// also watching.
stdio: ["ignore", "pipe", "pipe", "ipc"],
+ // MessagePack envelopes remain bytes across Node's IPC boundary.
+ serialization: "advanced",
+
// Only what the operating system needs to run a command.
// No program data travels this way: options and places are
// asked for over the channel, which is the one road a
diff --git a/source/server/core/link-manager/link-manager.ts b/source/server/core/link-manager/link-manager.ts
index 1f8e837..2fd09ab 100644
--- a/source/server/core/link-manager/link-manager.ts
+++ b/source/server/core/link-manager/link-manager.ts
@@ -2,7 +2,7 @@ import { Forward, Subscribe } from "@libs/the-link/decorators/escript"
import AuthManager from "./auth-manager/auth-manager"
import TheLink from "@libs/the-link/the-link"
import Property from "@libs/the-link/property"
-import { Transmitted } from "@libs/superjson"
+import { Transmitted } from "@libs/messagepack"
import Application from "../application"
import { type ThemeProperties, type WallpaperLaunch } from "@phreshos/core"
import { type default as Program } from "./auth-manager/program-manager/program"
diff --git a/source/server/view/link.ts b/source/server/view/link.ts
index 9b3c19d..a4378f3 100644
--- a/source/server/view/link.ts
+++ b/source/server/view/link.ts
@@ -1,7 +1,7 @@
import ServerLink from "@libs/the-link/plugins/server-link/server-link"
import { upgradeWebSocket } from "@hono/node-server"
import Application from "@server/core/application"
-import superjson from "@libs/superjson"
+import messagepack from "@libs/messagepack"
import { failed, succeeded } from "@server/core/outcome"
export default function (application: Application, debugging: boolean) {
@@ -10,9 +10,9 @@ export default function (application: Application, debugging: boolean) {
if (debugging) serverLink.enableDebugging()
- serverLink.setSerialize(data => superjson.stringify(data))
+ serverLink.setSerialize(messagepack.serialize)
- serverLink.setDeserialize(data => superjson.parse(data))
+ serverLink.setDeserialize(messagepack.deserialize)
serverLink.onSubscribe(function (socketLink) {