Skip to content

Hook reference ​

Everything your code can provide to Kav with Kav.provide(name, hook), every field Kav hands it, and every answer it may give. Input and answer are JSON text. Kav calls a hook on a thread of its own, never the main one, within the hook's deadline. Taken from Kav 5's code, paths under android/app/src/main/java/uk/noammm/kav/: ext/Hooks.kt, ext/NativeRules.kt, ext/Pipeline.kt, ext/BoardAnswers.kt, data/KavPlan.kt. If this page and the code disagree, the code is right; please report it.

A hook only runs when the manifest declares its contribution (native.md has the table). Cards, pages, settings and themes have a page of their own: screens.md.

kotlin
kav.provide("results.annotate") { input ->
    val routes = JSONObject(input).getJSONArray("routes")
    val out = JSONArray()
    for (i in 0 until routes.length()) out.put(JSONArray().put("quiet"))
    out.toString()
}

The five route rules ​

After a planner answers a search, Kav puts the routes through the rules the rider switched on, in this order: walking model, transfer policy, filters, ranker, annotators (ext/Pipeline.kt). A rider has at most one walking model, one transfer policy and one ranker; filters and annotators run in the order they were switched on.

Each rule is one call per search with every route in it. The input is the whole search:

FieldWhat it is
queryWhat was asked (below).
routesEvery route being judged.
walksEvery walk in those routes.
transfersEvery change in those routes.

A rule answers a JSON array for one of those lists: walk.time for walks, transfer.policy for transfers, the other three for routes. The array has exactly one entry per item, in the same order. Any other length, or an answer that isn't an array, is refused and the rule is skipped for that search.

Taxi cards (a route with a taxi leg and no ride) are never sent to a rule and keep their places.

query ​

FieldTypeWhat it is
waystring"d" leaving at a time, "a" arriving by a time, "l" the last way there tonight.
atnumberThe time asked about, in seconds since 1970 (UTC). When the rider asked to leave now, the time of the search.
nownumberWhen the search was made, same unit.
settingsstringThe rider's own planner settings, four letters (data/PlanSettings.kt): pace s slow, n usual, f fast; walking l less, n usual, m more; changes n usual, f fewer; time to spare t tight, n usual, r relaxed. The usual is "nnnn".
localestring"he" or "en".

A route ​

FieldTypeWhat it is
indexnumberIts place in routes. This is the number a ranker answers with.
providerstringWhose plan it is: an extension planner's namespace, or "" for Kav's own server.
dep, arrnumberWhen the rider leaves and arrives, seconds since 1970.
farenumberThe fare as the planner gave it (Kav's own server gives agorot), or -1 when it isn't known.
accessiblebooleanWhether the planner marked the route accessible.
tagsstring[]The tags on the route so far: the planner's and Kav's own (below), and other extensions' as x:<namespace>:<contribution>:<tag>.
legsobject[]The legs, in order.

Kav's own tags (data/KavPlan.kt and data/TripPlanner.kt): early_arrival, latest_departure, direct, least_walking, low_transfer, last_departure, long_walk, long_wait_time, risky_transfer (shown as "Tight connection"), likely_missed, high_frequency, flexible_route, after_shabbat, after_holiday.

A card on a trip's page and a line under a search result are told about their route in this same shape (screens.md).

A leg ​

FieldTypeWhat it is
kindstring"walk", "wait", "ride", "taxi", "bike" or "other".
dep, arrnumberSeconds since 1970.
metresnumberIts length. 0 when the planner gave none.
insideMetresnumberFor a walk: how many of its meters are inside a station. 0 when the planner gave none.
insideSecondsnumberFor a walk: how many of its seconds are the station's own time inside it, from its entrance to its platforms (a fixed time for each station, not its meters at a pace). 0 when the planner gave none. Kav 5.2.5 and older don't give it.
from, toobjectWhere it starts and ends: { stop, name, lat, lon }. stop is a stop's reference (below) or null for a place that is not a stop; name the stop's name or null; lat and lon are degrees, to six decimals, and 0 when unknown.
linestring or nullFor a ride: its line's reference. null for every other leg.
lineNumberstring or nullFor a ride: the line's number as riders know it. May be "". null for every other leg.
modenumberFor a ride: the line's route type as its planner gave it. 2 is a train (Kav treats it as one), 3 a bus (what Kav assumes when a planner says nothing). -1 when the line isn't known, and for every other leg.
tripstring or nullFor a ride: the trip's reference, null when Kav has none for it. null for every other leg.
stopsnumberFor a ride: how many stops it calls at, counting the first and the last. 0 otherwise.
stopListobject[]For a ride: the stops it calls at, first to last, each { stop, name, lat, lon } as from and to are. Empty for every other leg. Kav 5.2.4 and older don't give it.
shapestringThe leg's road as a Google encoded polyline at five decimal places (the encoding a planner's shape already has). For a ride it runs from the stop it's boarded at to the one it's left at. "" when Kav has no road for the leg. Kav 5.2.4 and older don't give it.
liveDep, liveArrnumber or nullAPI 5. For a ride: when Kav's live times have it leave the stop it's boarded at and get to the one it's left at, in seconds since 1970. null without a live time, and for every other leg.
turnsobject[]API 5. For a walk: its turns as its planner gives them, each { way, street, metres, lat, lon }: way OpenTripPlanner's relative direction (DEPART, LEFT, SLIGHTLY_RIGHT, CONTINUE...), street the street it goes onto ("" for a path with no name), metres how far along it. Empty for a walk without them and for every other leg.

A wait comes before each ride. It is at one stop, the one the ride leaves from: its from and to are both that stop.

A reference names a thing in someone's data (ext/Contracts.kt): publisher/dataset/kind/localId, where kind is stop, route, trip or agency. The Ministry of Transport's own are il.mot/gtfs/stop/<stop code>, il.mot/gtfs/route/<route id> and il.mot/gtfs/trip/<trip id>. In the local id, %, / and # are written %25, %2F and %23. The same local id from two publishers is two different things.

walk.time: a walking model ​

Answers for walks. A walk:

FieldTypeWhat it is
routenumberThe route it is in (routes[route]).
legnumberWhich leg of that route it is.
rolestring"access" before the first ride, "transfer" between two, "egress" after the last, "only" when the route has no ride at all.
metresnumberIts length.
insideMetresnumberHow many of those meters are inside a station.
plannedSecnumberHow long the planner gave it, in seconds.
fromKind, toKindstringWhat is at each end: "place", "stop", or "station" (a train's stop).

Answer: for each walk, its time in seconds: a number, or {"sec": number}. Kav rounds it to a whole second.

kotlin
kav.provide("walk.time") { input ->
    val walks = JSONObject(input).getJSONArray("walks")
    JSONArray().apply { for (i in 0 until walks.length()) put(walks.getJSONObject(i).getInt("metres") / 1.2) }.toString()
}

What Kav does with it:

  • It takes the times as they are. It never cuts one back towards the planner's time.
  • It refuses the whole answer when any time is negative. Whether a walk is believable is your business.
  • It then checks every route again on the same timetable. If the walks before the first ride no longer fit, the rider leaves earlier, but never before the time they asked to leave at (or before now). If a change can no longer be made, or an arrive-by time is missed, the route leaves the list. It is only counted, as "1 route isn't catchable with your walking settings"; it is never shown lower down.
  • When any time changed or a route left, it works its own tags out again for the routes that are left. A model that answers with the planner's own times changes nothing, tags included.

Deadline: 200 ms.

transfer.policy: how changes are judged ​

Answers for transfers: every change from one ride to the next where only walking and waiting come between, except a change at a stop the rider asked to stay at. A change:

FieldTypeWhat it is
routenumberThe route it is in.
fromLeg, toLegnumberThe ride arrived on and the ride boarded.
fromMode, toModenumberTheir route types (2 a train, 3 a bus, -1 unknown).
walkMetresnumberThe walking between them, in meters.
walkSecnumberThat walking's time: the walking model's when one answered, else the planner's.
gapSecnumberThe time in hand: from arriving to the next ride leaving, less walkSec. Can be negative.
sameStopbooleanWhether the rider gets off and boards at the same stop.
fromStop, toStopstring or nullThe two stops' references.

Answer: for each change, one of

AnswerMeaning
a numberThat many seconds to spare, as a hard rule.
{"minSpareSec": n, "hard": b}minSpareSec seconds to spare (default 0). hard defaults to true; only false makes it soft.
{"forbid": "why"}The route is hidden, whatever its times.
nullNo spare asked: the same as 0.

What Kav does with it:

  • minSpareSec must be from 0 to 86,400 (a day), or the whole answer is refused.
  • Hard: the walk plus the spare must fit before the next ride leaves, or the route is dropped and counted as not catchable.
  • Soft: the route stays; when the spare doesn't fit, Kav puts its own "Tight connection" tag on it.
  • Forbid: the route is dropped and counted as hidden ("1 route hidden by your extensions' rules"). A reason given as text is shown to the rider with that count; see "Reasons" below. "forbid": true forbids with no reason.
  • When the policy changes nothing (no route dropped, no time moved), the routes stay exactly as they came: Kav does not work its own tags out again. A soft spare that doesn't fit still adds "Tight connection".

Deadline: 150 ms.

results.filter: hiding routes ​

Answers for routes: the routes left after the walking model and the transfer policy, or after the filter before this one.

Answer: for each route, false or a string (the reason) to drop it. Anything else keeps it. Dropped routes are counted as hidden, and a reason is shown to the rider with that count.

Reasons, and the row of hidden routes ​

Kav keeps every route a rule left out, with the rule and the reason it gave. Under the routes the rider then sees a quiet row: how many were hidden and by which extension ("2 routes hidden by "Calm changes""), your reasons in a small line under it, as you gave them, each once, and a Show button that shows the hidden routes this once, after the kept ones (ui/ExtHiddenRoutes.kt). Nothing is judged again and nothing is remembered. Write a few plain words: the row shows two lines of reasons at most.

Deadline: 150 ms.

Called with the routes of Kav's main list only, and only when there are at least two.

Answer: the routes' index values in the order you want them: each a number, or an object with an index. Every index must appear exactly once. Anything else is refused and Kav keeps its own order.

A ranker is never required: when it fails or is late the search is shown without it.

Deadline: 150 ms.

results.annotate: tags on routes ​

Answers for routes.

Answer: for each route, a list of tags, or {"tags": [...]}, or anything else for none. A tag is any text; Kav takes up to 64 per route, drops blank ones and repeats, and shows every one after its own tags, kept as the extension's (x:<namespace>:<contribution>:<tag>), so it is never taken for one of Kav's.

A tag the manifest declares under tags shows with the words declared there, in the rider's language:

json
"tags": { "quiet": { "en": "Quiet streets", "he": "רחובות שקטים" } }

Any other tag shows as its own text.

Deadline: 150 ms.

Time, failure, and "required" ​

  • The five rules share 400 ms for the whole search, counted from the planner's answer. Each hook gets what is left, up to its own limit above. Kav shows its own routes first and applies the rules' changes when they arrive.
  • With less than 20 ms left a hook is not asked at all: an optional rule is skipped for that search, a required one fails it visibly.
  • A rider can mark a walking model, a transfer policy or a filter required. Kav switches a walking model and a transfer policy on as required, and a filter as optional. When a required rule fails, is late, or its extension is off, the search shows no routes and says so ("Can't use your walking rules (...) right now, so no routes are shown"), with a way to see the routes unjudged. An optional rule is skipped with a note ("Shown without ...: it didn't answer in time").
  • A late or unreadable answer is written to the extension's log and skipped. Kav switches nothing off for it. A hook that throws is also counted as a crash (native.md, "The crash guard and safe mode").
  • A late hook is not stopped: Kav stops waiting and leaves it to finish. Keep rules quick.

plan.provide: a planner ​

Declared as a contribution with capability plan.provide. Kav asks it instead of its own planner when the rider picks it. Deadline: 30 seconds.

The input (ext/Hooks.kt, NativePlanner):

FieldTypeWhat it is
from, to[lat, lon]Where from and where to, in degrees. Kav never sends a place's name.
atnumberThe time asked about, seconds since 1970.
waystring"d", "a" or "l", as in a query above.
modesnumber[]The route types the rider wants.
settingsstringThe rider's four settings letters.

It answers a plan, or null for no routes. Kav reads the plan with its own plan reader (data/KavPlan.kt, parse) and treats every id in it as the extension's own. A trip with stops on the way is planned part by part and joined by Kav.

The smallest plan Kav's own test planner returns (android/app/src/debug/java/uk/noammm/kav/ext/Fixtures.kt) has this shape:

json
{
  "stops": { "17038": ["17038", "Gamma Pier", 32.083, 34.783] },
  "agencies": { "5": "Gamma Lines" },
  "lines": { "7": ["7", "Gamma Market", "", "Gamma Pier", "", 5, 3, ""] },
  "it": [{
    "dep": 1795420860, "arr": 1795422780,
    "legs": [
      { "k": "w", "dep": 1795420860, "arr": 1795421100, "m": 300, "shape": "..." },
      { "k": "r", "line": "7", "trip": "1994912", "dep": 1795421100, "arr": 1795421700, "sdep": 1795421100, "stops": ["17038", "25565"], "shape": "..." }
    ]
  }]
}
  • stops: id to [code, name, lat, lon].
  • agencies: operator id to name.
  • lines: id to [number, to, to city, from, from city, operator id, route type, the operator's own name for the line].
  • it: the routes. A leg's k is "w" for a walk (m its meters, im its meters inside a station) or "r" for a ride.
  • shape is a polyline in Google's encoding at five decimals.

The plan reader takes more than this (alternatives, fares, tags, sections, turns). That part of the contract is not written up here yet.

Every planner's answer is read as plumbing (ext/PlanChecks.kt, data/KavPlan.kt):

  • One ceiling: the whole answer may be at most 262,144 characters. Past it, it is refused whole, and the rider is told the planner answered something Kav can't read as routes.
  • Your words are shown as you gave them: stop names, line ends, operators, street names, tags. Kav's screens cut what doesn't fit.
  • Ids of any length. Kav keeps an id (a stop's, a line's, a trip's, an operator's) over 64 characters as a short stand-in made from it ("~" and 24 hex characters of its SHA-256), the same one every time, so nothing breaks; but the id your route rules or a later call see for it is the stand-in, not yours.
  • Only routes Kav can draw: a route is dropped when it has no legs, ends before it starts, or has a leg that ends before it starts or starts before the leg before it ended. Whether a route is sensible (a fast walk, a day-long ride, a time other than the one asked) is your business.

When every route is dropped the rider is not told "no routes": they are told the planner answered routes Kav can't show. What Kav sends the rider's route rules about your routes must also fit 512 KB; an answer that comes to more is refused whole as too large. Short ids and no more stops and shape than a route needs keep you far from it.

Ids in your plan are your own: an id that looks like the ministry's is not taken for the ministry's, so its rides get no live times from the ministry. Their own board provider supplies live times as described below.

Timetables and stop boards: board.provide ​

A contribution with capability board.provide gives Kav stops of its own and what leaves them. Riders find those stops in the Stops tab, in search and nearby, after Kav's own, with no mark of yours; opening one shows Kav's stop board filled with your times, refreshed every 30 seconds; and a rider can save the stop like any other (ext/Hooks.kt, NativeBoard). Kav asks only the stop's own publisher about it, wherever it shows departures.

The timetable may be inside your code, or read from a server with Android's own networking. You provide two hooks.

board.stops: the stops and lines ​

Asked once per release, and the answer is kept. The input is {}.

kotlin
kav.provide("board.stops") { _ ->
    """{"stops": [{"id": "old-quay", "name": "Old Quay", "lat": 32.8201, "lon": 34.9712, "code": "Q1", "mode": 4}],
        "lines": {"blue": {"number": "B", "name": "Old Quay to Lighthouse Island", "mode": 4}}}"""
}
FieldRule
stops[].idYour own id for the stop: text of 1 to 128 characters, or a whole number. No control characters, no tabs or line breaks. Unique. Kav never mixes it with another publisher's or its own.
stops[].nameNeeded: text, not empty. Shown as you gave it.
stops[].lat, lonNeeded: degrees, within -90 to 90 and -180 to 180.
stops[].codeOptional: the code riders know the stop by. A search for exactly this finds the stop.
stops[].modeOptional: the kind of stop, as a route type from 0 to 12 (0 tram, 1 metro, 2 train, 3 bus, 4 ferry, 5 cable car, 6 gondola, 7 funicular). Default 3.
linesOptional: an object, each key a line's id. number, name and mode, each as above.

At most 200,000 stops and 20,000 lines. An answer with no stops means the provider offers nothing.

Deadline: 60 seconds.

board.departures: one stop's board ​

Called when a rider opens one of your stops, and again as the board refreshes:

FieldTypeWhat it is
stopstringThe stop's id, as you gave it.
fromnumberSeconds since 1970: departures from this time on are wanted.
limitnumberHow many Kav will take.

Answer: an array of departures, or null for none.

FieldRule
lineNeeded: the id of a line.
timeNeeded: the timetable's time, whole seconds since 1970, above 0 and not after 4102444800 (the start of the year 2100).
estimatedOptional: the time now expected, when you know better than the timetable. Leave it out when you don't: a null here is refused.
tripOptional: your id for the trip. Without one Kav makes one from the line and the time. Leave it out when you have none: a null is refused.
platformOptional.
headsignOptional: where it goes. Leave it out when the line's name says it.

Kav sorts the list itself, soonest first, by estimated when there is one.

What Kav does with an answer (ext/BoardAnswers.kt): it checks every field. Anything outside the rules above, or more departures than limit, makes the whole answer malformed, and a malformed answer is shown as a provider that could not answer, never as an empty board. Only null or an empty array is an empty board.

Deadline: 30 seconds.

samples/native/native-rules has a stop board for two stops of its own.

What is not here yet ​

  • The full shape of a plan (alternatives, fares, tags, sections, turns): see plan.provide above.
  • Saving one of your lines: Kav has no page for an extension's line yet, so only stops can be saved.

Planner tabs and display settings ​

Each extension planner the rider switches on gets a tab of its own on the results, beside Kav's: its key is ext:<publisher>/<dataset> and its label is your extension's name. A search asks every tab's planner at once, so a tab opens on its routes as soon as they're in. In Settings › Privacy › Routes from every planner the rider orders the tabs, hides one, and picks the tab results open on; Kav's own tab can be hidden while an extension's is left. While your extension is switched off its tab stays and says it didn't answer, so the rider is never shown another planner's routes in its place. A rider who had chosen one extension's planner before tabs keeps it: it gets its tab, and results open on it.

The part results.planners gets {"source": "<the tab shown>", "sources": ["kav", "ext:<publisher>/<dataset>", ...]}. The action results.planner.select shows a tab:

kotlin
kav.kavAction("results.planner.select", kav.context(), """{"source": "ext:example/planner"}""")

With "default": true it is also the tab results open on from then, whether results are showing or not, as if the rider picked it in Settings (where they can change it back).

The rider's display settings. Kav sends them as prefs in every plan.provide and stop.photo request, and kav.prefs() (API 5) answers them at any time:

json
{"stopNames": "en", "clock": 24, "locale": "en"}

stopNames is "en" or "he", the language the rider reads stop names in; clock is 12 or 24; locale is Kav's language, as kav.locale(). Ask again when you need them: the rider can change them at any time. kav.prefs() needs "api": 5 in the manifest, or check kav.apiVersion() >= 5 before calling it: an older Kav has no such method.

Live times, vehicles and ride alerts (plan 2.1, board 1.1) ​

Each of these is optional: a plan 2.0 or board 1.0 answer stays as it was.

Live times. In a plan, a ride's dep is when it leaves and sdep its timetabled time (dep when left out). "live": true says dep is a live estimate; without it, a dep that isn't sdep is shown as an expected time, not a live one. next and before are the line's later and earlier departures from the boarding stop, each [unix seconds, trip id], with a third item 1 when that time is live: the ride's card lists them.

Once the results show, Kav keeps a ride's times fresh from its boarding stop's board: it asks the same extension's board.departures for that stop, and matches each departure by its line and trip ids. Use the same stop, line and trip ids in your plan and on your board, and give each departure an estimated time when you have one. Without board.provide, the plan's own times stay.

Vehicles. A plan's ride and a board's departure can each say where the bus or train is:

json
"vehicle": {"lat": 32.0853, "lon": 34.7818, "at": 1795421100, "bearing": 90}

lat and lon in degrees; at when it was there, in unix seconds (left out: when you answered); bearing its heading in degrees from north (optional). A ride with a vehicle gets Kav's Live location button, on its trip page and on its card. A board's position replaces the plan's, so a board that is asked again keeps the bus moving; a vehicle with coordinates out of range is left out.

Alerts. A plan's ride can carry a service alert:

json
"alert": {"text": "Board at the temporary stop on Herzl Street.", "severe": false}

Kav shows it in its own alert row, on the results, the trip page and while navigating, with the warning color when severe is true. Empty text is no alert.

Stop photos: stop.photo ​

A photo of a stop, in place of Street View's. Declare a contribution with the capability stop.photo, and answer it in code:

kotlin
kav.provide("stop.photo") { input ->
    val o = JSONObject(input)  // {"lat": 32.0853, "lon": 34.7818, "stop": {"code": "778", "id": "s778"}, "prefs": {...}}
    val mine = o.optJSONObject("stop")?.optString("id")?.takeIf { it.isNotEmpty() }
    val url = if (mine != null) photoOf(mine) else photoNear(o.getDouble("lat"), o.getDouble("lon"))
    if (url == null) "null" else JSONObject.quote(url)
}

Kav always sends the place the photo shows (lat, lon). When Kav knows which stop it is, it adds stop: its code (the code riders see), and, for one of your own stops (one your plans or boards returned), id, your own id for it, exactly as you sent it. Another extension's stop comes as the place only. A Kav from before stop ids sends the place only, so fall back to it. Your code starts afresh each time Kav starts, so keep what you need (a file under kav.context(), or your own stop list) rather than only what your last plan returned.

Answer an https image address as a JSON string, or null for none. Kav asks each extension with stop.photo in turn, within 3 seconds each; the first image that loads is shown, small on the stop's row and large when the rider taps it. With none, Kav shows Street View's, as before, and keeps the photo it showed for that place until Kav restarts. An image is at most 5 MB, in a format Android reads (JPEG, PNG or WebP); Kav scales it down to what it shows. Kav asks only while the rider has stop photos on, and logs why an answer wasn't used (tag KavStopPhoto in adb logcat). A Kav from before stop.photo ignores the contribution.

The rider's trips: trips.history and trips.follow (API 5) ​

Two capabilities give an extension the rider's trips. Each is a contribution in the manifest, and each has its own line on your extension's page ("Reads your recent trips, if you allow it", "Follows the trips you take, if you allow it") and its own switch there, off until the rider turns it on: "Read your trip history" and "Follow your trips". Kav never turns them on for the rider. Turned off, Kav stops at once: kav.trips() gives null again, and no more events come.

json
"contributions": [
  {"id": "history", "capability": "trips.history"},
  {"id": "follow", "capability": "trips.follow"}
]

Trip history: kav.trips(). The trips of Kav's Recent trips list (Home › Recent trips), newest first, as JSON text, or null while the rider hasn't allowed it:

json
[{"from": {"name": "Home", "detail": "Herzl 1", "lat": 32.0853, "lon": 34.7818},
  "to": {"name": "Azrieli", "detail": "Tel Aviv", "lat": 32.0745, "lon": 34.7920},
  "stopovers": [], "at": 1795421100, "planner": ""}]

from is null for a trip from where the rider was. at is when the rider searched it, in Unix seconds. planner is the extension that planned it ("ext:<publisher>/<dataset>"), or "" for Kav's own planners. Ask again when you need it: the list changes with every search. Without a trips.history contribution kav.trips() throws.

Following trips: kav.onTrip(listener). Told about the trip the rider follows (Start on a trip's page) as it changes, on a thread of Kav's, never the main one:

kotlin
kav.onTrip { event ->
    val e = JSONObject(event)
    kav.log("${e.getString("event")}: step ${e.getJSONObject("step").getString("kind")}")
}
json
{"event": "step", "from": "Home", "to": "Azrieli",
 "trip": {"provider": "", "dep": 1795421100, "arr": 1795422900, "legs": [...]},
 "step": {"index": 2, "count": 6, "kind": "wait", "legIndex": 1, "leg": {"kind": "ride", "lineNumber": "18", ...},
          "alightAt": 1795422300, "shown": 2},
 "steps": [{"kind": "start", "legIndex": -1, "line": null, "place": "Home"},
           {"kind": "walk", "legIndex": -1, "line": null, "place": "Allenby"},
           {"kind": "wait", "legIndex": 1, "line": "18", "place": "Allenby"},
           {"kind": "ride", "legIndex": 1, "line": "18", "place": "Azrieli Center"},
           {"kind": "walk", "legIndex": -1, "line": null, "place": "Azrieli"},
           {"kind": "arrive", "legIndex": -1, "line": null, "place": "Azrieli"}]}
  • event: "start" (the rider started following it, or Kav started again with it under way), "step" (the rider moved on to another step: off a bus, the next walk or wait, and so on), "replan" (Kav planned a new route on the way; trip is the new one), "shown" (the rider swiped navigation's cards to another step, or opened or left navigation; only step.shown changed), "eta" (Kav's estimate of when the trip gets there moved to another minute; only eta changed), "alight" (Kav's estimate of step.alightAt moved to another minute; only it changed. When both move at once, Kav tells "eta" and then "alight", each with both new times) or "end", with "reason": "arrived" when it ended at its last step, or "ended" when the rider ended it before. Ignore an event you don't know: a later Kav may add more.
  • trip: the trip as slots, parts and route rules get it (its legs, stops, lines and times).
  • step: the step the trip is on, the one navigation marks as current: its index and the count of steps, its kind (start, walk, wait, ride, taxi, cycle or arrive), its leg (leg, as a leg of trip; for a wait or a ride, the line the rider chose to take) and that leg's place in trip.legs (legIndex, -1 for a walk or the start and end). For a wait or a ride, alightAt is when its ride gets to the stop the rider gets off at, as Kav estimates it now, in seconds since 1970: on board, by the bus the rider is on and where they are on its road (as Kav's warning that a change won't work counts it), not only by its live times as leg.liveArr. null for other steps; Kav 5.2.5 and older don't give it, nor "alight" events. Getting off a bus is the step after its ride. shown is the step whose card navigation shows: the rider can swipe the cards, or tap the step dots, to look at another step than the one the trip is on. It's -1 while navigation isn't open (the rider went back to Home during the trip).
  • steps: every step of the trip, in navigation's order, so step.index and step.shown are places in it. Each has its kind and legIndex as above, the line a wait or a ride is for (the line the rider chose there, null for other steps), and the place the step is about: where the trip starts, the stop a walk goes to, the stop a wait boards at, the stop a ride gets off at (a taxi's or a bike's too, when it ends at one), or where the trip ends. null when it has none.
  • eta: when the trip gets there as Kav estimates it now, in seconds since 1970: the trip notification's "Arrive", worked out from where the bus is on a ride, otherwise from the plan and the live times Kav has. Kav works it out every few seconds in its trip service, and step.alightAt with it, so "eta" and "alight" events also come with Kav in the background.
  • Set while a trip is under way (from start(), or when the rider allows it during a trip), the listener is told that trip at once, as "start". null stops it. Without a trips.follow contribution kav.onTrip throws.

Both need "api": 5 in the manifest (an older Kav has neither method). A Kav without these capabilities installs your extension and never calls you.

Kav's own planner: kav.plan, results.add and kav.switchTrip (API 5) ​

kav.plan(query) asks Kav's own planner, as Kav's search does, and answers its routes. Off the main thread: it asks the network, and throws on the main one. No contribution needed.

kotlin
val answer = kav.plan("""{"from": [32.0853, 34.7818], "to": [32.0745, 34.7920], "at": 0, "way": "d", "settings": "fnnt"}""")
// {"routes": [{"ref": "r12", "dep": ..., "arr": ..., "legs": [...], ...}]}
  • from, to: [lat, lon], required. at: seconds since 1970, 0 or none for now. way: "d" to leave at at (the default) or "a" to get there by it. settings: the planner settings' four letters, in this order: pace (s slow, n normal, f fast), walking (l less, n normal, m more), changes (n normal, f fewer) and time at the stop (t tight, n normal, r relaxed); the rider's own by default. modes: the route types to take (all by default).
  • Each route is in the shape route rules get it (A route), with a ref. Kav keeps the route by its ref for 15 minutes (the last 60 of yours), for results.add and kav.switchTrip; another extension's ref is unknown to you. No routes when the planner found none, null when it can't be reached. A query that isn't right throws.

results.add: your routes first in Kav's results. Once Kav's own planner has answered a search and its routes are on screen, Kav asks each extension that provides results.add, with a contribution of that capability. Its routes go first. Kav asks only for its own planner (not an extension's planner, a recent trip an extension planned, or a shared trip), and not for a search with stops on the way or for the last departures. The rider's route rules judge your routes too.

json
"contributions": [{"id": "runs", "capability": "results.add"}]
kotlin
kav.provide("results.add") { input ->
    val q = JSONObject(input).getJSONObject("query")
    val faster = JSONObject(kav.plan(q.put("settings", "fnnt").toString()))
    // The first two of them at the fast pace, leaving 2 minutes later.
    JSONArray((0 until minOf(2, faster.getJSONArray("routes").length())).map {
        val r = faster.getJSONArray("routes").getJSONObject(it)
        JSONObject().put("ref", r.getString("ref")).put("start", r.getLong("dep") + 120)
    }).toString()
}
  • Asked {"query": {"from", "to", "at", "way", "now", "settings", "modes", "reason"}, "routes": [...], "trip"}: routes are Kav's own, reason is "search", or "replan" when Kav plans a New route from here for the trip under way, which also gives that trip (as kav.onTrip gives it). For "replan", the first route you answer is the new route. at is as for kav.plan: 0 when the rider searched for now, now the time Kav asks, in seconds since 1970.
  • Answered [{"ref", "start", "walks"}]: routes from kav.plan, at most 3. start is when the rider leaves, in seconds since 1970 (the route's own by default); walks how many seconds each walk before the route's first ride takes (the route's own by default; as many as those walks). Kav lays the walks and waits out from start, and takes the route only when they reach the first ride by when it leaves, by its live time when Kav has one. Its tag likely_missed goes, and Kav's own tags are worked out again over all the results.
  • Within 20 seconds; Kav's own routes stay on screen meanwhile. A route Kav doesn't know or can't lay out so is left out, and an answer Kav can't read adds nothing.

kav.switchTrip(change): the trip under way goes on with one of your routes, from where one of its rides ends, as Kav's own New route from here does: the legs up to that ride stay, your route comes after them.

kotlin
val switched = kav.switchTrip("""{"ref": "r12", "after": 1, "dep": 1795421100, "arr": 1795422900}""")

after is the ride's index in the trip's legs, dep and arr the trip's own as kav.onTrip gives them, so a trip that changed since is left as it is. start and walks, both optional, lay the route out first as for results.add (a run from the stop where the ride ends, say). True when it was switched; false for a ref Kav doesn't know, another trip, a ride the rider is past, walks that don't reach the route's first ride in time, a trip with stops on the way still ahead (a route of kav.plan goes through none), or Kav's screen not running. Only while the rider allows following trips, with a trips.follow contribution (without it, it throws). From any thread. The listener is then told "replan".