Games & simulation

live-jev

@vinilana10JavaScriptupdated 2026-09-18runnable

2D autonomous car simulation in the browser, driven by TypeSafe's Jev decision model

vinilana/live-jev

Where it calls Jev

import { TypeSafeClient, APIError } from "@typesafe-ai/sdk";

server.js:8

The link points at the commit we read, so the line number still holds.

What it asks Jev

These question sets are lifted from this project's source exactly as written.

from public/js/brain.js:5

  1. lane_actionchoice

    You are the driving policy of `ego`, a car on a one-way road with 3 lanes (see `road`).

    • keep_laneStay in the current lane; it is clear enough, or no adjacent lane is safer.
    • change_leftMove one lane to the left: the left lane exists, is clear ahead and no car is closing from behind, and the current lane is blocked or slower.
    • change_rightMove one lane to the right: the right lane exists, is clear ahead and no car is closing from behind, and the current lane is blocked or slower.
  2. speed_actionchoice

    Decide how `ego` should adjust its speed in the next second. Only `lanes.current` matters for speed; objects in

    • stopBrake to a full stop: a pedestrian is in or entering the path, or a stopped obstacle/vehicle is within `ego.stopping_distance_m` plus a 5 m margin (leave room to steer around it later).
    • slow_downReduce speed: the lead in the current lane is within about twice the stopping distance, or `time_to_collision_s` is under ~4 s.
    • holdKeep the current speed: there is a lead in the current lane but the gap is comfortable (`time_to_collision_s` between ~4 and ~8 s, or matching its speed).
    • speed_upAccelerate: the current lane is clear well beyond twice the stopping distance (or `time_to_collision_s` is null or above ~8 s) and ego is below the speed limit.
  3. hazardscore

    Rate the overall collision hazard for `ego` right now, given everything in the state.

    • 0No hazard: the road ahead is clear for a long distance.
    • 1Low: obstacles or vehicles exist but they are far away or in other lanes.
    • 2Moderate: something in the current lane is within about twice the stopping distance, or a pedestrian is close to the road.
    • 3Severe: a collision is likely within a few seconds unless ego brakes or swerves now.
  4. pedestrian_yieldtrue/false

    A pedestrian is on the road, or is walking toward the road and will reach ego's lane, within roughly `ego.stopping_distance_m`

Run it on your own text

The code
import { experimental_evaluate as evaluate } from 'ai';

const { answers } = await evaluate({
  model: 'typesafe-ai/jev',
  state,
  questions: {
    lane_action: { type: 'choice', instructions: 'You are the driving policy of `ego`, a car on a one-way road with 3 lanes (see `road`).',
      criteria: { keep_lane: 'Stay in the current lane; it is clear enough, or no adjacent lane is safer.', change_left: 'Move one lane to the left: the left lane exists, is clear ahead and no car is closing from behind, and the current lane is blocked or slower.', change_right: 'Move one lane to the right: the right lane exists, is clear ahead and no car is closing from behind, and the current lane is blocked or slower.' } },
    speed_action: { type: 'choice', instructions: 'Decide how `ego` should adjust its speed in the next second. Only `lanes.current` matters for speed; objects in',
      criteria: { stop: 'Brake to a full stop: a pedestrian is in or entering the path, or a stopped obstacle/vehicle is within `ego.stopping_distance_m` plus a 5 m margin (leave room to steer around it later).', slow_down: 'Reduce speed: the lead in the current lane is within about twice the stopping distance, or `time_to_collision_s` is under ~4 s.', hold: 'Keep the current speed: there is a lead in the current lane but the gap is comfortable (`time_to_collision_s` between ~4 and ~8 s, or matching its speed).', speed_up: 'Accelerate: the current lane is clear well beyond twice the stopping distance (or `time_to_collision_s` is null or above ~8 s) and ego is below the speed limit.' } },
    hazard: { type: 'score', instructions: 'Rate the overall collision hazard for `ego` right now, given everything in the state.',
      criteria: ['No hazard: the road ahead is clear for a long distance.', 'Low: obstacles or vehicles exist but they are far away or in other lanes.', 'Moderate: something in the current lane is within about twice the stopping distance, or a pedestrian is close to the road.', 'Severe: a collision is likely within a few seconds unless ego brakes or swerves now.'] },
    pedestrian_yield: { type: 'boolean', instructions: 'A pedestrian is on the road, or is walking toward the road and will reach ego\'s lane, within roughly `ego.stopping_distance_m`' },
  },
});

Other projects in this category