Skip to Content
Runlane
Realtime

Frontend types

Type run outputs, metadata, and stream parts in the browser without bundling backend code.

The hooks and the client take a type argument. It types run.output, run.meta, stream names, and stream parts. Pick one of three ways to supply it:

Your setupUse
Frontend and tasks in the same repoImport the task type
Frontend in another repoGenerate types
You want to write the types yourselfDeclare types by hand

All three add types only. They add no code to your bundle and do not check values at runtime. The server checks output and stream parts when the task writes them.

Import the task type

Use import type with typeof:

import { useRun, useRunStream } from '@runlane/react'

import type { writeAnswer } from './tasks/write-answer'

const { run } = useRun<typeof writeAnswer>(runId)
const { parts } = useRunStream<typeof writeAnswer>(runId, 'answer')

import type is removed when your code is built. No task code, Node.js modules, or secrets reach the browser.

In a monorepo, export the type from the backend package:

packages/backend/src/index.ts
export type { writeAnswer } from './tasks/write-answer'

Generate types

When the frontend lives in another repo, generate a types file from the backend. Run this in the backend's app folder:

npm exec -- runlane types --out src/runlane-types.ts

It writes one type per task, named from the task ID. For example, answer.write becomes AnswerWrite. Copy the file into the frontend and commit it there:

import type { AnswerWrite } from './runlane-types'

const { run } = useRun<AnswerWrite>(runId)
const { parts } = useRunStream<AnswerWrite>(runId, 'answer')

Run the command again whenever the task schemas change. Your schemas must support JSON Schema conversion: Zod 4.2+, ArkType 2.1.28+, or Valibot with @valibot/to-json-schema. See generate frontend types for options and errors.

Declare types by hand

Use RunTypes to describe what the server sends:

import type { RunTypes } from '@runlane/react'

export type WriteAnswer = RunTypes<{
  output: { parts: number }
  meta: { progress: number; total: number }
  streams: { answer: string }
}>
const { run } = useRun<WriteAnswer>(runId)
run?.meta?.progress // number | undefined

Every key is optional. This is also the only way to type meta. With a task type, meta is plain JSON.

RunTypes is also exported from @runlane/realtime/client and @runlane/contracts/realtime.

Rules to know

  • Output is the returned value. run.output uses the type your task returns, before any output schema transforms or defaults. The server sends the stored value unchanged.
  • Stream parts are parsed values. Parts use the stream schema's output type, because the task saves parsed parts.
  • Several streams need a second type argument. Write useRunStream<typeof task, 'answer'> for the exact part type. With only the first argument, parts are a union of every stream's type.
  • No type argument means JSON. Without one, output and parts are JsonValue, meta is JsonObject, and any stream name is allowed.

Type helpers

Use these to name the types in your own code:

import type { RunOutput, RunStreamPart } from '@runlane/react'

type Answer = RunOutput<typeof writeAnswer> // { parts: 10 }
type AnswerPart = RunStreamPart<typeof writeAnswer, 'answer'> // string

See frontend type helpers for the full list.

On this page