feat: complete DM pairing codes with channel adapters, gateway handlers, and TUI command (Tier 4 feature 4)

This commit is contained in:
William Valentin
2026-02-09 18:28:10 -08:00
parent 9d4d440ecf
commit 1e29da4da2
11 changed files with 270 additions and 7 deletions
+42
View File
@@ -0,0 +1,42 @@
import type { GatewayRequest, OutboundMessage } from '../protocol.js';
import { makeResponse, makeError, ErrorCode } from '../protocol.js';
import type { PairingManager } from '../../channels/pairing.js';
export interface PairingHandlerDeps {
pairingManager: PairingManager;
}
export function createPairingHandlers(deps: PairingHandlerDeps) {
return {
'pairing.generate': async (request: GatewayRequest): Promise<OutboundMessage> => {
const label = request.params?.label as string | undefined;
const code = deps.pairingManager.generateCode(label);
const pending = deps.pairingManager.listPendingCodes();
const entry = pending.find(p => p.code === code);
return makeResponse(request.id, {
code,
expiresAt: entry?.expiresAt ?? null,
});
},
'pairing.list': async (request: GatewayRequest): Promise<OutboundMessage> => {
return makeResponse(request.id, {
pending: deps.pairingManager.listPendingCodes(),
approved: deps.pairingManager.listApproved(),
});
},
'pairing.revoke': async (request: GatewayRequest): Promise<OutboundMessage> => {
const channel = request.params?.channel as string | undefined;
const senderId = request.params?.senderId as string | undefined;
if (!channel || !senderId) {
return makeError(request.id, ErrorCode.InvalidRequest, 'Missing required params: channel, senderId');
}
const revoked = deps.pairingManager.revokeApproval(channel, senderId);
return makeResponse(request.id, { revoked });
},
};
}