hex/sdk/commands/src/protocol.ts
Kit Langton c768021ba4 feat: add typed captures to personal commands
Add bounded digit, letter, choice, union, and text captures across the TypeScript SDK, host protocol, Rust grammar, and command runtime. Validate capture schemas and invocation payloads before activation, preserve exact inferred handler types, and document the personal-command workflow.\n\nKeep modifier-only dictation events passive so Finder and other applications still receive Option state changes. Also emit balanced synthetic modifier transitions, tighten local installation behavior, and refine recording HUD responsiveness.
2026-08-03 17:04:10 -04:00

71 lines
2.2 KiB
TypeScript

import type { CaptureSchema, DictationProtocolConfig, HandlerContext, NativeAction, UntypedCaptures } from "./model.js"
export interface RegistrationCommand {
readonly id: string
readonly phrases: readonly string[]
readonly group?: string
readonly description?: string
readonly when?: { readonly application: string } | { readonly browserHost: string }
readonly captures?: CaptureSchema
readonly execution:
| { readonly type: "native"; readonly action: NativeAction }
| { readonly type: "handler" }
}
export interface RegistrationTransformation {
readonly id: string
readonly name: string
readonly description?: string
}
export interface Registration {
readonly type: "registration"
readonly protocolVersion: typeof import("./model.js").PROTOCOL_VERSION
readonly dictation?: DictationProtocolConfig
readonly transformations: readonly RegistrationTransformation[]
readonly commands: readonly RegistrationCommand[]
}
export type HostInput =
| {
readonly type: "transform"
readonly invocationId: string
readonly transformationIds: readonly string[]
readonly text: string
readonly context: HandlerContext
}
| {
readonly type: "invoke"
readonly invocationId: string
readonly commandId: string
readonly context: HandlerContext
readonly captures: UntypedCaptures
}
| {
readonly type: "toolResult"
readonly invocationId: string
readonly toolCallId: string
readonly result: { readonly type: "success" } | { readonly type: "failure"; readonly message: string; readonly code?: string }
}
| { readonly type: "shutdown" }
export type HostOutput =
| Registration
| {
readonly type: "transformationResult"
readonly invocationId: string
readonly result:
| { readonly type: "success"; readonly text: string }
| { readonly type: "failure"; readonly message: string }
}
| {
readonly type: "toolCall"
readonly invocationId: string
readonly toolCallId: string
readonly action: NativeAction
}
| {
readonly type: "invocationResult"
readonly invocationId: string
readonly result: { readonly type: "success" } | { readonly type: "failure"; readonly message: string }
}