b4:routes
Use this when
Import from b4:routes when application code needs route paths, dynamic parameters, tools, or state keyed by a route path. These are generated types, not runtime values. Run b4 typegen, b4 dev, or b4 build before type-checking code that imports them.
Install and import
The module is generated with your B4.run app; it is not a package to install.
import type { B4RouteParams, B4RoutePath, B4RouteTools, RouteTools } from "b4:routes"Do not hand-edit .b4/b4.generated.d.ts. Change routes, tools, or state.ts, then regenerate it.
Compatibility and audience
| Surface | Kind | Audience | Stability |
|---|---|---|---|
b4:routes | generated types | application | supported |
The module has no runtime or purity classification because every export is erased by TypeScript.
Public exports
b4:routes
| Generated export | Responsibility |
|---|---|
B4RoutePath | Union of discovered route pathnames. |
B4RouteParams | Map each route to its dynamic path parameters. |
B4RouteTools | Map each route to its generated async tool call signatures. |
RouteTools | Select generated tools for one B4RoutePath. |
B4RouteState | Conditionally map routes that declare state to their state fields. |
RouteState | Conditionally select state for one B4RoutePath. |
B4RoutePath, B4RouteParams, B4RouteTools, and RouteTools are always generated. B4RouteState and RouteState are generated only when at least one discovered route declares state.ts and contributes a route-state entry.
Key contracts
Route paths and parameters
With no routes, B4RoutePath is never and the parameter map is empty. A dynamic segment becomes string, a catch-all becomes string[], and an optional catch-all becomes an optional string[] property. B4RouteParams tells callers which dynamic-segment fields to include in invocation input; B4.run derives the names, not the values, from the route path. For ordinary [param] agent routes, B4.run separates those fields from message input and exposes them to middleware and tool context instead of merging them into B4RouteState.
Tools
B4RouteTools includes routes with discovered or capability-contributed tools and omits routes with none. Members are readonly and return Promise<output>. A no-input tool renders as () => Promise<output>, not (input: void) => Promise<output>.
Behavior contract generated-routes.tool-signatures
B4RouteTools omits routes with no tools and renders void-input tools as zero-argument functions returning promises.
State
State types come only from fields discovered in a route's state.ts. When state exports are present, RouteState<P> indexes B4RouteState[P] for a route in that map; it does not merge dynamic route parameters into state.
Behavior contract generated-routes.state-conditional
B4RouteState and RouteState are generated when route state is present and omitted when state types are not supplied.
Examples and related guides
import type { B4RouteParams, RouteTools } from "b4:routes"
type TenantParams = B4RouteParams["/support/[tenant]"]
type SupportTools = RouteTools<"/support/[tenant]">Continue with State, Tools, Routes, and CLI Reference.