Import
import { resource, resourceRegistry } from "veryfront/resource";
Examples
import { resource } from "veryfront/resource";
import { defineSchema } from "veryfront/schemas";
const docsBySection: Record<string, string> = {
agents: "Agents accept messages, tools, context, and runtime options.",
tools: "Tools expose schema-backed callable capabilities.",
};
const docs = resource({
pattern: "docs/:section",
description: "API documentation",
paramsSchema: defineSchema((v) => v.object({ section: v.string() }))(),
load: ({ section }) => {
return { content: docsBySection[section] ?? "Section not found." };
},
});
const result = await docs.load({ section: "agents" });
API
resource(config)
Create a typed resource definition with unique URI-template parameter names.
| Property | Type | Description | Source |
|---|---|---|---|
pattern? | string | URI template using :name parameters. Hierarchical (/users/:id) and rootless (docs:collection/:id) paths are supported, as are embedded and query parameters (/file-:base.:ext?lang=:lang). Opaque identifiers such as urn:isbn remain literal. Parameter names must be unique and separated by literal text; the first following literal delimits an embedded value. A : directly following an alphanumeric character is always data, never a parameter: write /files/file-:id, not /files/file:id. This keeps opaque colon identifiers literal under one uniform rule. | source |
description | string | Resource description | source |
title? | string | source | |
paramsSchema | Schema<TParams> | Schema that validates and transforms URI parameters | source |
load | (params: TParams) => Promise<TData> | TData | Function returning resource content | source |
subscribe? | (params: TParams) => AsyncIterable<TData> | Async iterable for real-time resource updates | source |
mcp? | McpConfig | MCP configuration. enabled: false hides the resource from lists and reads. | source |
Resource<TParams, TData>
Exports
Functions
| Name | Description | Source |
|---|---|---|
resource | Create a typed resource definition with unique URI-template parameter names. | source |
Types
Constants
| Name | Description | Source |
|---|---|---|
resourceRegistry | Shared resource registry value. | source |