feat(gateway): add node capability negotiation foundation
This commit is contained in:
@@ -8,6 +8,16 @@ export interface GatewayRequest {
|
||||
params?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export const GATEWAY_PROTOCOL_VERSION = 1;
|
||||
|
||||
export interface NodeRegisterParams {
|
||||
connectionId: string;
|
||||
nodeId: string;
|
||||
role: string;
|
||||
protocolVersion: number;
|
||||
capabilities: string[];
|
||||
}
|
||||
|
||||
// ── Server → Client ────────────────────────────────────────────
|
||||
|
||||
export interface GatewayResponse {
|
||||
@@ -129,6 +139,37 @@ export function parseMessage(raw: string): GatewayRequest | null {
|
||||
}
|
||||
}
|
||||
|
||||
export function parseNodeRegisterParams(params: unknown): NodeRegisterParams | null {
|
||||
if (!params || typeof params !== 'object') {
|
||||
return null;
|
||||
}
|
||||
const p = params as Record<string, unknown>;
|
||||
if (typeof p.connectionId !== 'string' || !p.connectionId.trim()) {
|
||||
return null;
|
||||
}
|
||||
if (typeof p.nodeId !== 'string' || !p.nodeId.trim()) {
|
||||
return null;
|
||||
}
|
||||
if (typeof p.role !== 'string' || !p.role.trim()) {
|
||||
return null;
|
||||
}
|
||||
if (typeof p.protocolVersion !== 'number' || !Number.isFinite(p.protocolVersion) || p.protocolVersion < 1) {
|
||||
return null;
|
||||
}
|
||||
const capabilitiesRaw = p.capabilities;
|
||||
if (!Array.isArray(capabilitiesRaw) || !capabilitiesRaw.every((entry) => typeof entry === 'string')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
connectionId: p.connectionId,
|
||||
nodeId: p.nodeId,
|
||||
role: p.role,
|
||||
protocolVersion: Math.floor(p.protocolVersion),
|
||||
capabilities: capabilitiesRaw,
|
||||
};
|
||||
}
|
||||
|
||||
export function makeResponse(id: number, result: unknown): GatewayResponse {
|
||||
return { id, result };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user