npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@intentface/latch-server

v0.11.0

Published

The mountable Latch HTTP surface — one framework-agnostic Web handler (chat, approvals, lists, MCP connection OAuth). Hono adapter in the /hono subpath.

Readme

@intentface/latch-server

The mountable HTTP surface for a Latch runtime — one framework-agnostic Web handler you mount at a single route in any Web-standard host (TanStack Start, Next, Bun, Deno, serverless).

What it does

createLatchHandler({ runtime, connections, resolveContext }) returns a (Request) => Response handler that exposes the runtime over HTTP:

  • POST /agents/:agent/:id — run a chat turn (streams UIMessage SSE).
  • POST /agents/:agent/:id/approvals — submit HITL approval decisions (resumes the turn).
  • POST /agents/:agent/:id/tool-result — return a client-handled tool result (e.g. ask_question).
  • GET /agents/:agent/:id/history, GET /chats, GET /runs — projections for the UI.
  • GET/POST/DELETE /schedules, GET /schedules/:id, POST /schedules/:id/run-now — manage scheduled agents; POST /cron/run — the host-guarded tick.
  • GET /connections, …/:name/authorize, …/:name/callback, …/:name/disconnect, …/test — generic MCP connection OAuth + status.

resolveContext(request) turns a request into your Principal (bring-your-own auth). A Hono adapter is exported from the /hono subpath.

OAuth callback identity

The connection callback is the one route that does NOT authenticate via resolveContext. An IdP redirect arrives at a moment you don't control, so a degraded session there must never decide where credentials land. Instead, authorize pins the resolved principal into the OAuth flow state, and the callback rebuilds it from that pin:

createLatchHandler<Principal>({
  runtime, connections, resolveContext,
  // Validate/re-hydrate the pinned identity on the callback (e.g. re-check
  // org membership). Null → 401. Default: trust the pin as-is.
  reconstructPrincipal: async (identity) => validateMembership(identity),
  oauthFlowMaxAgeMs: 30 * 60_000, // authorize → callback TTL (the default)
});

The callback does not resume a waiting turn — the browser must not sit on a blank page for a whole run. Resuming is the client's job after the redirect: find the pending connect_<name> approval in the chat's history, submit it to POST /agents/:agent/:id/approvals, and read the continuation stream that returns. Two details are easy to miss: the continuation reuses the last assistant message's id and streams only its new parts, so seed your stream reader with a clone of that message or the answer renders as a second, half-empty one; and mirror the decision locally first, or the approval card stays on screen for the whole run. Reconcile against server history at the end.

A callback whose pin is older than oauthFlowMaxAgeMs redirects with ?error=flow_expired (the user just re-runs connect). The pin is tamper-evident — the full state string is exact-matched against the copy the flow stored at start() — and principals are IDs-only by contract (see @intentface/latch-core's principal.ts), so nothing sensitive rides in the URL.

Scheduling over HTTP

POST /schedules takes everything runtime.schedule() does, so the mounted handler is not a reduced version of the contract:

{
  "agent": "briefer", "cron": "0 8 * * 1-5", "timezone": "Europe/Helsinki",
  "prompt": "morning brief",
  // Opaque to core — only your `runSchedule` hook reads it (a Slack thread, a DM).
  "delivery": { "kind": "slack", "appId": "A1", "channel": "C1" },
  // "skip" (default) = don't fire onto a predecessor still waiting on a human;
  // "fire" = always fire. An unknown value is a 400, never a silent default.
  "onParked": "fire"
}

POST /schedules/:id/run-now arms a schedule for the next tick rather than firing it inline — it then goes through the ordinary runDue path (same claim, same occurrence consume, same delivery), so "run now" cannot drift from what the cron actually does. GET /runs deliberately omits each run's identity (the serialized principal): it is durable server state and a type you are invited to extend, so it never enters a browser payload — read it server-side via runtime.listRuns if you need it.

Usage

import { createLatchHandler } from "@intentface/latch-server";

const handler = createLatchHandler<Principal>({
  runtime, connections,
  resolveContext: (req) => getPrincipalFromHeaders(req.headers),
});
// mount at /api/latch/* — every Latch operation flows through this one handler.

Where it fits

The HTTP tier over @intentface/latch-core. The routes are a convenience over the real contract — the Runtime operations — which you can still call directly from your own routes or non-HTTP triggers (cron, queues, chat channels).