← Haptic Feedback Planner
Your token

Haptic Feedback Planner API

Reading the code, finding the controls, planning a haptic for each, the navigator.vibrate() patterns and the React, Vue, Svelte and JavaScript code all run free in the browser and need no API. The API is for the one metered step: send the numbered code and the plan, get back a review of every planned haptic.

Base URL: https://api.skillsafe.ai/v1/app-api. Every response is {"data": ...} or {"error": {"code", "message"}}; read error.code and error.message rather than the HTTP status alone.

The task field

This app has one task. Always send "task": "review".

taskWhat it doesReply
reviewChecks each planned haptic against the code at its line: keeps it, changes it to another web-haptics preset, or turns it off or back on, and reports up to 5 controls the plan missed, each pointing at a line of the sent code.One JSON object

Input fields

FieldTypeMeaning
taskstring"review"
codestringThe code, each line as N| text. The page sends up to 400 lines; from a longer paste, the lines around each control, with ... N lines not sent ... markers.
planstringJSON text: an array of {id, line, control, kind, haptic, when, on, on_failure?}.
frameworkstringreact, vue, svelte, vanilla or vibrate.
notestringOptional: what the app is, at most 300 characters. May be empty.
factsstringJSON text from the page: framework, detected, mode, lines_total, lines_sent, planned, no_haptic, existing_calls.

The reply

job.output.output is JSON text: {"task": "review", "rows": [{"id", "haptic", "keep", "why"}], "missed": [{"line", "element", "haptic", "when", "why"}], "advice": [...]}. haptic is one of success, warning, error, light, medium, heavy, soft, rigid, selection, nudge, buzz. The page uses a row answer only when its id was sent and its haptic is a preset, and a missed control only when its line was sent, its element text is on that line and the line has no haptic yet; everything else is listed as not used. If the balance ran low, truncated is true and the object may stop early; the answers that arrived whole are kept.

Worked examples

A React checkout, with a note

Input (input.json):

{
  "task": "review",
  "code": "1| import { useState } from \"react\";\n2| \n3| export function Checkout({ cart, onPay }) {\n4|   const [qty, setQty] = useState(1);\n5|   const [gift, setGift] = useState(false);\n6|   const [shipping, setShipping] = useState(\"standard\");\n7| \n8|   async function handlePay(e) {\n9|     e.preventDefault();\n10|     await fetch(\"/api/pay\", { method: \"POST\", body: JSON.stringify({ qty, gift, shipping }) });\n11|     onPay();\n12|   }\n13| \n14|   return (\n15|     <form className=\"checkout\" onSubmit={handlePay}>\n16|       <div className=\"qty\">\n17|         <button type=\"button\" aria-label=\"Decrease\" onClick={() => setQty(Math.max(1, qty - 1))}>-</button>\n18|         <span>{qty}</span>\n19|         <button type=\"button\" aria-label=\"Increase\" onClick={() => setQty(qty + 1)}>+</button>\n20|       </div>\n21|       <label>\n22|         <input type=\"checkbox\" checked={gift} onChange={(e) => setGift(e.target.checked)} /> Gift wrap\n23|       </label>\n24|       <select value={shipping} onChange={(e) => setShipping(e.target.value)}>\n25|         <option value=\"standard\">Standard</option>\n26|         <option value=\"express\">Express</option>\n27|       </select>\n28|       <input type=\"email\" name=\"email\" placeholder=\"Email for the receipt\" required />\n29|       <button type=\"button\" className=\"link\" onClick={() => cart.clear()}>Remove all items</button>\n30|       <a href=\"/cart\">Back to cart</a>\n31|       <button type=\"submit\" className=\"primary\">Pay now</button>\n32|     </form>\n33|   );\n34| }",
  "plan": "[{\"id\":\"h1\",\"line\":15,\"control\":\"checkout form\",\"kind\":\"payment\",\"haptic\":\"success\",\"when\":\"result\",\"on\":true,\"on_failure\":\"error\"},{\"id\":\"h2\",\"line\":17,\"control\":\"Decrease\",\"kind\":\"stepper\",\"haptic\":\"selection\",\"when\":\"tap\",\"on\":true},{\"id\":\"h3\",\"line\":19,\"control\":\"Increase\",\"kind\":\"stepper\",\"haptic\":\"selection\",\"when\":\"tap\",\"on\":true},{\"id\":\"h4\",\"line\":22,\"control\":\"Gift wrap\",\"kind\":\"toggle\",\"haptic\":\"light\",\"when\":\"change\",\"on\":true},{\"id\":\"h5\",\"line\":24,\"control\":\"shipping picker\",\"kind\":\"picker\",\"haptic\":\"selection\",\"when\":\"change\",\"on\":true},{\"id\":\"h6\",\"line\":29,\"control\":\"Remove all items\",\"kind\":\"destructive\",\"haptic\":\"warning\",\"when\":\"tap\",\"on\":true},{\"id\":\"h7\",\"line\":31,\"control\":\"Pay now\",\"kind\":\"primary\",\"haptic\":\"medium\",\"when\":\"tap\",\"on\":true}]",
  "framework": "react",
  "note": "Mobile web shop; most people pay on a phone.",
  "facts": "{\"framework\":\"react\",\"detected\":\"react\",\"mode\":\"balanced\",\"lines_total\":34,\"lines_sent\":34,\"planned\":7,\"no_haptic\":\"28:field 30:link\",\"existing_calls\":0}"
}

Reply:

{
  "task": "review",
  "rows": [
    {
      "id": "h1",
      "haptic": "success",
      "keep": true,
      "why": "handlePay posts the payment and then calls onPay, so the result is a real outcome."
    },
    {
      "id": "h2",
      "haptic": "selection",
      "keep": true,
      "why": "Decrease steps the quantity down by one, clamped at 1, a discrete step."
    },
    {
      "id": "h3",
      "haptic": "selection",
      "keep": true,
      "why": "Increase steps the quantity up by one, a discrete step."
    },
    {
      "id": "h4",
      "haptic": "light",
      "keep": true,
      "why": "Gift wrap checkbox flips one boolean option, so a light tick fits."
    },
    {
      "id": "h5",
      "haptic": "selection",
      "keep": true,
      "why": "The shipping select chooses between Standard and Express, a discrete choice."
    },
    {
      "id": "h6",
      "haptic": "warning",
      "keep": true,
      "why": "Remove all items calls cart.clear() immediately with no confirm, so it is destructive."
    },
    {
      "id": "h7",
      "haptic": "medium",
      "keep": true,
      "why": "Pay now is the primary submit tap; the note does not ask for fewer haptics."
    }
  ],
  "missed": [],
  "advice": [
    "Fire success in handlePay after the fetch on line 10 resolves, not in the onSubmit wiring on line 15.",
    "The fetch on line 10 never checks response status, so use the error haptic in handlePay when the response is not ok."
  ]
}

A review form with a custom star rating

Input:

{
  "task": "review",
  "code": "1| import { useState } from \"react\";\n2| import { StarRating, Stepper } from \"./ui\";\n3| \n4| export function ReviewForm({ onSent }) {\n5|   const [stars, setStars] = useState(0);\n6|   const [anon, setAnon] = useState(false);\n7|   const [busy, setBusy] = useState(false);\n8|   async function send() {\n9|     setBusy(true);\n10|     try {\n11|       await api.post(\"/reviews\", { stars, anon });\n12|       onSent();\n13|     } finally { setBusy(false); }\n14|   }\n15|   return (\n16|     <div className=\"review\">\n17|       <StarRating value={stars} onChange={setStars} />\n18|       <label><input type=\"checkbox\" checked={anon} onChange={() => setAnon(!anon)} /> Post anonymously</label>\n19|       <textarea placeholder=\"What did you think?\" />\n20|       <button className=\"ghost\" onClick={() => setStars(0)}>Clear</button>\n21|       <button disabled={busy} onClick={send}>Continue</button>\n22|       <a href=\"/guidelines\">Review guidelines</a>\n23|     </div>\n24|   );\n25| }",
  "plan": "[{\"id\":\"h1\",\"line\":18,\"control\":\"Post anonymously\",\"kind\":\"toggle\",\"haptic\":\"light\",\"when\":\"change\",\"on\":true},{\"id\":\"h2\",\"line\":20,\"control\":\"Clear\",\"kind\":\"destructive\",\"haptic\":\"warning\",\"when\":\"tap\",\"on\":true},{\"id\":\"h3\",\"line\":21,\"control\":\"Continue\",\"kind\":\"submit\",\"haptic\":\"success\",\"when\":\"result\",\"on\":true,\"on_failure\":\"error\"}]",
  "framework": "react",
  "note": "",
  "facts": "{\"framework\":\"react\",\"detected\":\"react\",\"mode\":\"balanced\",\"lines_total\":25,\"lines_sent\":25,\"planned\":3,\"no_haptic\":\"19:field 22:link\",\"existing_calls\":0}"
}

Reply:

{
  "task": "review",
  "rows": [
    {
      "id": "h1",
      "haptic": "light",
      "keep": true,
      "why": "Anonymous checkbox flips one boolean with setAnon, so a light tick fits."
    },
    {
      "id": "h2",
      "haptic": "light",
      "keep": true,
      "why": "Clear only resets stars to 0 with setStars(0); nothing is deleted, so it is not destructive."
    },
    {
      "id": "h3",
      "haptic": "success",
      "keep": true,
      "why": "Continue runs send(), which posts the review; success on resolve and error on failure fit."
    }
  ],
  "missed": [
    {
      "line": 17,
      "element": "<StarRating value",
      "haptic": "selection",
      "when": "change",
      "why": "Each star choice via onChange is a discrete step, like a picker."
    }
  ],
  "advice": [
    "Fire success in send() right after the await api.post on line 11, and error if it throws; the try has no catch."
  ]
}

On the page, the answers rewrite the plan and the code, and each change is listed with its reason.

Errors

HTTPWhat to do
401The token is missing, expired or a guest token on a run. Get a personal token on the token page.
402The balance is below what the run reserves. Top up at skillsafe.ai/account/billing.
400The body is not a JSON object of the fields above.
429Wait and retry with the same Idempotency-Key.

Step 1 — a tiny client helper

One function that sends JSON and unwraps the {data, error} envelope.

BASE="https://api.skillsafe.ai/v1/app-api"
TOKEN="paste-your-token-here"   # from https://haptic-feedback-planner.skillsafe.ai/tokens.html
api() { # api METHOD PATH [JSON-BODY]
  curl -s -X "$1" "$BASE$2" -H "Content-Type: application/json" \
    ${TOKEN:+-H "Authorization: Bearer $TOKEN"} ${3:+--data "$3"}
}

Step 2 — a token

A guest token is enough for /me and /estimate. A run is metered, so it needs your personal token: sign in on the token page and copy it.

# a guest token (enough for /me and /estimate); a run needs your personal token from /tokens.html
TOKEN=$(curl -s -X POST "$BASE/guest" -H "Content-Type: application/json" -d '{"slug":"haptic-feedback-planner"}' | jq -r '.data.token')

Step 3 — who am I, and my balance

subject_type is guest or user; credits is the balance (1 credit = $0.0001).

api GET /me | jq '.data | {subject_type, credits}' 

Step 4 — price a run for free

/estimate charges nothing and starts no job. hold_credits is the amount reserved while a run is in flight, not the price; the run is charged what it uses.

# input.json: the run input object - {"task": "review", "code": "1| ...", "plan": "[...]", "framework": "react", "note": "", "facts": "{...}"}
api POST /estimate "$(cat input.json)" | jq '.data | {hold_credits, min_credits, model, model_alias, markup_bps, warnings}' 

Step 5 — run it and wait for the job

Send an Idempotency-Key derived from the input: a retry with the same key is never billed twice.

KEY="haptic-feedback-planner:review:$(shasum -a 256 input.json | cut -c1-16):a1"
JOB=$(curl -s -X POST "$BASE/run" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: $KEY" --data @input.json | jq -r '.data.job_id')
while :; do
  J=$(api GET "/jobs/$JOB"); S=$(echo "$J" | jq -r '.data.status')
  case "$S" in succeeded|failed|cancelled) break;; esac; sleep 2
done
echo "$J" | jq -r '.data.output.output' > reply.json   # one JSON object: task, rows, missed, advice
echo "$J" | jq '.data | {charged_credits, truncated}' 

Step 6 — or stream it

/run-stream sends Server-Sent Events while the job runs and the finished job at the end.

# Server-Sent Events: tick/delta events while the job runs, then a final event with the job
curl -N -s -X POST "$BASE/run-stream" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: haptic-feedback-planner:review:$(shasum -a 256 input.json | cut -c1-16):a1" --data @input.json