MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / isClientControlMessage

Function isClientControlMessage

src/workspaces/protocol.ts:96–111  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

94// ── runtime validators (used only by the server for client→server msgs) ─────
95
96export function isClientControlMessage(value: unknown): value is ClientControlMessage {
97 if (typeof value !== 'object' || value === null) return false;
98 const v = value as Record<string, unknown>;
99 if (v['type'] === 'attach') {
100 return (
101 isNonEmptyString(v['wsId']) &&
102 isPositiveInt(v['cols']) &&
103 isPositiveInt(v['rows']) &&
104 (v['since'] === undefined || isNonNegativeInt(v['since']))
105 );
106 }
107 if (v['type'] === 'resize') {
108 return isPositiveInt(v['cols']) && isPositiveInt(v['rows']);
109 }
110 return false;
111}
112
113function isNonEmptyString(x: unknown): x is string {
114 return typeof x === 'string' && x.length > 0;

Callers 1

onWsMessageMethod · 0.85

Calls 3

isNonEmptyStringFunction · 0.85
isPositiveIntFunction · 0.85
isNonNegativeIntFunction · 0.85

Tested by

no test coverage detected