b4:routes
Use this whenCopy link to section: 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 importCopy link to section: Install and import
B4.run generates this module for your app. There is no 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 audienceCopy link to section: Compatibility and audience
| Surface | Kind | Audience | Stability |
|---|---|---|---|
b4:routes | generated types | application | supported |
The module has no runtime or purity classification because TypeScript erases every export.
Public exportsCopy link to section: Public exports
b4:routesCopy link to section: 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 contractsCopy link to section: Key contracts
Route paths and parametersCopy link to section: 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.
ToolsCopy link to section: 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.
StateCopy link to section: 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. Dynamic route parameters stay out of 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 guidesCopy link to section: 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.