Skip to main content

@svatah/yam-surface

The published AgentSurface interface, adapter registry and wire schemas

Exports

ExportKindSignature
ActArgstypealiastype ActArgs = z.infer<typeof actArgsSchema>;
actArgsSchemavariableactArgsSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString, "many">]>>
ActionabilityErrorclassexport class ActionabilityError extends SurfaceErrorThe element was found but was not in a state that permits the action.
ActResulttypealiastype ActResult = z.infer<typeof actResultSchema>;
actResultSchemavariableactResultSchema: z.ZodObject<
adapterDriverfunctionexport function adapterDriver(name: string): AdapterDriver | undefinedWhat name needs installed, when it needs anything.
AdapterDriverinterfaceexport interface AdapterDriverWhat an adapter needs installed before it can drive anything (PK-03).
adapterFactoryfunctionexport function adapterFactory(name: string): AdapterFactory | undefinedThe factory registered under a name, or undefined.
AdapterFactorytypealiasexport type AdapterFactory = (config: Config) => AgentSurface | Promise<AgentSurface>;Adapter registration and selection (LLD §2.4, REQ-SURF-2).
AgentSurfaceinterfaceexport interface AgentSurfaceThe agent surface (LLD §2.1, REQ-SURF-1).
ApiRequesttypealiastype ApiRequest = z.infer<typeof apiRequestSchema>;
ApiResponsetypealiastype ApiResponse = z.infer<typeof apiResponseSchema>;
APPIUM_ANDROID_ROLE_MAPvariableAPPIUM_ANDROID_ROLE_MAP: Readonly<Record<string, string>> Appium native Android class → ARIA role (REQ-ADP-5).
ATSPI_ROLE_MAPvariableATSPI_ROLE_MAP: Readonly<Record<string, string>> AT-SPI role names, onto the same vocabulary (T23, SF-23).
AX_ROLE_MAPvariableAX_ROLE_MAP: Readonly<Record<string, string>> macOS Accessibility AXRole → ARIA role (REQ-ADP-7).
AX_WINDOW_CHROME_SUBROLESvariableAX_WINDOW_CHROME_SUBROLES: ReadonlySet<string> = new Set([The window's own buttons — close, minimise, zoom, full screen, collapse.
buildSnapshotfunctionexport function buildSnapshot(Assemble a Snapshot from its nodes: renders the text and fills in the estimate.
Candidatetypealiastype Candidate = z.infer<typeof candidateSchema>;
Capabilitiestypealiastype Capabilities = z.infer<typeof capabilitiesSchema>;
capabilitiesSchemavariablecapabilitiesSchema: z.ZodObject<
CAPABILITY_FLAGSvariableCAPABILITY_FLAGS: readonly ["dialogs", "frames", "windows", "upload", "drag", "trace", "webmcp", "screenshot", "restore", "pick", "observe"]
CapabilityFlagtypealiastype CapabilityFlag = (typeof CAPABILITY_FLAGS)[number];
capabilityForActionfunctionexport function capabilityForAction(action: SurfaceAction): keyof Capabilities | undefinedThe capability an action requires, or undefined when every adapter must support it.
CheckErrorclassexport class CheckError extends SurfaceErrorA check() predicate did not hold. Maps to the assertion failure class.
CheckResulttypealiastype CheckResult = z.infer<typeof checkResultSchema>;
checkResultSchemavariablecheckResultSchema: z.ZodObject<
CheckSubjecttypealiastype CheckSubject = z.infer<typeof checkSubjectSchema>;
clearAdaptersfunctionexport function clearAdapters(): voidDrop every registration. For tests and for the REPL's session teardown.
createSurfacefunctionexport async function createSurface(config: Config): Promise<AgentSurface>Build the surface the configuration selects (LLD §2.4).
DataErrorclassexport class DataError extends SurfaceErrorA value was missing or of the wrong type (type validation, {data.*} lookups).
DialogErrorclassexport class DialogError extends SurfaceErrorA dialog was expected and absent, unexpected and present, or could not be handled.
ElementDescriptiontypealiastype ElementDescription = z.infer<typeof elementDescriptionSchema>;
elementDescriptionSchemavariableelementDescriptionSchema: z.ZodObject<What describe(ref) returns: everything candidate synthesis and fingerprinting
estimateTokensfunctionexport function estimateTokens(text: string): numberA rough token estimate for Snapshot.tokensEstimate, used to keep grounding
executableOffunctionexport function executableOf(launch: LaunchConfig, platform: string): string | undefinedThe executable a pgrep -f / taskkill addresses, for either shape.
failureClassOffunctionexport function failureClassOf(error: unknown): FailureClassThe failure class for any thrown value (LLD §8.4).
FALLBACK_ROLEvariableFALLBACK_ROLE = "generic"What an unmapped source role becomes.
hasAdapterfunctionexport function hasAdapter(name: string): boolean
INTERACTIVE_ROLESvariableINTERACTIVE_ROLES: ReadonlySet<string> = new Set([The roles that are worth acting on (LLD §2.2, §11).
isInteractiveRolefunctionexport function isInteractiveRole(role: string): boolean
isWindowChromefunctionexport function isWindowChrome(node:Is this snapshot node one of the window manager's own controls?
launchApplicationfunctionexport function launchApplication(Start the application.
LaunchConfiginterfaceexport interface LaunchConfigWhere the application is and how to start it (config.app.launch).
lengthBucketfunctionexport function lengthBucket(value: string | undefined): stringNames collapse to a length bucket: 0, 1-8, 9-32, 33+ (LLD §6.2).
LifecycleStepinterfaceexport interface LifecycleStepWhat ran, so a caller can say what it did and a test can see it.
listAdaptersfunctionexport function listAdapters(): string[]Every registered adapter name, sorted.
LOCATE_RETURN_MARGIN_MSvariableLOCATE_RETURN_MARGIN_MS = 250How long an adapter's locate may keep asking.
locateDeadlinefunctionexport function locateDeadline(candidateTimeoutMs: number | undefined, now = Date.now()): numberThe instant an adapter's retrying locate must answer by, given the
LocateErrorclassexport class LocateError extends SurfaceErrorA candidate matched no element, or matched more than one where exactly one was
missingCapabilitiesfunctionexport function missingCapabilities(The capabilities a set of actions needs but the adapter lacks. Empty means the
NavigationErrorclassexport class NavigationError extends SurfaceErrorNavigation failed, timed out, or landed somewhere unexpected.
NO_CAPABILITIESvariableNO_CAPABILITIES: Capabilities All capability flags default to false, so an adapter opts in to what it supports.
NODE_STATESvariableNODE_STATES: readonly ["disabled", "checked", "unchecked", "selected", "expanded", "collapsed", "focused", "required", "hidden", "readonly"]
NodeStatetypealiastype NodeState = z.infer<typeof nodeStateSchema>;
normalisedRolesfunctionexport function normalisedRoles(): string[]Every ARIA role any table maps onto, sorted. Useful for conformance assertions.
normaliseRolefunctionexport function normaliseRole(map: RoleMapName, sourceRole: string): stringMap one source role onto the ARIA vocabulary, falling back to generic.
ObservedEventtypealiasexport type ObservedEvent One thing a person did in the driven session (Draft 2.23, REQ-REC-13).
Predicatetypealiastype Predicate = z.infer<typeof predicateSchema>;
processIdsOffunctionexport function processIdsOf(The process ids of this executable, right now.
quitApplicationfunctionexport async function quitApplication(Stop it: the graceful route, then a signal, then a harder one.
QuitConfiginterfaceexport interface QuitConfigHow to stop it (config.app.quit).
ReadKindtypealiastype ReadKind = z.infer<typeof readKindSchema>;
Reftypealiastype Ref = z.infer<typeof refSchema>;
registerAdapterfunctionexport function registerAdapter(name: string, factory: AdapterFactory, driver?: AdapterDriver): voidRegister an adapter under a name. Registering the same name twice is an error:
renderForHashfunctionexport function renderForHash(nodes: readonly SnapshotNode[]): stringThe canonical rendering the hash is taken over: one line per node, indented by
renderNodefunctionexport function renderNode(node: SnapshotNode, options: RenderOptions = {}): stringRender one node, without its children.
RenderOptionsinterfaceexport interface RenderOptions
renderSnapshotfunctionexport function renderSnapshot(Render a whole snapshot. Nodes are emitted in the order the adapter produced
REQUIRED_SURFACE_METHODSvariableREQUIRED_SURFACE_METHODS = SURFACE_METHODS.filter(The methods every adapter must implement; trace, request, pick and observe are optional.
ROLE_MAPSvariableROLE_MAPS The published mapping tables, keyed by the adapter family they belong to.
RoleMapNametypealiasexport type RoleMapName = keyof typeof ROLE_MAPS;
Runnerinterfaceexport interface RunnerThe commands this module runs. Injected, so every path above is testable.
ScriptErrorclassexport class ScriptError extends SurfaceErrorAn evaluate or an injected script threw.
SessionErrorclassexport class SessionError extends SurfaceErrorThe session could not be opened, was lost, or the driven process crashed.
SessionInittypealiastype SessionInit = z.infer<typeof sessionInitSchema>;
sessionInitSchemavariablesessionInitSchema: z.ZodObject<
SessionStatetypealiastype SessionState = z.infer<typeof sessionStateSchema>;
sessionStateSchemavariablesessionStateSchema: z.ZodObject<The restorable subset of session state (LLD §2.1). It is what a checkpoint
Snapshottypealiastype Snapshot = z.infer<typeof snapshotSchema>;
SnapshotNodetypealiastype SnapshotNode = z.infer<typeof snapshotNodeSchema>;
snapshotNodeSchemavariablesnapshotNodeSchema: z.ZodObject<
snapshotSchemavariablesnapshotSchema: z.ZodObject<
structuralHashfunctionexport function structuralHash(nodes: readonly SnapshotNode[]): stringsha256 of renderForHash, hex encoded.
SURFACE_ACTIONSvariableSURFACE_ACTIONS: readonly SurfaceAction[]
SURFACE_ERRORSvariableSURFACE_ERRORS = [Every surface error class, in the order LLD §2.3 lists them.
SURFACE_METHODSvariableSURFACE_METHODS = [Every method name on AgentSurface, required first, then the optional ones.
SurfaceActiontypealiastype SurfaceAction = Exclude<Action, (typeof SURFACE_ONLY_EXCLUSIONS)[number]>;
surfaceActionSchemavariablesurfaceActionSchema: z.ZodEnum<["navigate", "back", "forward", "refresh", "click", "doubleClick", "rightClick", "hover", "hoverAndClick", "pressAndHold", "relea
surfaceActMessageSchemavariablesurfaceActMessageSchema: z.ZodObject<surface.act.schema.json — request and response of act().
surfaceCapabilitiesMessageSchemavariablesurfaceCapabilitiesMessageSchema: z.ZodObject<surface.capabilities.schema.json — the descriptor an adapter publishes.
surfaceCheckMessageSchemavariablesurfaceCheckMessageSchema: z.ZodObject<surface.check.schema.json — request and response of check().
SurfaceErrorclassexport abstract class SurfaceError extends ErrorThe typed errors adapters throw (LLD §2.3).
SurfaceKindtypealiastype SurfaceKind = z.infer<typeof surfaceKindSchema>;
surfaceLocateMessageSchemavariablesurfaceLocateMessageSchema: z.ZodObject<surface.locate.schema.json — candidate in, references out (used by the resolver).
SurfaceMethodtypealiasexport type SurfaceMethod = (typeof SURFACE_METHODS)[number];
surfaceReadMessageSchemavariablesurfaceReadMessageSchema: z.ZodObject<surface.read.schema.json — request and response of read().
surfaceSnapshotMessageSchemavariablesurfaceSnapshotMessageSchema: z.ZodObject<surface.snapshot.schema.json — request and response of snapshot().
systemRunnervariablesystemRunner: Runner
TimeoutErrorclassexport class TimeoutError extends SurfaceErrorAn operation exceeded its configured timeout.
UIA_ROLE_MAPvariableUIA_ROLE_MAP: Readonly<Record<string, string>> Windows UI Automation ControlType → ARIA role (REQ-ADP-6).
UIA_WINDOW_CHROME_IDSvariableUIA_WINDOW_CHROME_IDS: ReadonlySet<string> = new Set([What Windows calls the same three, as AutomationIds.
unregisterAdapterfunctionexport function unregisterAdapter(name: string): booleanRemove a registration. Returns false when the name was not registered.
waitForfunctionexport async function waitFor(Wait for a condition, and say how long it took.