xrk-http-api
Skill140 starsChanged 8 months agoMITView on GitHub
当你需要开发或排查 HTTP API(core/*/http/*.js)、理解 HttpApi 基类、HttpApiLoader、业务层约定时使用。
In this repository43 other files it gives its agents.
- AGENTS.mdAGENTS.md
- docs/agents.mdAGENTS.md
- .cursor/rules/vibe-learn-craft.mdcCursor rule
- .cursor/rules/xrk-core-code.mdcCursor rule
- .cursor/rules/xrk-dev-requirements.mdcCursor rule
- .cursor/rules/xrk-infrastructure.mdcCursor rule
- .cursor/rules/xrk-project.mdcCursor rule
- .cursor/rules/xrk-third-party-plugins.mdcCursor rule
- accessibility-complianceSkill
- design-system-patternsSkill
- fronted-designSkill
- immersive-short-videoSkill
- interaction-designSkill
- mobile-android-designSkill
- mobile-ios-designSkill
- react-native-designSkill
- responsive-designSkill
- ui-ux-pro-maxSkill
- visual-design-foundationsSkill
- web-component-designSkill
- xrk-agent-runtimeSkill
- xrk-ai-workflowSkill
- xrk-app-devSkill
- xrk-authSkill
- xrk-coding-styleSkill
- xrk-configSkill
- xrk-crawlSkill
- xrk-dockerSkill
- xrk-docsSkill
- xrk-github-researchSkill
- xrk-infrastructureSkill
- xrk-llmSkill
- xrk-mcpSkill
- xrk-node-runtimeSkill
- xrk-pluginsSkill
- xrk-project-overviewSkill
- xrk-rendererSkill
- xrk-runtime-utilSkill
- xrk-subserverSkill
- xrk-system-coreSkill
- xrk-taskerSkill
- xrk-v3-apiSkill
- xrk-www-compatSkill
The file
Files
文档与代码
- 文档:
docs/http-api.md、docs/runtime-surface.md、docs/api-loader.md - 基类:
src/infrastructure/http/http.js - 加载器:
src/infrastructure/http/loader.js
核心约定
- API 模块放在
core/*/http/*.js,导出对象或继承 HttpApi。 - 路由数组
routes中声明 method/path/handler/middleware。 - 鉴权策略由各模块自行决定:system-Core HTTP 推荐在模块内通过
AgentRuntime.checkApiAuthorization(req)统一使用系统级 API Key,其他 Core 可自定义或选择接入该能力(详见xrk-authskill)。 - handler 用
req.agentRuntime或第三参AgentRuntime,勿global.AgentRuntime。
HttpResponse
import { HttpResponse } from '#utils/http-utils.js'。handler 用 return HttpResponse.success/error/asyncHandler/...,勿混用 res.json()。
success 响应形状(底层定义)
实现:src/utils/http-utils.js → HttpResponse.success。
第二参 data | 实际 JSON |
| 普通对象(非数组) | { success: true, message, ...data }(拍平,无外层 data) |
| 数组 / 标量 | { success: true, message, data: <值> } |
null / 省略 | { success: true, message } |
// 服务端
HttpResponse.success(res, { assessments, webVersion });
// → { success: true, message: '操作成功', assessments, webVersion }
HttpResponse.success(res, { data: config }); // 刻意要顶层 data 字段
// → { success: true, message: '操作成功', data: config }
HttpResponse.success(res, items); // 数组
// → { success: true, message: '操作成功', data: items }前端 / Core www 消费约定
禁止默认 const data = json.data 再读业务字段(对象拍平后常为 undefined)。
| 场景 | 做法 |
/xrk | import { unwrapSuccess } from './web-compat.js' |
| 其它产品 www | 内联同语义(见 skill xrk-www-compat) |
| 或 | 直接读顶层:json.assessments、json.configs |
function unwrapSuccess(json) {
if (!json?.success) throw new Error(json?.message || '请求失败');
if (json.data !== undefined) return json.data;
const { success, message, ...rest } = json;
return rest;
}需要「整包在 data 下」时,服务端应写 success(res, { data: payload })(如 kaguya、xiaozhi config)。
详见 docs/http-api.md「响应格式」。
Node 26(Core HTTP)
- 模块内出站请求:
fetch+AbortSignal.timeout(仅服务端;浏览器用abortTimeout,见xrk-www-compat)。 - catch:
Error.isError/normalizeError(见 skillxrk-node-runtime)。 - 禁止
node-fetch、手写AbortController超时。
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

