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.
| Property | Type | Description | Source |
|---|---|---|---|
pattern? | string | URI template pattern for parameterized resources | source |
description | string | Resource description | source |
title? | string | source | |
paramsSchema | Schema<TParams> | Zod schema for 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 server configuration | source |
Resource<TParams, TData>
Exports
Functions
| Name | Description | Source |
|---|---|---|
resource | Create a typed resource definition. | source |
Types
Constants
| Name | Description | Source |
|---|---|---|
resourceRegistry | Shared resource registry value. | source |