import type { HqClientCapability, HqClientMessage } from './client.js'; import type { HqQueuedCommand } from './fleet.js'; import { type HqServerKanbanSnapshotMessage } from './kanban.js'; import type { HqRedactionPolicy } from './tool.js'; export declare const HQ_PROTOCOL_VERSION: 1; export type HqProtocolVersion = typeof HQ_PROTOCOL_VERSION; export interface HqWelcomePayload { type: 'hq.welcome'; protocolVersion: HqProtocolVersion; serverTime: string; acceptedCapabilities: readonly HqClientCapability[]; redactionPolicy: HqRedactionPolicy; } export interface HqEventEnvelope { id: string; type: HqEventType | (string & {}); schemaVersion: HqProtocolVersion; timestamp: string; clientId: string; projectId: string; sessionId?: string; runId?: string; seq: number; payload: TPayload; } export type HqEventType = 'client.hello' | 'client.heartbeat' | 'session.started' | 'session.status' | 'session.usage' | 'tool.started' | 'tool.completed' | 'fleet.snapshot' | 'fleet.event' | 'mailbox.snapshot' | 'mailbox.event' | 'kanban.snapshot' | 'worklist.snapshot' | 'git.snapshot' | 'agent.message' | 'agent.status' | 'session.snapshot' | 'session.transcript' | 'session.ended' | 'brain.event' | 'worktree.event' | 'mcp.health.snapshot' | 'mcp.operation'; export interface HqUsagePayload { inputTokens?: number; outputTokens?: number; totalTokens?: number; costUsd?: number; durationMs?: number; /** Provider id that produced this usage (e.g. 'anthropic'), when known. */ provider?: string; /** Model id the cost was priced against, when known. */ model?: string; /** Cache-read (prompt-cache hit) tokens, when reported. */ cacheRead?: number; /** Cache-write tokens, when reported. */ cacheWrite?: number; } /** A physical machine, aggregated by HQ from connected clients' machineId. */ export interface HqMachineRecord { machineId: string; hostname?: string; clientCount: number; sessionCount: number; agentCount: number; projectIds: readonly string[]; lastActivityAt: string; } export interface HqGitSnapshotPayload { branch?: string; dirtyFiles?: number; stagedFiles?: number; ahead?: number; behind?: number; } export interface HqAlertMessage { type: 'hq.alert'; severity: 'info' | 'warn' | 'error'; message: string; timestamp: string; } export interface HqHeartbeatMessage { type: 'hq.heartbeat'; serverTime: string; } export interface HqServerCommandBatchMessage { type: 'hq.command_batch'; commands: readonly HqQueuedCommand[]; } export type HqServerMessage = HqServerCommandBatchMessage | HqServerKanbanSnapshotMessage | HqWelcomePayload; /** * Discriminated parse result for {@link parseHqFrame}. The `reason` field * is only present when `ok` is `false`; consumers should narrow on `ok` * before accessing `frame` or `reason`. */ export type HqParseResult = { ok: true; frame: HqClientMessage; } | { ok: false; reason: 'invalid-json' | 'unknown-type' | 'malformed'; }; /** * Strictly parse a raw client → server frame into a {@link HqParseResult}. * * Validates, in order: * 1. JSON syntax (`invalid-json` on failure) * 2. Top-level object with string `type` discriminator * 3. `type` is one of {@link HqClientMessage} union members (`unknown-type`) * 4. Per-type field-shape presence checks (`malformed` on failure) * * On success, `frame` is narrowed to {@link HqClientMessage} and consumers * can switch on `frame.type` for type-safe access to per-union-member * fields without `as` casts. */ export declare function parseHqFrame(raw: string | Buffer): HqParseResult; /** * Validate the `payload` field of a {@link HqEventEnvelope} for known * event types. Returns `{ ok: true, payload }` with a narrowed payload * type when the event type has a registered shape guard and the payload * matches it; `{ ok: true, payload: unknown }` for event types that the * server does not yet validate; or `{ ok: false, reason }` when the * payload fails the registered guard. * * Use this after {@link parseHqFrame} has produced a valid frame, when * the frame is `client.event` and the server is about to consume the * event payload. */ export type HqEventPayloadResult = { ok: true; payload: T; } | { ok: false; reason: 'unknown-event-type' | 'malformed-payload'; }; export declare function parseHqEventPayload(eventType: string, payload: unknown): HqEventPayloadResult; export declare function createHqEventEnvelope(input: { id: string; type: HqEventType | (string & {}); timestamp: string; clientId: string; projectId: string; seq: number; payload: TPayload; sessionId?: string; runId?: string; }): HqEventEnvelope; //# sourceMappingURL=core.d.ts.map