/** * endpoint-rule — 接口驱动的自定义检查维度。 * * 普通自定义维度走 LLM health composer(promptSection 喂 prompt);带 `endpoint` * 的维度则注册成独立 DoctorRule:doctor 运行时把 skill 完整快照 POST 给用户的 * 接口,接口按协议返回判定结果。适合"调外部服务做深度审查"(eg. 安全风险审查) * 这类靠 prompt 表达不了、需要真实逻辑/模型的场景。 * * 请求协议(doctor → endpoint): * POST Content-Type: application/json * { * "dimensionId": "deep-security-audit", * "params": { ... }, // YAML 里用户透传的自定义参数 * "skill": { * "name": "my-skill", * "content": "SKILL.md 全文", // file-skill / directory-skill 主文件 * "skillRoot": "/abs/path" | null, // git / inline 来源可能为 null * "ref": "abc1234" | null, // git 来源的 commit * "files": { "references/x.md": "...", "scripts/y.sh": "..." } // 子文件快照 * } * } * * 响应协议(endpoint → doctor): * { "status": "pass" | "warn" | "fail", "message": "...", "hint"?: "...", "detail"?: {...} } */ import type { DoctorRule, DoctorSeverity } from '../types/doctor.js'; export interface EndpointDimensionSpec { id: string; displayName: string; severity: DoctorSeverity; /** 检查接口地址。doctor 把 skill 快照 POST 到这里。 */ endpoint: string; /** 用户自定义参数,原样放进请求 body.params 透传给接口。 */ params?: Record; /** 是否把子文件(references / scripts 等)内容一起传。默认 true。 * 关掉可显著缩小 payload(接口只看主文件时)。 */ includeFiles?: boolean; /** 附加请求头(eg. 鉴权 token)。 */ headers?: Record; /** 单文件内容上限(字节),超过截断。默认 200KB。 */ maxFileBytes?: number; /** 整个 files 块的总上限(字节),超过停止收集。默认 2MB。 */ maxTotalBytes?: number; /** 是否放行私网/本机 endpoint。默认 false:hostname 为 localhost、*.local、::1、 * 127.0.0.0/8、10.0.0.0/8、172.16.0.0/12、192.168.0.0/16、169.254.0.0/16 * (含云 metadata 169.254.169.254)时直接 fail。动机:check() 会把 skill 完整 * 快照 POST 给 endpoint 并把响应回填进报告,等于一个 SSRF response oracle, * 默认不能指向内网/本机。确属可信内网检查服务时显式置 true 放行。 */ allowPrivateHost?: boolean; } /** 可注入的 fetch(测试用),默认走全局 fetch。 */ export type FetchFn = typeof fetch; /** * 把一个 endpoint spec 编译成 DoctorRule。check() 内组装 skill 快照、POST、 * 校验响应协议并映射成 DoctorRuleCheckOutcome。 * * 所有失败(网络错误 / 非 2xx / 非法 JSON / 协议字段缺失)都返回 status='fail', * 让用户立刻看到接口侧的问题,而不是静默放行。 */ export declare function makeEndpointRule(spec: EndpointDimensionSpec, fetchFn?: FetchFn): DoctorRule;