Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

refactor(device-link): 将压缩复用收缩为设备传输

Dasha73d42db2b4c
diff --git a/apps/desktop/src/main/device-link/transferCodec.ts b/apps/desktop/src/main/device-link/transferCodec.ts
index e78c5a8199..445eca9b9d 100644
--- a/apps/desktop/src/main/device-link/transferCodec.ts
+++ b/apps/desktop/src/main/device-link/transferCodec.ts
@@ -1,5 +1,5 @@
import { createHash } from 'node:crypto';
-import { compressGzipSync, gunzipBase64TextBounded } from '@cindy/anthropic-compat-proxy/compression';
+import { compressGzipSync, gunzipBase64TextBounded } from '@cindy/device-link/node-compression';
import type { DeviceLinkTransferCodec } from '@cindy/device-link';
import { createLogger } from '../logger';
@@ -7,7 +7,7 @@ const log = createLogger('device-link:compression');
/**
* Desktop 既是被控端也是控制端(桌面远控桌面),两个方向共用一份编码器。
- * 保留 level 4 和同步发送错误契约;HTTP 大请求复用同一工具的异步版本。
+ * 保留 level 4 和同步发送错误契约;Node 编解码通过独立入口复用。
*/
export const desktopTransferCodec: DeviceLinkTransferCodec = {
gzipBase64: (text) => {
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index 0b0208c3f6..5f7e169e39 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -196,24 +196,9 @@ relay 不解析隧道 payload,无服务端改动、数据库 migration 或部
Desktop 的压缩保持 gzip level 4 与同步发送/错误处理契约,手机与电脑、电脑与电脑
共用这一实现。收益按 gzip 的 base64 长度与原始 JSON 的 UTF-8 **字节数**比较,缩小超过
10% 才采用;大小门槛、解压上限与缓存预算仍按原有字符数计。Node 编解码及数字统计复用
-`@cindy/anthropic-compat-proxy/compression` 独立入口,不把 Node 依赖引入 Mobile/device-link。
-
-## 模型 HTTP 代理的出站压缩
-
-`anthropic-compat-proxy` 在路由、正文转换与请求头改写之后,仅对最终目标为
-`https://api.anthropic.com:443/v1/messages` 的 JSON POST 启用 gzip:正文至少 64 KiB、
-没有既存 `Content-Encoding`,使用异步 level 1,压缩字节数减少超过 10% 才发送。
-目标按精确协议、主机、端口和路径判断,不按供应商名或兼容 API 格式猜测;本地端点、
-Cindy 网关与未经确认的第三方默认保持原样。原生订阅直连、WebSocket 与 localHandler
-自己发出的请求不经过这个出口,不因本改动强制压缩。
-
-保留逻辑 JSON 给观察器与已有语义错误恢复,只对 wire 副本压缩并重算 Content-Length。
-压缩等待后重新检查客户端连接与原有派发授权。压缩本身失败可在首次发送前回退原文;
-上游拒绝压缩不触发自动重放或支持探测,避免重复推理。成功响应仍流式透传。
-两类链路共用 Node gzip 原语与原始/gzip/wire 字节、压缩耗时的统计口径,业务门槛
-和封装各自保留。DEBUG 统计只记数字,不记录正文、凭证或完整目标 URL。
-回归见 `packages/anthropic-compat-proxy/src/request-compression.test.ts` 与 Desktop
-`device-link/__tests__/transferCodec.test.ts`(实际 zlib/pako 解码)。
+`@cindy/device-link/node-compression` 独立入口,跨平台主入口与 Mobile 不加载 Node 模块。
+DEBUG 统计只记原始/gzip/wire 字节与压缩耗时,不记录正文或凭证。
+回归见 Desktop `device-link/__tests__/transferCodec.test.ts`(实际 zlib/pako 解码)。
## 群执行终态与错误展示
diff --git a/packages/anthropic-compat-proxy/package.json b/packages/anthropic-compat-proxy/package.json
index 2af6bcba95..c30581cbd3 100644
--- a/packages/anthropic-compat-proxy/package.json
+++ b/packages/anthropic-compat-proxy/package.json
@@ -7,8 +7,7 @@
"main": "./src/index.ts",
"types": "./src/index.ts",
"exports": {
- ".": "./src/index.ts",
- "./compression": "./src/compression.ts"
+ ".": "./src/index.ts"
},
"scripts": {
"build": "tsc --noEmit",
diff --git a/packages/anthropic-compat-proxy/src/request-compression.test.ts b/packages/anthropic-compat-proxy/src/request-compression.test.ts
deleted file mode 100644
index 4edee86cea..0000000000
--- a/packages/anthropic-compat-proxy/src/request-compression.test.ts
+++ /dev/null
@@ -1,237 +0,0 @@
-import { createServer, request as httpRequest, type IncomingHttpHeaders, type RequestOptions } from 'node:http';
-import { gunzipSync, gzipSync } from 'node:zlib';
-import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
-import { compressGzip } from './compression.js';
-import { createAnthropicCompatProxy } from './server.js';
-import { shouldCompressRequest } from './request-compression.js';
-import { listenOnAvailableLoopbackPort } from './test-loopback-server.js';
-import type { ProxyHandle, ProxyOptions } from './types.js';
-
-// Value: the production proxy must gzip only its final supported HTTP upload,
-// preserving recovery, cancellation and dispatch authorization. Existing tests
-// only use plain loopback targets, which deliberately never enable compression.
-// Minimal input: >=64 KiB JSON routed to the first-party Messages endpoint.
-// Tier: unit, one loopback fixture; HTTPS is redirected here, never to the internet.
-const transport = vi.hoisted(() => ({ port: 0 }));
-vi.mock('node:https', async (original) => ({
- ...await original<typeof import('node:https')>(),
- request: (options: RequestOptions) => httpRequest({
- ...options, hostname: '127.0.0.1', port: transport.port, agent: undefined,
- }),
-}));
-vi.mock('./compression.js', async (original) => {
- const actual = await original<typeof import('./compression.js')>();
- return { ...actual, compressGzip: vi.fn(actual.compressGzip) };
-});
-
-const records: Array<{ body: Buffer; headers: IncomingHttpHeaders }> = [];
-let responses: number[] = [];
-const upstream = createServer((req, res) => {
- const chunks: Buffer[] = [];
- req.on('data', (chunk: Buffer) => chunks.push(chunk));
- req.on('end', () => {
- records.push({ body: Buffer.concat(chunks), headers: req.headers });
- res.writeHead(responses.shift() ?? 200, { 'content-type': 'application/json' });
- res.end(JSON.stringify({ message: 'remove forbidden' }));
- });
-});
-let proxy: ProxyHandle | undefined;
-beforeAll(async () => { transport.port = await listenOnAvailableLoopbackPort(upstream); });
-beforeEach(() => { records.length = 0; responses = []; vi.mocked(compressGzip).mockClear(); });
-afterEach(async () => { await proxy?.dispose(); proxy = undefined; });
-afterAll(async () => {
- upstream.closeAllConnections();
- await new Promise<void>((resolve) => upstream.close(() => resolve()));
-});
-
-const large = { model: 'claude-test', messages: [{ role: 'user', content: '中文代码🙂'.repeat(12_000) }] };
-async function start(options: Partial<ProxyOptions> = {}) {
- proxy = await createAnthropicCompatProxy({
- upstream: 'https://api.anthropic.com', transformRequest: [], ...options,
- });
- return proxy;
-}
-function send(body: string | Buffer = JSON.stringify(large), headers = {}, path = '/v1/messages') {
- return fetch(`${proxy!.url}${path}`, {
- method: 'POST', headers: { 'content-type': 'application/json', ...headers },
- body: typeof body === 'string' ? body : new Uint8Array(body),
- });
-}
-const decoded = (index = 0) => JSON.parse(gunzipSync(records[index].body).toString('utf8'));
-
-describe('final model request compression', () => {
- it('compresses after routing/transforms; preserves JSON for observers and reports byte metrics only', async () => {
- const observer = vi.fn();
- const debug = vi.fn();
- await start({
- upstream: 'http://unused.invalid',
- routingTransform: () => ({ upstreamOverride: 'https://api.anthropic.com' }),
- transformRequest: [(body) => ({ ...(body as Record<string, unknown>), model: 'claude-rewritten' })],
- responseObserver: observer,
- logger: { debug },
- });
- const response = await send();
- expect(response.status).toBe(200);
- await response.text();
- expect(decoded()).toEqual({ ...large, model: 'claude-rewritten' });
- expect(records[0].headers['content-encoding']).toBe('gzip');
- expect(Number(records[0].headers['content-length'])).toBe(records[0].body.length);
- expect(records[0].body.length).toBeLessThan(Buffer.byteLength(JSON.stringify(large)) / 4);
- expect(JSON.parse(observer.mock.calls[0][0].requestBody.toString())).toEqual(decoded());
- expect(debug.mock.calls.find(([message]) => message === 'request gzip')?.[1]).toEqual({
- reqId: expect.any(Number), originalBytes: expect.any(Number), gzipBytes: records[0].body.length,
- wireBytes: records[0].body.length, compressionMs: expect.any(Number), used: true,
- });
- });
-
- it.each([
- ['small', JSON.stringify({ model: 'claude-test' }), {}, '/v1/messages'],
- ['already encoded', gzipSync(JSON.stringify(large)), { 'Content-Encoding': 'gzip' }, '/v1/messages'],
- ['other media', JSON.stringify(large), { 'content-type': 'text/plain' }, '/v1/messages'],
- ['other endpoint', JSON.stringify(large), {}, '/v1/other'],
- ])('passes %s requests through without another encoding', async (_name, body, headers, path) => {
- await start();
- await (await send(body as string | Buffer, headers, path as string)).text();
- expect(records[0].body).toEqual(Buffer.from(body as string));
- expect(compressGzip).not.toHaveBeenCalled();
- });
-
- it('uses the final route: a compatible third-party or local target is not sufficient', async () => {
- await start({ routingTransform: () => ({ upstreamOverride: `http://127.0.0.1:${transport.port}` }) });
- await (await send()).text();
- expect(records[0].headers['content-encoding']).toBeUndefined();
- expect(JSON.parse(records[0].body.toString())).toEqual(large);
- expect(compressGzip).not.toHaveBeenCalled();
- });
-
- it('keeps the original body for semantic recovery and compresses the corrected retry once', async () => {
- responses = [400, 200];
- await start({ recoveryRules: [{
- id: 'test-forbidden', enabled: () => true, matches: (error) => error.includes('remove forbidden'),
- strip: (body) => {
- const parsed = JSON.parse(body.toString());
- delete parsed.forbidden;
- return Buffer.from(JSON.stringify(parsed));
- },
- }] });
- expect((await send(JSON.stringify({ ...large, forbidden: true }))).status).toBe(200);
- expect(decoded(0).forbidden).toBe(true);
- expect(decoded(1)).toEqual(large);
- expect(records).toHaveLength(2);
- });
-
- it('does not retry an upstream rejection to guess gzip support', async () => {
- responses = [415];
- await start();
- expect((await send()).status).toBe(415);
- expect(records).toHaveLength(1);
- });
-
- it('falls back before sending if local compression fails or has insufficient savings', async () => {
- await start();
- vi.mocked(compressGzip).mockRejectedValueOnce(new Error('local zlib failure'));
- await (await send()).text();
- const body = Buffer.from(JSON.stringify(large));
- vi.mocked(compressGzip).mockResolvedValueOnce({ compressed: body, stats: {
- originalBytes: body.length, gzipBytes: body.length, wireBytes: body.length, compressionMs: 0,
- } });
- await (await send()).text();
- expect(records).toHaveLength(2);
- for (const record of records) {
- expect(record.body).toEqual(body);
- expect(record.headers['content-encoding']).toBeUndefined();
- }
- });
-
- // PR #6284: after a 400 recovery, the previous response has ended but no new
- // upstream listener exists during gzip. Its lifecycle must still settle once.
- it.each([
- ['initial', 'owner-changed'], ['initial', 'client-disconnected'], ['initial', 'gate-error'],
- ['retry', 'owner-changed'], ['retry', 'client-disconnected'], ['retry', 'gate-error'],
- ] as const)('settles %s forwarding after %s during compression', async (phase, reason) => {
- let release!: () => void;
- let started!: () => void;
- const entered = new Promise<void>((resolve) => { started = resolve; });
- const blocked = new Promise<void>((resolve) => { release = resolve; });
- let markSettled!: () => void;
- const settled = new Promise<void>((resolve) => { markSettled = resolve; });
- let valid = true;
- let gateError = false;
- const lifecycle = { onStart: vi.fn(), onComplete: vi.fn(), onFailure: vi.fn() };
- if (phase === 'retry') {
- responses = [400];
- vi.mocked(compressGzip).mockImplementationOnce(async (body) => {
- const compressed = gzipSync(body);
- return { compressed, stats: { originalBytes: body.length, gzipBytes: compressed.length,
- wireBytes: compressed.length, compressionMs: 0 } };
- });
- }
- vi.mocked(compressGzip).mockImplementationOnce(async (body) => {
- started(); await blocked;
- const compressed = gzipSync(body);
- return { compressed, stats: { originalBytes: body.length, gzipBytes: compressed.length,
- wireBytes: compressed.length, compressionMs: 0 } };
- });
- await start({
- transformRequest: [Object.assign((body: unknown) => body, { onRequestSettled: markSettled })],
- routingTransform: () => ({
- dispatchGenerationValid: () => {
- if (gateError) throw new Error('private gate failure');
- return valid;
- },
- forwardLifecycle: lifecycle,
- }),
- recoveryRules: [{
- id: 'test-retry', enabled: () => true, matches: () => true,
- strip: (body) => body,
- }],
- });
- const abort = new AbortController();
- const pending = fetch(`${proxy!.url}/v1/messages`, {
- method: 'POST', headers: { 'content-type': 'application/json' },
- body: JSON.stringify(large), signal: abort.signal,
- });
- await entered;
- if (reason === 'owner-changed') valid = false;
- else if (reason === 'gate-error') gateError = true;
- else {
- abort.abort();
- await expect(pending).rejects.toThrow();
- // Wait for the production settlement hook, not only server.close(): the
- // response close event may arrive after dispose's listening socket closes.
- await proxy!.dispose(); proxy = undefined;
- await settled;
- }
- release();
- if (reason === 'owner-changed') expect((await pending).status).toBe(503);
- if (reason === 'gate-error') expect((await pending).status).toBe(502);
- // Drain the deferred continuation, without a timing-based sleep.
- await blocked;
- await new Promise<void>((resolve) => setImmediate(resolve));
- expect(records).toHaveLength(phase === 'retry' ? 1 : 0);
- expect(lifecycle.onStart).toHaveBeenCalledTimes(phase === 'retry' ? 1 : 0);
- expect(lifecycle.onComplete).not.toHaveBeenCalled();
- if (phase === 'retry') {
- expect(lifecycle.onFailure.mock.calls).toEqual([[
- reason === 'owner-changed' ? 'retry-rejected' : reason === 'gate-error' ? 'retry-error' : 'client-aborted',
- undefined,
- ]]);
- } else {
- expect(lifecycle.onFailure).not.toHaveBeenCalled();
- }
- });
-
- it('requires an exact supported destination, JSON and a 64 KiB byte threshold', () => {
- const target = { protocol: 'https:', hostname: 'api.anthropic.com', port: 443 };
- const headers = { 'Content-Type': 'application/json; charset=utf-8' };
- const eligible = (t = target, bytes = 65536, h = headers) => shouldCompressRequest(t, 'POST', '/v1/messages', h, bytes);
- expect(eligible()).toBe(true);
- expect(eligible(target, 65535)).toBe(false);
- for (const hostname of ['localhost', '127.0.0.1', '::1', 'api.openai.com', 'api.anthropic.com.example.com']) {
- expect(eligible({ ...target, hostname })).toBe(false);
- }
- expect(eligible({ ...target, protocol: 'http:' })).toBe(false);
- expect(eligible({ ...target, port: 8443 })).toBe(false);
- expect(eligible(target, 65536, { ...headers, 'Content-Encoding': 'identity' } as typeof headers)).toBe(false);
- });
-});
diff --git a/packages/anthropic-compat-proxy/src/request-compression.ts b/packages/anthropic-compat-proxy/src/request-compression.ts
deleted file mode 100644
index d68d7fad6c..0000000000
--- a/packages/anthropic-compat-proxy/src/request-compression.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import { headerValue } from './headers.js';
-
-/**
- * Only the first-party Messages endpoint is known to support gzip request bodies
- * (also targeted by Claude Code's native gzip transport). An Anthropic-compatible
- * API shape does not imply support. No probes, retries, or provider-name guesses.
- */
-export function shouldCompressRequest(
- target: { protocol: string; hostname: string; port: number },
- method: string,
- pathname: string,
- headers: Readonly<Record<string, string>>,
- bytes: number,
-): boolean {
- return target.protocol === 'https:' && target.hostname === 'api.anthropic.com' && target.port === 443
- && method === 'POST' && pathname === '/v1/messages'
- && bytes >= 64 * 1024
- && headerValue(headers, 'content-type').split(';', 1)[0].trim().toLowerCase() === 'application/json'
- && !Object.keys(headers).some((key) => key.toLowerCase() === 'content-encoding');
-}
diff --git a/packages/anthropic-compat-proxy/src/server.ts b/packages/anthropic-compat-proxy/src/server.ts
index 76b64737ab..e820b7835b 100644
--- a/packages/anthropic-compat-proxy/src/server.ts
+++ b/packages/anthropic-compat-proxy/src/server.ts
@@ -14,8 +14,6 @@
*/
import { installResponseGuard } from './response-guard.js';
-import { compressGzip } from './compression.js';
-import { shouldCompressRequest } from './request-compression.js';
import { collectRecoverableBody } from './oversized-attachments.js';
import { createHash } from 'node:crypto';
import { createServer, request as httpRequest, type ClientRequest, type IncomingMessage, type RequestOptions, type Server, type ServerResponse } from 'node:http';
@@ -907,19 +905,7 @@ function decodeBodyForLog(buf: Buffer, contentEncoding: string | undefined): Buf
*
* 请求 body 在调用 forward 前已被上层在 debug 级别下 dump 过,这里不重复。
*/
-function forward(...args: Parameters<typeof forwardRequest>): void {
- void forwardRequest(...args).catch(() => {
- const res = args[5];
- // Preparation/dispatch failure must settle the request, never leave an
- // unhandled rejection or replay inference to discover compression support.
- if (res.destroyed || res.writableEnded) return;
- if (res.headersSent) { res.destroy(); return; }
- res.writeHead(502, { 'content-type': 'application/json' });
- res.end(JSON.stringify({ error: { type: 'proxy_error', message: 'upstream request preparation failed' } }));
- });
-}
-
-async function forwardRequest(
+function forward(
target: UpstreamTarget,
method: string,
path: string,
@@ -959,13 +945,13 @@ async function forwardRequest(
// 为 true 时启用 2xx 成功响应的流式有效性门(#2242):空 2xx / 非 SSE 2xx /
// 零事件 SSE 不再原样透传给客户端,转成结构化 502。false 保持字节级透传。
requestDeclaredStream = false,
- // 异步压缩完成后、透明重试前再跑同一条 dispatch gate。返回 false = 已改道(典型 503),
+ // 透明重试前再跑同一条 dispatch gate。返回 false = 已改道(典型 503),
// 不得带着旧 headerOverride 再发一次。省略 = 与扩展前一样直接重发。
beforeRetry?: () => Promise<boolean>,
// Optional request-local operational observer. It never receives raw request/response data.
forwardLifecycle?: ForwardLifecycleObserver | null,
recoverUpstreamOversized?: (body: Buffer, signal: AbortSignal) => Promise<Buffer>,
-): Promise<void> {
+): void {
// Diagnostics are a strict side channel: callback failures must never change forwarding.
const notifyForwardLifecycle = (notify: () => void): void => {
try {
@@ -1003,49 +989,6 @@ async function forwardRequest(
const upstreamQuery = [actualTarget.baseQuery, routedQuery].filter(Boolean).join('&');
const upstreamPath = upstreamQuery ? `${upstreamPathname}?${upstreamQuery}` : upstreamPathname;
- // Keep the logical body for observers and existing semantic recovery rules.
- // Compress only the final wire copy, after routing, transforms and headers.
- let wireBody = body;
- if (shouldCompressRequest(actualTarget, method, upstreamPathname, actualHeaders, body.length)) {
- try {
- const { compressed, stats } = await compressGzip(body, 1);
- const used = stats.wireBytes < stats.originalBytes * 0.9;
- if (used) {
- wireBody = compressed;
- actualHeaders = { ...actualHeaders, 'content-encoding': 'gzip' };
- }
- logger.debug?.('request gzip', { reqId, ...stats, used });
- } catch {
- // Nothing has been sent yet. Local compression failure can safely retain
- // the original body; an upstream error must never trigger a gzip retry.
- logger.debug?.('request gzip unavailable; sending identity', { reqId });
- }
- // A transparent retry has already started the shared lifecycle, but its
- // previous upstream ended and the new request has no close listener yet.
- const notifyPreparationFailure = (fallback: 'retry-rejected' | 'retry-error'): void => {
- notifyForwardLifecycle(() => forwardLifecycle?.onFailure?.(
- clientRes.destroyed && !clientRes.writableEnded ? 'client-aborted' : fallback,
- ));
- };
- const stopIfClientClosed = (): boolean => {
- if (!clientRes.destroyed && !clientRes.writableEnded) return false;
- notifyPreparationFailure('retry-rejected');
- return true;
- };
- if (stopIfClientClosed()) return;
- // Compression yields to the event loop: credentials/owner may have changed.
- try {
- if (beforeRetry && !(await beforeRetry())) {
- notifyPreparationFailure('retry-rejected');
- return;
- }
- } catch (err) {
- notifyPreparationFailure('retry-error');
- throw err;
- }
- if (stopIfClientClosed()) return;
- }
-
// http.request 会把 options 原样透传给 agent.createConnection → net.connect,
// 所以 socket 级 connect 选项运行时有效;但 @types/node 的 RequestOptions 没收录
// autoSelectFamilyAttemptTimeout,用交叉类型显式补上。
@@ -1057,7 +1000,7 @@ async function forwardRequest(
headers: {
...actualHeaders,
host: actualTarget.hostname,
- 'content-length': String(wireBody.length),
+ 'content-length': String(body.length),
},
timeout: UPSTREAM_SOCKET_TIMEOUT_MS,
autoSelectFamilyAttemptTimeout: UPSTREAM_CONNECT_ATTEMPT_TIMEOUT_MS,
@@ -1946,7 +1889,7 @@ async function forwardRequest(
upstreamReq.destroy(new Error('upstream socket timeout'));
});
- upstreamReq.end(wireBody);
+ upstreamReq.end(body);
}
/**
diff --git a/packages/anthropic-compat-proxy/src/types.ts b/packages/anthropic-compat-proxy/src/types.ts
index 88611e21d3..66b2a489bf 100644
--- a/packages/anthropic-compat-proxy/src/types.ts
+++ b/packages/anthropic-compat-proxy/src/types.ts
@@ -168,7 +168,6 @@ export interface ResponseObserverCtx {
*/
readonly outboundHeaders?: Readonly<Record<string, string>>;
readonly responseHeaders: Readonly<Record<string, string>>;
- /** Logical outbound body, before optional transport gzip (observers parse JSON). */
readonly requestBody: Buffer;
}
diff --git a/packages/device-link/package.json b/packages/device-link/package.json
index 4440c13aca..9826e5315d 100644
--- a/packages/device-link/package.json
+++ b/packages/device-link/package.json
@@ -7,7 +7,8 @@
"main": "./src/index.ts",
"types": "./src/index.ts",
"exports": {
- ".": "./src/index.ts"
+ ".": "./src/index.ts",
+ "./node-compression": "./src/nodeCompression.ts"
},
"scripts": {
"build": "tsc --noEmit",
diff --git a/packages/anthropic-compat-proxy/src/compression.ts b/packages/device-link/src/nodeCompression.ts
similarity index 71%
rename from packages/anthropic-compat-proxy/src/compression.ts
rename to packages/device-link/src/nodeCompression.ts
index c4554be703..9b39cb8d3e 100644
--- a/packages/anthropic-compat-proxy/src/compression.ts
+++ b/packages/device-link/src/nodeCompression.ts
@@ -1,9 +1,6 @@
-/** Node-only transport primitives. Policies and wire envelopes belong to callers. */
+/** Node-only device transport primitives; not exported from the cross-platform entry. */
import { performance } from 'node:perf_hooks';
-import { promisify } from 'node:util';
-import { gzip, gzipSync, gunzipSync } from 'node:zlib';
-
-const gzipAsync = promisify(gzip);
+import { gzipSync, gunzipSync } from 'node:zlib';
export interface CompressionStats {
originalBytes: number;
@@ -22,12 +19,6 @@ function result(input: Buffer, compressed: Buffer, started: number, base64: bool
return { compressed, stats };
}
-/** Large HTTP uploads use libuv rather than blocking the main event loop. */
-export async function compressGzip(input: Buffer, level: number, base64 = false) {
- const started = performance.now();
- return result(input, await gzipAsync(input, { level }), started, base64);
-}
-
/** Retains synchronous send/error contracts in existing device-link transports. */
export function compressGzipSync(input: Buffer, level: number, base64 = false) {
const started = performance.now();