yaml by vercel-labs/json-render
npx skills add https://github.com/vercel-labs/json-render --skill yaml@json-render/core 的 YAML 传输格式。通过流式 YAML 实现渐进式渲染和精准编辑。
yaml-spec, yaml-edit, yaml-patch, diff)TransformStreamimport { yamlPrompt } from "@json-render/yaml";
import { catalog } from "./catalog";
// 独立模式 (LLM 仅输出 YAML)
const systemPrompt = yamlPrompt(catalog, {
mode: "standalone",
editModes: ["merge"],
customRules: ["Always use dark theme"],
});
// 内联模式 (LLM 以对话方式响应,将 YAML 包裹在围栏中)
const chatPrompt = yamlPrompt(catalog, { mode: "inline" });
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
选项:
system (string) — 自定义系统消息介绍mode ("standalone" | "inline") — 输出模式,默认为 "standalone"customRules (string[]) — 附加到提示的额外规则editModes (EditMode[]) — 要记录的编辑模式,默认为 ["merge"]使用 pipeYamlRender 作为 pipeJsonRender 的即插即用替代品:
import { pipeYamlRender } from "@json-render/yaml";
import { createUIMessageStream, createUIMessageStreamResponse } from "ai";
const stream = createUIMessageStream({
execute: async ({ writer }) => {
writer.merge(pipeYamlRender(result.toUIMessageStream()));
},
});
return createUIMessageStreamResponse({ stream });
对于多轮编辑,传递之前的规范:
pipeYamlRender(result.toUIMessageStream(), {
previousSpec: currentSpec,
});
该转换器识别四种围栏类型:
yaml-spec — 完整规范,逐行渐进式解析yaml-edit — 与当前规范深度合并的部分 YAML (RFC 7396)yaml-patch — RFC 6902 JSON Patch 行diff — 应用于序列化规范的统一差异import { createYamlStreamCompiler } from "@json-render/yaml";
const compiler = createYamlStreamCompiler<Spec>();
// 从任何来源接收数据块时进行推送
const { result, newPatches } = compiler.push("root: main\n");
compiler.push("elements:\n main:\n type: Card\n");
// 在流结束时刷新剩余数据
const { result: final } = compiler.flush();
// 重置以处理下一个流 (可选择使用初始状态)
compiler.reset({ root: "main", elements: {} });
方法:push(chunk), flush(), getResult(), getPatches(), reset(initial?)
YAML 包使用核心中的通用编辑模式系统:
import { buildEditInstructions, buildEditUserPrompt } from "@json-render/core";
import type { EditMode } from "@json-render/core";
// 为 YAML 格式生成编辑指令
const instructions = buildEditInstructions({ modes: ["merge", "patch"] }, "yaml");
// 使用当前规范上下文构建用户提示
const userPrompt = buildEditUserPrompt({
prompt: "Change the title to Dashboard",
currentSpec: spec,
config: { modes: ["merge"] },
format: "yaml",
serializer: (s) => yamlStringify(s, { indent: 2 }).trimEnd(),
});
对于自定义解析,使用导出的常量:
import {
YAML_SPEC_FENCE, // "```yaml-spec"
YAML_EDIT_FENCE, // "```yaml-edit"
YAML_PATCH_FENCE, // "```yaml-patch"
DIFF_FENCE, // "```diff"
FENCE_CLOSE, // "```"
} from "@json-render/yaml";
| 导出项 | 描述 |
|---|---|
yamlPrompt | 从目录生成 YAML 系统提示 |
createYamlTransform | 用于 YAML 围栏的 AI SDK TransformStream |
pipeYamlRender | 便捷的管道包装器 (替代 pipeJsonRender) |
createYamlStreamCompiler | 带补丁发射功能的流式 YAML 解析器 |
YAML_SPEC_FENCE | yaml-spec 的围栏常量 |
YAML_EDIT_FENCE | yaml-edit 的围栏常量 |
YAML_PATCH_FENCE | yaml-patch 的围栏常量 |
DIFF_FENCE | diff 的围栏常量 |
FENCE_CLOSE | 围栏关闭常量 |
diffToPatches | 重新导出:对象差异到 JSON Patch |
deepMergeSpec | 重新导出:RFC 7396 深度合并 |
每周安装量
90
代码仓库
GitHub 星标数
13.3K
首次出现
12 天前
安全审计
已安装于
codex88
cursor87
gemini-cli86
kimi-cli86
opencode86
github-copilot86
YAML wire format for @json-render/core. Progressive rendering and surgical edits via streaming YAML.
yaml-spec, yaml-edit, yaml-patch, diff)TransformStream that converts YAML fences into json-render patchesimport { yamlPrompt } from "@json-render/yaml";
import { catalog } from "./catalog";
// Standalone mode (LLM outputs only YAML)
const systemPrompt = yamlPrompt(catalog, {
mode: "standalone",
editModes: ["merge"],
customRules: ["Always use dark theme"],
});
// Inline mode (LLM responds conversationally, wraps YAML in fences)
const chatPrompt = yamlPrompt(catalog, { mode: "inline" });
Options:
system (string) — Custom system message intromode ("standalone" | "inline") — Output mode, default "standalone"customRules (string[]) — Additional rules appended to prompteditModes (EditMode[]) — Edit modes to document, default ["merge"]Use pipeYamlRender as a drop-in replacement for pipeJsonRender:
import { pipeYamlRender } from "@json-render/yaml";
import { createUIMessageStream, createUIMessageStreamResponse } from "ai";
const stream = createUIMessageStream({
execute: async ({ writer }) => {
writer.merge(pipeYamlRender(result.toUIMessageStream()));
},
});
return createUIMessageStreamResponse({ stream });
For multi-turn edits, pass the previous spec:
pipeYamlRender(result.toUIMessageStream(), {
previousSpec: currentSpec,
});
The transform recognizes four fence types:
yaml-spec — Full spec, parsed progressively line-by-lineyaml-edit — Partial YAML deep-merged with current spec (RFC 7396)yaml-patch — RFC 6902 JSON Patch linesdiff — Unified diff applied to serialized specimport { createYamlStreamCompiler } from "@json-render/yaml";
const compiler = createYamlStreamCompiler<Spec>();
// Feed chunks as they arrive from any source
const { result, newPatches } = compiler.push("root: main\n");
compiler.push("elements:\n main:\n type: Card\n");
// Flush remaining data at end of stream
const { result: final } = compiler.flush();
// Reset for next stream (optionally with initial state)
compiler.reset({ root: "main", elements: {} });
Methods: push(chunk), flush(), getResult(), getPatches(), reset(initial?)
The YAML package uses the universal edit mode system from core:
import { buildEditInstructions, buildEditUserPrompt } from "@json-render/core";
import type { EditMode } from "@json-render/core";
// Generate edit instructions for YAML format
const instructions = buildEditInstructions({ modes: ["merge", "patch"] }, "yaml");
// Build user prompt with current spec context
const userPrompt = buildEditUserPrompt({
prompt: "Change the title to Dashboard",
currentSpec: spec,
config: { modes: ["merge"] },
format: "yaml",
serializer: (s) => yamlStringify(s, { indent: 2 }).trimEnd(),
});
For custom parsing, use the exported constants:
import {
YAML_SPEC_FENCE, // "```yaml-spec"
YAML_EDIT_FENCE, // "```yaml-edit"
YAML_PATCH_FENCE, // "```yaml-patch"
DIFF_FENCE, // "```diff"
FENCE_CLOSE, // "```"
} from "@json-render/yaml";
| Export | Description |
|---|---|
yamlPrompt | Generate YAML system prompt from catalog |
createYamlTransform | AI SDK TransformStream for YAML fences |
pipeYamlRender | Convenience pipe wrapper (replaces pipeJsonRender) |
createYamlStreamCompiler | Streaming YAML parser with patch emission |
YAML_SPEC_FENCE | Fence constant for yaml-spec |
Weekly Installs
90
Repository
GitHub Stars
13.3K
First Seen
12 days ago
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex88
cursor87
gemini-cli86
kimi-cli86
opencode86
github-copilot86
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
118,000 周安装
Java 21+ 专家技能:现代 Java 开发、Spring Boot 3.x、JVM 性能优化与云原生架构
138 周安装
Tauri v2 权限配置指南:安全控制命令与系统资源访问
141 周安装
ASR语音转文本技能:使用z-ai-web-dev-sdk实现音频转录与语音识别
142 周安装
Web应用测试指南:Playwright自动化、E2E测试与视觉测试最佳实践
144 周安装
GitLab CLI 集成技能:使用 glab 命令行工具自动化 GitLab 任务
145 周安装
UI/UX 打磨迭代工作流:使用AI智能体进行10+次增量优化,打造世界级用户体验
144 周安装
YAML_EDIT_FENCE| Fence constant for yaml-edit |
YAML_PATCH_FENCE | Fence constant for yaml-patch |
DIFF_FENCE | Fence constant for diff |
FENCE_CLOSE | Fence close constant |
diffToPatches | Re-export: object diff to JSON Patch |
deepMergeSpec | Re-export: RFC 7396 deep merge |