mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 00:02:31 +00:00
* chore(dead-code): drop 2k lines of unreachable exports and orphan modules Ran knip across every build entry (main, preload, renderer, popout, web, cli, relay, workers, forked sidecars, config scripts) and removed what no entry graph can reach. - 11 orphan modules nothing imported, plus one test that only covered them - 159 unused exports/types, with their now-dead helpers, imports and tests Each candidate was verified against dynamic references before deletion. 42 knip hits were false positives and are kept: shared modules consumed by the mobile/ workspace, the src/shared/plugins/** public API, vendored shadcn primitives, and relay wire-protocol constants held for compatibility. Adds knip.json + `pnpm audit:dead-code` so this stays measurable. Verified: pnpm typecheck, pnpm lint, and 2081 tests across the 73 affected test files all pass. * chore(dead-code): move knip config under config/ Root-level additions are blocked by the root directory guard. Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai>
82 lines
3.1 KiB
TypeScript
82 lines
3.1 KiB
TypeScript
import {
|
|
JsonStringifyByteLimitError,
|
|
stringifyJsonWithinByteLimit
|
|
} from './node-bounded-json-stringify'
|
|
import { RemoteRuntimeClientError } from './remote-runtime-client-error'
|
|
|
|
export const REMOTE_RUNTIME_MAX_OUTBOUND_JSON_BYTES = 4 * 1024 * 1024
|
|
export const REMOTE_RUNTIME_MAX_WEBSOCKET_FRAME_BYTES = 8 * 1024 * 1024 + 64
|
|
export const REMOTE_RUNTIME_MAX_SUBSCRIPTIONS = 256
|
|
export const REMOTE_RUNTIME_MAX_SUBSCRIPTION_PARAM_BYTES = 1024 * 1024
|
|
export const REMOTE_RUNTIME_MAX_RETAINED_SUBSCRIPTION_BYTES = 16 * 1024 * 1024
|
|
export const REMOTE_RUNTIME_MAX_PENDING_REQUESTS = 256
|
|
export const REMOTE_RUNTIME_MAX_PENDING_RPC_BYTES = 32 * 1024 * 1024
|
|
export const REMOTE_RUNTIME_MAX_PREPARED_RPC_BYTES = REMOTE_RUNTIME_MAX_PENDING_RPC_BYTES
|
|
export const REMOTE_RUNTIME_MAX_PROCESS_PENDING_REQUESTS = REMOTE_RUNTIME_MAX_PENDING_REQUESTS * 2
|
|
export const REMOTE_RUNTIME_MAX_PROCESS_PENDING_RPC_BYTES = REMOTE_RUNTIME_MAX_PENDING_RPC_BYTES * 2
|
|
export const REMOTE_RUNTIME_MAX_READY_WAITERS =
|
|
REMOTE_RUNTIME_MAX_PENDING_REQUESTS + REMOTE_RUNTIME_MAX_SUBSCRIPTIONS
|
|
export const REMOTE_RUNTIME_MAX_OUTBOUND_BINARY_FRAME_BYTES = 8 * 1024 * 1024
|
|
|
|
export function serializeRemoteRuntimePayload(value: unknown): string {
|
|
try {
|
|
return stringifyJsonWithinByteLimit(value, REMOTE_RUNTIME_MAX_OUTBOUND_JSON_BYTES).serialized
|
|
} catch (error) {
|
|
if (error instanceof JsonStringifyByteLimitError) {
|
|
throw new RemoteRuntimeClientError(
|
|
'invalid_argument',
|
|
`Remote runtime JSON payload exceeds ${REMOTE_RUNTIME_MAX_OUTBOUND_JSON_BYTES} bytes.`
|
|
)
|
|
}
|
|
const message = error instanceof Error ? error.message : String(error)
|
|
throw new RemoteRuntimeClientError(
|
|
'invalid_argument',
|
|
`Remote runtime JSON payload could not be serialized: ${message}`
|
|
)
|
|
}
|
|
}
|
|
|
|
export function measureRemoteRuntimeSubscriptionParams(params: unknown): number {
|
|
if (params === undefined) {
|
|
return 0
|
|
}
|
|
try {
|
|
return stringifyJsonWithinByteLimit(params, REMOTE_RUNTIME_MAX_SUBSCRIPTION_PARAM_BYTES)
|
|
.byteLength
|
|
} catch (error) {
|
|
if (error instanceof JsonStringifyByteLimitError) {
|
|
throw new RemoteRuntimeClientError(
|
|
'invalid_argument',
|
|
`Remote runtime subscription parameters exceed ${REMOTE_RUNTIME_MAX_SUBSCRIPTION_PARAM_BYTES} bytes.`
|
|
)
|
|
}
|
|
const message = error instanceof Error ? error.message : String(error)
|
|
throw new RemoteRuntimeClientError(
|
|
'invalid_argument',
|
|
`Remote runtime subscription parameters could not be serialized: ${message}`
|
|
)
|
|
}
|
|
}
|
|
|
|
export function serializeRemoteRuntimeRpcRequest(args: {
|
|
requestId: string
|
|
deviceToken: string
|
|
method: string
|
|
params: unknown
|
|
}): string {
|
|
return serializeRemoteRuntimePayload({
|
|
id: args.requestId,
|
|
deviceToken: args.deviceToken,
|
|
method: args.method,
|
|
params: args.params
|
|
})
|
|
}
|
|
|
|
export function retainedRemoteRuntimeJsonStringBytes(value: string): number {
|
|
return value.length * 3
|
|
}
|
|
|
|
export function isRemoteRuntimeBinaryFrameWithinLimit(bytes: Uint8Array<ArrayBufferLike>): boolean {
|
|
return bytes.byteLength <= REMOTE_RUNTIME_MAX_OUTBOUND_BINARY_FRAME_BYTES
|
|
}
|