Skip to content
pairshapedPublic

About

Hyperapp-inspired Typescript with some Elm guardrails and WebMCP Support

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Repository files navigation

Hypertea

Hypertea is a tiny TypeScript TEA runtime for server-rendered apps, from a single interactive island to full single-page applications.

The goal is to make the client side of a server-rendered app feel close to Elm:

  • a typed model
  • typed messages
  • a pure update function
  • managed effects
  • managed subscriptions
  • strict linting around side effects
  • full test coverage

The same program model scales from a small island to a complete single-page application, while the client runtime stays small.

Public boundary

Applications use the package exports declared in package.json: the low-level runtime, the canonical program API, browserless testing helpers, and the ESLint purity configuration. The optional @pairshaped/hypertea/webmcp export connects declared browser tools to ordinary program messages and completion effects. src/index.ts, src/program.ts, src/testing.ts, and src/webmcp.ts own those interfaces. Benchmark and test internals are not public API.

WebMCP invocations stop waiting after 120 seconds and reject with WebMCPInvocationError, outcome unknown and reason timeout. The invocation is retired, so late completion messages cannot change the Program. A timeout does not roll back a request already sent; callers must report the uncertainty and must not replay a write automatically.

Status

The runtime exposes:

  • defineProgram() for one canonical Flags, Model, Msg, and Effect definition shared by production and tests
  • mountProgram() for mounting a program into a caller-provided element
  • mountIslands() for scanning server-rendered mounts, parsing flags, and mounting canonical programs
  • start() for lower-level hosts that already construct a runtime
  • h() for element VNodes and fragment() for inline child lists
  • package-provided JSX types for TSX islands
  • text() for text VNodes
  • memo() for memoized view islands
  • program-bound event helpers such as clicked, inputChanged, checkedChanged, and submitted
  • browser subscription helpers such as every, keyPressed, and windowResized
  • lower-level app() support for the small Hyperapp-shaped runtime underneath
  • keyed DOM patching

The package also includes:

  • strict TypeScript config
  • ESLint configured as an Elm-like safety rail
  • Vitest with 100 percent coverage thresholds
  • ADRs describing the intended design
  • helpers for exhaustive matching and empty effects

Fragments and view roots

Fragments (<>...</>, h(fragment, ...) or fragment(...)) group children without adding a DOM element. Child fragments may be nested, conditionally inserted, updated and removed. Helpers may return fragments for use as children.

Each Program or memoized view must return one root VNode. Wrap a root fragment in an element. A VNode can appear in more than one position. Hypertea gives each mounted occurrence its own DOM pointer and child slots, while retaining identity reuse at the same position. Direct fragment-array returns fail TypeScript. JSX shorthand needs the additional build check because TypeScript types every JSX expression as JSX.Element. Run this from the Hypertea package directory:

node bin/check-fragment-roots.mjs path/to/tsconfig.json

Run this check before bundling, including lazy feature sources. It follows view results through helpers and rejects fragment roots with a source location. Fragments beneath an element root remain valid.

This rule concerns rendered nodes. It supports both independently mounted Programs, including nested embeds, and parent-owned models with mapped child messages and effects. Each independently mounted Program owns its own root and lifetime.

Elm-Like Guardrails

The ESLint config is part of the runtime design. It exists to make TypeScript app code behave more like Elm code:

  • ordinary modules cannot call unmanaged side-effect APIs like fetch, timers, browser globals, storage, randomness, or wall-clock APIs
  • promises must be handled
  • boolean checks must be explicit
  • mutation is discouraged through readonly-oriented rules
  • TypeScript strictness catches missing branches, unchecked index access, and optional-field mistakes

Approved effect and subscription modules are where browser, network, time, storage, and DOM APIs belong.

Make unmanaged effects explicit

Hypertea exports a flat ESLint config for application modules that should not touch browser state directly:

import { hyperteaPurity } from "@pairshaped/hypertea/eslint";

export default [
  ...hyperteaPurity({
    files: ["src/islands/**/*.ts", "src/pages/**/*.ts"],
    effectFiles: [
      "src/islands/runtime.ts",
      "src/islands/sortable_list.ts",
    ],
  }),
];

The config rejects raw DOM, network, storage, timer, randomness, wall-clock, listener, and logging APIs in ordinary matched files. This catches a common hole where update calls an imported helper and that helper performs an unmanaged effect.

effectFiles is the reviewable exception list. Put real effect adapters there and explain each application-specific entry next to the config. For a genuinely local exception, use a one-line ESLint disable with a reason. Do not disable the rule for a directory just to get a build through.

If an entry module deliberately owns limited browser plumbing, give that file group a separate hyperteaPurity() entry with an allowedGlobals list. Keep the list short and explain it beside the config. extraRestrictedSyntax lets an application append its mutation, assertion, or JSX restrictions without replacing Hypertea's side-effect selectors in flat ESLint config.

This is a guardrail, not an effect type system. It does not inspect third-party packages, follow arbitrary call graphs, or prove that every function is pure. Island entry modules may still own mount and runEffect plumbing when splitting those into separate files would only add ceremony.

Commands

pnpm run typecheck
pnpm run lint
pnpm run test:coverage
pnpm run build
pnpm run check
pnpm run bench

pnpm run check is the command to run before handing work back.

pnpm run test:webmcp, from the Hypertea package directory, runs the optional native WebMCP smoke test through the globally installed playwright-cli and Chrome. It opens a headless browser, serves only the local example and compiled library, saves screenshots under the system temporary directory, and closes its server and browser. Finish other Playwright sessions first. The normal check stays browserless.

pnpm run test:webmcp:fallback runs the same example through its JavaScript bridge with native WebMCP disabled in the test browser.

pnpm run bench builds Hypertea and compares its DOM patching against Hyperapp in jsdom. Treat the numbers as regression signals and optimization guidance, not browser parity proof.

API Shape

Server-rendered application islands should use mountIslands():

import {
  bindEvents,
  defineProgram,
  h,
  mountIslands,
  type VNode,
} from "@pairshaped/hypertea/program"

type Model = {
  readonly count: number
}

type Msg = { readonly type: "increment" }
const on = bindEvents<Msg>()

function parseFlags(value: unknown): Model {
  if (typeof value !== "object" || value === null || !("count" in value) || typeof value.count !== "number") {
    throw new Error("Expected count")
  }
  return { count: value.count }
}

const counterProgram = defineProgram<Model, Model, Msg, never>({
  init: (flags) => [flags, []],
  update: (model, message) => {
    switch (message.type) {
      case "increment":
        return [{ count: model.count + 1 }, []]
    }
  },
  view: (model): VNode<Model> =>
    h("button", { onClick: on.clicked({ type: "increment" }) }, String(model.count)),
})

mountIslands({
  selector: "[data-counter]",
  parseFlags,
  program: counterProgram,
})

update returns [model, effects]. Effectless programs omit runEffect; declaring a real effect type makes the runner required. Invalid or missing flags render a visible mount error and produce a console diagnostic.

mountProgram() and start() return a handle with model(), dispatch(), call(), settle(), and stop(). settle() flushes the currently queued DOM render without waiting for an animation frame. It does not wait for effects, timers, or network requests. stop() is idempotent, removes active subscriptions, blocks further dispatch and aborts pending runners' effect signals.

Use effectSignal(dispatch) from @pairshaped/hypertea/program in an effect adapter to obtain its stop signal. Pass it to fetch, or listen for abort to clear a timer or release another resource. Return a promise covering the whole operation, including cleanup. A runner that returns void is complete when it returns; a settled promise is complete when the runtime observes its settlement. Completed runners' signals do not abort on later stop. A plain dispatch has no effect signal. Preserve the captured dispatch when forwarding effects between bundles.

Cancellation is cooperative. An adapter that ignores the signal keeps its existing resource behavior, although its late dispatch is blocked. The effect signal belongs to one runner and aborts on Program stop. A caller's effectInvocation(dispatch)?.signal has a separate lifetime; combine the two signals when the operation must also stop on caller cancellation. This API does not add keyed replacement or retry a request.

Ordinary effects keep their own recovery policy. Writes with an unknown outcome must not be replayed without a server idempotency guarantee. The optional live subscription below owns retries for an observational stream while it remains subscribed.

Subscriptions

A program's subscriptions callback returns ReadonlyArray<ProgramSubscription<Msg>>. Keep each subscription in a fixed slot. For an absent entry, use condition ? subscription : emptySubscription("slot-name:off"). An empty subscription starts nothing. Switching a slot from a real subscription to the empty one disposes it, and switching back starts it, because the key changes at that position. Later slots are not restarted.

Matching is positional, then compares the subscription key. A conditional spread or filtering out an earlier entry shifts later entries and restarts them. Keep ownership, publication, and live-stream slots stable.

Live subscriptions

Import liveSubscription, eventStream and the types you need from @pairshaped/hypertea/live. The main entry does not import this module. Public types include SseRecord, SseOptions, SseCursor, EventStreamOptions, LiveTransport, LiveHealth, LiveRetry and LiveOptions. Use LiveRetry to name a shared retry policy.

import { eventStream, liveSubscription, type SseRecord } from "@pairshaped/hypertea/live"

type Msg = { type: "record"; data: string } | { type: "disconnected" }

const feed = liveSubscription<SseRecord, string, Msg>({
  key: "feed:baseline-1",
  after: "0",
  open: eventStream({ url: "/events", cursor: { header: "Last-Event-ID" } }),
  decode: (record) => ({
    message: { type: "record", data: record.data },
    cursor: record.id,
  }),
  disconnected: () => ({ type: "disconnected" }),
  retry: { initialMs: 1000, maxMs: 30000, resetOn: "message" },
})

The SSE parser keeps the last valid id across records, so an id-less event in this example retains its cursor. An id-only block updates the next record without dispatching a message. An explicit empty id: clears it; a NUL-containing id leaves it unchanged.

The key names the resource and any stable baseline, never the moving cursor. Options captured at first subscribe, including after, decode and callbacks, stay fixed until the key changes or the slot is removed. Each subscription owns its connection, cursor and retry timer. Startup is deferred by one microtask so synchronous transport callbacks cannot re-enter subscription installation.

decode(record, cursor) returns { message, cursor? }. Omit cursor to keep the previous value. The core stores the returned value exactly; the decoder owns monotonicity and validation. Inclusive replay can deliver duplicates. Throw to refuse a record: the connection closes, the cursor stays unchanged and retries continue. onCursor(cursor) runs after acceptance, including when the retained cursor is undefined. onError(error) receives each failed attempt, including an unexpected clean stream end, but not disposal.

health maps { kind: "healthy" } | { kind: "problem"; text: string } into a message once per change. connected runs once per healthy connection; disconnected runs once per transition to unhealthy, including a first failed attempt. A quiet open connection is healthy. These callbacks only produce messages; the reducer owns UI state.

Retry delay starts at initialMs, multiplies by factor (default 2), and caps at maxMs. Set resetOn: "open" to reset at connection establishment, or resetOn: "message" to reset after an accepted record. Equal initial and maximum delays give a fixed interval. Delays must be finite and positive, with initialMs <= maxMs <= 2147483647 and a finite factor of at least 1. There is no attempt limit. Remove the subscription, using emptySubscription in its slot, when the app reaches a terminal state or needs a new snapshot. Disposal aborts reads, clears pending retries and suppresses late messages, even during decoding.

eventStream<Cursor>({ url, headers?, cursor?, credentials?, maxEventBytes?, describeError?, fetch?, TextDecoder? }) returns a transport. It sends Accept: text/event-stream, uses cache: "no-store", and defaults credentials to "same-origin". Pass "omit" for a credential-free stream. Caller headers are preserved except Accept, which always requests the stream format.

Choose { header: "Last-Event-ID" } or { param: "since_ms" } for cursor placement. Values use String(cursor); an undefined cursor or absent cursor option sends no cursor. The query form replaces that parameter while keeping other parameters and the fragment. With no caller headers, query cursors require no custom request header and keep cross-origin GETs eligible for simple CORS. The endpoint still needs the appropriate CORS response headers.

Records are { id, event, data }. The parser supports CR, LF and CRLF, multiline data, comments and fragmented UTF-8. It ignores NUL-containing ids, unknown fields and server retry: hints. The default event name is message. Records without data and unfinished records at EOF are discarded. Invalid UTF-8 fails the stream. The default cap is 1048576 raw bytes per record, including field names, comments, line endings and a leading BOM; maxEventBytes must be a positive safe integer. An oversized record is rejected before delivery. A replay should send separate records so one batch cannot exceed this cap.

Every failure the transport raises itself is a LiveStreamError whose failure is a LiveStreamFailure: network, rejected (401 or 403), status, content-type (contentType is undefined when the header is missing), no-body, record-too-large (limitBytes), invalid-utf8 or disconnected (the connection dropped mid-stream; cause holds the read error). The message keeps a neutral default and cause holds the original error where there is one. describeError(error, defaultText) supplies application wording. Narrow with instanceof and switch on the kind instead of matching message text:

describeError: (error, defaultText) => {
  if (!(error instanceof LiveStreamError)) return defaultText;
  const { failure } = error;
  switch (failure.kind) {
    case "rejected": return "Sign in again to keep this page live.";
    case "network": return "You appear to be offline.";
    case "status":
    case "content-type":
    case "no-body":
    case "record-too-large":
    case "invalid-utf8":
    case "disconnected": return defaultText;
    default: return assertNever(failure);
  }
},

When describeError is set, the thrown error is still a LiveStreamError with the original failure and the reworded message. Invalid options, such as a bad maxEventBytes, are programmer errors: eventStream and readSse throw RangeError("Invalid event byte limit") and describeError never sees them. Every runtime stream failure is a LiveStreamError.

Errors that did not come from the transport, such as a decode throw or an abort, pass through untouched. Only a TypeError thrown by fetch is classified as network; a fatal-decoder TypeError is invalid-utf8.

Custom transports implement open(cursor, signal, opened): AsyncIterable<Record> for one attempt. Call opened() when healthy, honor abort and release resources when iteration ends. readSse(stream, signal, { maxEventBytes?, TextDecoder? }) is also exported as an async generator. For deterministic tests, inject fetch and TextDecoder into the SSE transport, and setTimeout and clearTimeout into the live subscription. All default effects live inside this module.

update(model, message, origin) receives the chain's native or fallback origin, or undefined for human and plain subscription messages. Direct callers must pass that third argument. Origin is provenance, not authorization.

Use call(message, { origin, signal }) on the handle or subscription context when a caller needs an answer. Return reply(jsonValue) alongside effects in the transition. Hypertea routes it through the effect's own dispatch continuation, flushes rendering, and resolves the call. The first reply is secured before subscription teardown and delivered before the transition's effects run. Runners never interpret replies; they return a promise that settles after their last dispatch and use context.settle() for DOM coordination.

A signal already aborted rejects with ProgramCallError outcome cancelled-before-dispatch. Later cancellation, issuing-subscription withdrawal, program stop or an unanswered chain rejects with unknown. Cancellation retires that invocation: pending effect dispatchers cannot update the model or start new effects. Already-sent requests can still complete externally, so an unknown outcome must not be replayed. Duplicate terminal dispatches are ignored. Human-chain replies are dropped.

Field Values

Controls are uncontrolled after mount: value, checked, and selected write to the DOM only when the declared prop changes, so a re-render never overwrites what the user typed or toggled. A field that must mirror the model uses controlledValue (text inputs, textareas, selects), controlledChecked (checkboxes, radios), or controlledSelected (options) instead. Those compare the live DOM property against the declared value on every patch, so a rejected value is written back. value and controlledValue on a <select> are applied after its options patch, so a replaced option list does not lose the declared selection.

See 0007: Field Value Ownership After Mount.

Browserless Interaction Tests

Tests provide their own DOM environment and mount the production program through the testing entry point:

import { screen } from "@testing-library/dom"
import userEvent from "@testing-library/user-event"
import { mountProgram } from "@pairshaped/hypertea/testing"

const node = document.createElement("div")
document.body.append(node)
const mounted = mountProgram({
  node,
  flags: { count: 0 },
  program: counterProgram,
})
const user = userEvent.setup()

await mounted.settle()
await user.click(screen.getByRole("button", { name: "0" }))
await mounted.settle()

expect(mounted.model().count).toBe(1)
expect(screen.getByRole("button", { name: "1" })).toBeDefined()
mounted.stop()

Hypertea does not start JSDOM and does not provide a query or assertion language. Use Vitest, Testing Library, and user-event in the host application. The automated suite is browserless. Check layout, pointer geometry, native drag behavior, and browser quirks manually when those paths change.

The testing mount captures effects instead of running the production interpreter. effects() returns a frozen snapshot of pending { effect, dispatch } values. takeEffect(index) removes one pending effect, which lets a test complete requests in any order through normal messages. Use call() to start a waiting chain and its captured dispatch to return results. A captured effect stays pending until that dispatcher is used. Unresolved effects do not delay settle(), and their dispatchers cannot update a stopped program.

const mounted = mountProgram({ node, flags: searchFlags, program: searchProgram })

mounted.dispatch({ type: "setQuery", value: "club" })
const pending = mounted.takeEffect()
if (pending?.effect.type !== "search") throw new Error("Expected search effect")

expect(pending.effect).toEqual({ type: "search", query: "club" })
pending.dispatch({
  type: "suggestionsLoaded",
  query: pending.effect.query,
  suggestions: [{ id: 1, name: "Club league" }],
})
await mounted.settle()

The lower-level app() API remains available from the package root for runtime internals and benchmarks. Application code should import from @pairshaped/hypertea/program, which exposes the typed program APIs without low-level dispatch or magic no-effect values.

WebMCP

WebMCP tools are an optional input to the same running program. A tool validates input and calls the program with an ordinary application message. Its update returns reply(result) on the request's own effect chain. Human actions use the same messages; replies on their chains are dropped. The runtime never infers an outcome from rendering or a loading flag.

Declare which existing messages agents can send:

import { exposeMessages } from "@pairshaped/hypertea/webmcp";
import schemas from "./webmcp.generated.js";

const mcpTools = exposeMessages<Msg>([
  { message: "filterProductResults" },
  { message: "toggleNavigation" },
], schemas);

Supply tool text through the host's toolDescriptions packet array mount option, alongside business flags. The packet carries scope, language, binding, and a tools map from tool name to { key, description }. Island hosts read the same packet from data-tool-descriptions; parseWebMCPDescriptionPackets validates manual hosts. Programs and subscriptions receive the packet through their context. Refresh it by replacing the mount when a new server page arrives. A composed document host can supply toolDescriptions in the bridge subscription options when its server document changes without replacing the Program. Invalid packets omit tools and report a fixed error; they never fall back to the older mount text.

Declarations contain no description default. A tool without text is omitted and its scope/name is reported without prose. Other tools and the human UI remain available. Native, fallback and built-in callers receive the same stored text. The internal publication retains key, scope and binding so an application's server can validate discovery and resolve its own text again.

Each message name is checked against Msg["type"]. The generator reads their payload types and writes the schema sidecar; Hypertea uses those same schemas to validate inputs and construct messages. There are no repeated tool names, payload definitions, parsers or dispatch mappings. Keep Msg organized around application behavior. Only allowlisted messages are exposed.

Input parsing or message mapping failures reject with WebMCPInvocationError whose outcome is "cancelled-before-dispatch" and reason is "invalid-input". These failures happen before call observers and the Program run. The error uses a fixed message and does not expose the rejected input or parser exception. Errors after dispatch keep the existing cancellation or "unknown" outcome; unknown errors never carry an invalid-input reason. A known refusal can be reported through the caller's normal result protocol without replaying work.

Use isWebMCPInvocationError(error) in catch blocks that receive failures from page tools. Shell and feature bundles have different class constructors, so instanceof WebMCPInvocationError cannot recognize the other bundle's error. The predicate recognizes canonical error instances through a shared weak set in the current JavaScript global; matching names or outcome fields alone do not qualify. Unknown errors keep their original outcome.

A scoped caller rejects a name absent from its still-current captured catalog with cancelled-before-dispatch and reason unknown-tool, before input mapping or application work. The message is fixed and does not echo the requested name or input. An aborted caller or changed catalog keeps the ordinary cancellation result. Callers can use the captured getTools() names to explain what was offered. Unknown outcomes never carry either refusal reason.

Run hypertea-webmcp --project tsconfig.json --source webmcp.ts --output webmcp.generated.ts after changing a selected message. Add the same command with --check to your build or CI to reject stale schemas. Generation requires TypeScript 6, strictNullChecks, and exactOptionalPropertyTypes. It does not run application code or include the compiler in the browser bundle.

A field typed with the exported WebMCPValue supports a JSON document. The generator recognizes that declaration through imported aliases and reexports and emits {"x-hypertea-json-value":true} for that field. Outer message and operation objects remain closed. Both tool interfaces validate finite JSON data before and after copying; getters, custom serialization, cycles and non-JSON values are rejected. Arbitrary unknown, any, recursive types and index signatures remain unsupported. The application still owns document validation and authorization.

Registration is a managed subscription. Removing it cancels pending callers and unregisters the tools. The runtime flushes queued rendering before delivering a reply, even in a hidden tab. Effect runners never interpret replies.

Register once with bridge.subscription(mcpTools). Hypertea publishes both:

  • Native tools through document.modelContext, when available.
  • window.hyperteaAgent and an inert JSON catalog at script#hypertea-agent-tools[type="application/json"], in every browser running the program.

Pass bridge.subscription(mcpTools, { nativeRegistration: false }) when the application's server policy permits only fallback publication. This keeps the full fallback catalog available. Passing true cannot widen a document declared restricted; both policies must permit native registration. Omit the option to use the document policy alone.

After a native registration failure, the owning Program can republish the same bridge with nativeRegistration: false. Fresh scoped callers can capture the fallback catalog once it is ready. Earlier captures stay invalid, and recovery cannot clear another bridge’s registration failure.

No URL parameter or mode switch is needed. Both interfaces use the same validation, messages, effects and completion handling. An agent with permission to execute page JavaScript can discover and invoke the tools:

window.hyperteaAgent.getTools();
await window.hyperteaAgent.executeTool("add", { amount: 2 });

The example above calls the counter tool from the integration guide. The catalog contains the names, descriptions, schemas and annotations of the current page's registered tools. It updates as programs add or remove tools, and disappears with the last tool set. Multiple programs share the catalog; names must be unique across the document.

observeWebMCPCalls(document, { beforeDispatch, onStart }) observes calls from both interfaces across independently bundled programs. After input validation, beforeDispatch(tool) runs synchronously. Return a JSON result to refuse the call without dispatching a message. Return undefined to admit it. All admission callbacks run before any onStart(tool) callback, which runs immediately before dispatch. Use this boundary for a page's assistant guard and agent-control mode; ordinary human messages do not trigger it. Call the returned cleanup function when the page controller stops. Observers and publication belong to the document, so separate tabs share neither. A callback that throws prevents dispatch.

Built-in assistants can use createWebMCPCaller(document). Its opaque handle is passed as the second argument to admission and start callbacks for that caller's invocations. Compare it by identity when deciding whether an assistant's own busy guard applies. Other admission callbacks and the target Program's authorization still apply; the invocation retains the fallback origin.

Call capture() at the start of a turn to read and execute the current registry. The captured caller refuses a tool before dispatch if its registration is removed or replaced. Call stop() on detachment. Cancellation after dispatch reports an unknown outcome and does not undo application work.

effectOrigin(dispatch) from @pairshaped/hypertea/program returns "native" or "fallback" for an effect caused by a tool call, and undefined for a human or initial effect. Use the dispatch passed to that effect runner. Messages sent through it keep their origin across asynchronous continuation; a human message on the same mount has its own origin. Use this for telemetry, never permission.

effectInvocation(dispatch) returns the call's frozen, read-only context: { caller?, origin?, signal, isLive }. Each call has a unique context shared by all its effect continuations. The optional opaque caller is the scoped caller's handle; native and external fallback calls have no known handle. Human and initial effects have no invocation. The handle comes from the adapter, never from tool input. Direct program callers may supply it in CallOptions.

Check isLive() immediately before a delayed business dispatch. It becomes false on reply, cancellation, subscription withdrawal or program stop. signal aborts on cancellation or failed/unanswered retirement, so a waiting UI can settle its own declined result. Successful replies retire liveness without aborting the transition's already-scheduled effects. Effect runners must use the returned context when guarding external work; Hypertea cannot undo a request already sent.

The fallback does not make an agent discover tools automatically. Give it the calling instructions or use a browser connector that knows this convention. Agents limited to screenshots or accessibility snapshots can still use the ordinary UI. The bridge provides no browser permission dialog or extra authority; application validation, confirmation and server authorization still apply.

Read the application integration guide for typed usage, asynchronous outcomes, cancellation, and the exact browser compatibility tested. The browser example exercises both interfaces with local and simulated async actions.

Non-Goals

  • No whole-app router.
  • No server runtime.
  • No ORM or general-purpose RPC framework.
  • No large component system.
  • No direct replacement for Elm.

Design Records

createWebMCPCaller(document).captureReady() waits for the current publication's native registrations before capturing its tools. It refuses if registration fails, the caller stops, or the catalog changes while waiting. Use it before automatically continuing work on a newly loaded page.

Document page state

Import registerPageState, pageStateReader and decidePageConfirmation from @pairshaped/hypertea/page-state. This optional effect module shares one registry and unload listener across independently bundled mounts in the same document. The core Program entry does not import it. Attach the listener only while a live projection requires protection; the last clean transition removes it even while that mount remains connected.

Register from a mount ownership subscription. Publish a pure model projection in a separate fixed subscription slot with the projection as an explicit non-function payload. Changing only a subscription closure keeps its old payload in the runtime. Keep child subscription slots stable so publishing state cannot cancel their calls. Dispose the registration on stop; publication cleanup must leave ownership intact.

A projection separates hasUnsavedChanges from protectBeforeUnload. Pending or uncertain writes can require protection without a dirty draft. A missing projection or no live owners yields type: "unavailable", which consumers must never treat as clean. Only known protection predicates warn; unavailable legacy pages retain their existing guard until their adapter migration.

A page with a controlled leave dialog can publish pendingNavigation, the target URL awaiting its existing leave decision. Clear it when the person stays. The shell can cancel a staged continuation from this read-only signal; it never chooses a leave action or releases page work.

Cards contain immutable plain-text summaries and ordered label/value strings. Their opaque handles belong to a live mount and pending cycle. Scope, token, revision or material changes invalidate them. Consume a handle through the human surface's decision helper, then revalidate the current model in the target Program before dispatching its typed Confirm/Cancel message. A feature's revision must cover the exact action payload and eligibility. The bridge does not infer business rules.

Shells can use a type-only PageStateReader import and discover the read-only port at document[Symbol.for("hypertea.page-state.reader.v1")], then listen for hypertea:page-state-available on that document. Subscribe and read immediately. Retained readers stay valid after the final owner stops and a new one registers. The decision helper belongs on the lazy human surface. It starts a plain target subscription chain; never forward through an effect's attributed dispatch.

Use anySignal(signals) from @pairshaped/hypertea/program to combine effect lifetimes. It preserves the first cancellation reason and removes its listeners when cancelled, including on Safari 16 where AbortSignal.any is unavailable.

Application shells can publish root tools alongside page tools through the same WebMCP registry. Names must remain unique across the document. Applications own read adapters, authorization, navigation policy and approval for writes.

About

Hyperapp-inspired Typescript with some Elm guardrails and WebMCP Support

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages