Skip to main content

@svatah/yam-bindings

Bindings store, context hash, resolver, synthesis, fingerprint, relocalization

Exports

ExportKindSignature
assertElementIdfunctionexport function assertElementId(id: string): voidThrow unless id is well formed, naming what is wrong.
attrSimilarityfunctionexport function attrSimilarity(a: Record<string, string>, b: Record<string, string>): numberJaccard over key=value pairs.
BindingIndexEntryinterfaceexport interface BindingIndexEntryThe dictionary's view of the store: every element id with the phrases its file
BindingsStoreclassexport class BindingsStoreThe store, held in memory and written back as files.
boxProximityfunctionexport function boxProximity(How near two boxes are, in both position and size.
CandidateAttemptinterfaceexport interface CandidateAttemptWhat one candidate did when it was tried.
candidatesForfunctionexport function candidatesFor(The ranked candidates for one element, before uniqueness filtering.
contextHashfunctionexport function contextHash(The context hash for an element, or for the page when no element is named.
contextPatternfunctionexport function contextPattern(url: string, options: ContextPatternOptions = {}): stringThe URL or window pattern an entry is stored against (REQ-REC-6).
ContextPatternOptionsinterfaceexport interface ContextPatternOptionsOptions for contextPattern (config.bindings, LLD §3.5).
contextRootfunctionexport function contextRoot(The node a context is scoped to: the nearest landmark ancestor of ref,
decidefunctionexport function decide(Decide from a ranking, applying the threshold and the margin.
DEFAULT_CANDIDATE_TIMEOUT_MSvariableDEFAULT_CANDIDATE_TIMEOUT_MS = 2000Default per-candidate timeout; Config.run.candidateTimeoutMs.
DEFAULT_MARGINvariableDEFAULT_MARGIN = 0.1heal.margin — the best must beat the runner-up by this much.
DEFAULT_MAX_CANDIDATESvariableDEFAULT_MAX_CANDIDATES = 300How many elements are described and scored before giving up.
DEFAULT_THRESHOLDvariableDEFAULT_THRESHOLD = 0.72heal.relocalizeThreshold — below this, nothing is proposed.
Dictionaryclassexport class Dictionary
elementIdFromPhrasefunctionexport function elementIdFromPhrase(phrase: string): stringThe element id a target phrase normalises to (docs/flow-language.md §4): drop a
EntrySelectorinterfaceexport interface EntrySelectorHow an entry is selected for a context (LLD §6.3).
fingerprintfunctionexport async function fingerprint(The fingerprint of a live element.
fingerprintOffunctionexport function fingerprintOf(The structural fingerprint of one element (REQ-REC-4, LLD §3.3).
idToSegmentsfunctionexport function idToSegments(id: string): string[]Path segments for an id, relative to the bindings directory; the last is the file.
isElementIdfunctionexport function isElementId(id: string): booleanWhether a string is a well-formed element id.
LANDMARK_ROLESvariableLANDMARK_ROLES = [The roles that scope a context, in the order LLD §6.2 tries them: a landmark,
LocatorErrorclassexport class LocatorError extends LocateError
LocatorErrorDetailinterfaceexport interface LocatorErrorDetail
looksGeneratedfunctionexport function looksGenerated(value: string): booleanWhether a value looks machine-generated and so is not worth binding to.
Lookupinterfaceexport interface Lookup
Matchinterfaceexport interface Match
neighbourSimilarityfunctionexport function neighbourSimilarity(Neighbour text, before and after weighted equally.
pathToIdfunctionexport function pathToId(relativePath: string): stringThe id a path under the bindings directory belongs to.
patternMatchesfunctionexport function patternMatches(Whether a stored pattern applies to a URL.
rankfunctionexport function rank(Rank a set of already-described elements against a fingerprint.
readBindingIndexfunctionexport function readBindingIndex(dir: string): BindingIndexEntry[]Read a bindings directory as ids and phrases.
relocalizefunctionexport async function relocalize(Find the element a fingerprint describes, on the page as it is now.
RelocalizeOptionsinterfaceexport interface RelocalizeOptions
RelocalizeResulttypealiasexport type RelocalizeResult
Resolutioninterfaceexport interface Resolution
resolvefunctionexport async function resolve(Resolve one element id against a live surface.
ResolveOptionsinterfaceexport interface ResolveOptions
rolePathSimilarityfunctionexport function rolePathSimilarity(a: readonly string[], b: readonly string[]): numberHow alike two ancestries are: the longest common suffix, over the roles
Scoreinterfaceexport interface Score
scoreAgainstfunctionexport function scoreAgainst(Score one live element against a recorded fingerprint (LLD §6.4).
siteToolCandidatesForfunctionexport function siteToolCandidatesFor(phrase: string, elementId?: string): string[]The tool names a target might be, best first.
siteToolOffunctionexport function siteToolOf(phrase: string): string | undefinedThe site tool a target phrase names, if it names one.
subtreefunctionexport function subtree(snapshot: Snapshot, root: SnapshotNode): SnapshotNode[]The subtree under a node, in document order, with depths made relative to it.
synthesisefunctionexport async function synthesise(The ranked, verified candidate bundle for one element (REQ-REC-3).
synthesiseBundlefunctionexport async function synthesiseBundle(Candidates and fingerprint in one pass, which is what the recorder wants.
synthesiseSiteToolfunctionexport async function synthesiseSiteTool(The webmcp candidate for a target, when the page declares the tool.
SynthesisOptionsinterfaceexport interface SynthesisOptions
textSimilarityfunctionexport function textSimilarity(a: string, b: string): numberDice similarity over word tokens, with an exact-match shortcut.
tryResolvefunctionexport async function tryResolve(Try to resolve, and report rather than throw.
WEIGHTSvariableWEIGHTS The weights of LLD §6.4. They sum to 1.