import type { Market, Money, SubscriptionTier, SuggestionCategory, TriggerType } from './beacon-mcp-tools-v1.js'; export type { Market, Money, SubscriptionTier, SuggestionCategory, TriggerType }; /** 批量拉规则(client 24h 全量同步) */ export declare const BEACON_RULES_PATH: "/v1/beacon/rules"; /** 单条决策(client 实时调,Brain 返回个性化建议) */ export declare const BEACON_RULES_DECIDE_PATH: "/v1/beacon/rules/decide"; /** 跨工作空间的契约版本标记 */ export declare const BEACON_RULE_PROTOCOL_VERSION: "v1"; /** * trigger_pattern JSONB 形状(Phase 1 MVP): * 用 key/value 描述"什么状况触发这条规则"。 * Brain 决策端用模式匹配 + 阈值比较;client 24h 同步后本地决策树也按此 evaluate。 * * 例(D 时效预警): * { kind: 'asset_expiry', asset_type: 'domain', within_days_lte: 7 } * 例(B 异常): * { kind: 'session_burn_anomaly', burn_usd_per_hour_gte: 5 } */ export interface RuleTriggerPattern { kind: string; /** 任意机读字段;client / Brain 共用 evaluator */ [key: string]: unknown; } /** * decision_logic 描述"匹配后给什么样的 suggestion"。 * Phase 1 MVP 走简单 template 路线;Phase 2 引入 ml_model_version。 */ export interface RuleDecisionLogic { /** 'template' | 'ml_v1' | 'experiment'(Phase 1 主用 'template') */ strategy: 'template' | 'ml_v1' | 'experiment'; /** strategy=template 时,该字段必填:对应 suggestion_template 的 key */ template_key?: string; /** strategy=experiment 时,变体配比 */ experiment_variants?: Record; /** 评分函数所需参数(Phase 1 选填) */ scoring?: Record; } /** * suggestion_template 中英分语,client 按 user_profile.market 选语言。 * placeholder 用 {{name}} 风格,client / Brain evaluator 都按此 fill。 */ export interface RuleSuggestionTemplate { /** 给 agent 解释给用户的英文提示 */ reasoning_en: string; /** 中文版 */ reasoning_zh: string; /** 命中后的预估价值 — 如 "省 $30/月" / "续费防止域名过期" */ estimated_value?: Money; /** 用户点击后跳转 — 续费 / 升级 / 安装 skill */ action_url?: string; } /** * beacon_rules 表 row 在网络层的标准映射。 * 顺序、字段名都跟 PRD-SKILLFM-BRAIN-RULE-CENTER-V1.md §3 schema 完全对齐。 */ export interface BeaconRule { /** UUID 或语义化 id;Phase 1 用 'D3_domain_7d_warning' 形式 */ rule_id: string; /** 触发场景大类 A-H,见 beacon-mcp-tools-v1.ts SuggestionCategory */ category: SuggestionCategory; /** 关联的 trigger_type(beacon-mcp-tools-v1.ts) — 形如 'D3_domain_7d_warning' */ trigger_type: TriggerType; /** JSONB 模式 */ trigger_pattern: RuleTriggerPattern; /** 决策逻辑(template / ml / experiment) */ decision_logic: RuleDecisionLogic; /** 建议模板(中英) */ suggestion_template: RuleSuggestionTemplate; /** Pro-only 规则:Free 命中时 should_suggest=true 但 is_pro_locked=true */ is_pro_only: boolean; /** 单调递增,client since_version=N 拉增量用 */ version: number; /** 0-100;Phase 1 灰度发布用 */ rollout_percent: number; /** false → client 即使 cache 也不应再触发 */ is_active: boolean; /** 实验 id(可选);决策结果须把 experiment_variant 透传给 client + feedback 上报 */ experiment_id?: string; /** 适用市场过滤,可选;不写则全市场命中 */ applicable_markets?: Market[]; /** 适用订阅 tier 过滤,可选;不写则全 tier 命中 */ applicable_tiers?: SubscriptionTier[]; /** ISO 8601 UTC,Brain 写入,client 用作展示 */ created_at?: string; updated_at?: string; } /** 请求 query params */ export interface BeaconRulesRequestQuery { /** A-H 单选;省略则返回全分类 */ category?: SuggestionCategory; /** 增量同步 — 只回 version > since_version 的规则 */ since_version?: number; /** 默认仅 is_active=true;internal 工具可置 false */ include_inactive?: boolean; } /** 请求 headers */ export interface BeaconRulesRequestHeaders { /** v0.2 一致:长效 agent_token */ 'X-Agent-Token': string; /** client 版本(observability) */ 'X-Skillfm-Local-Version'?: string; Accept?: 'application/json'; } /** 200 OK 成功响应 */ export interface BeaconRulesResponse { /** 服务端最新 rule version(client 下次 since_version 用此) */ version: number; /** 命中规则;空数组也是合法 */ rules: BeaconRule[]; /** ISO 8601 UTC */ generated_at: string; } /** * 调用方传入"现在发生了什么"+ "用户是谁",Brain 决策返回是否应给建议。 * * trigger_context 例(F 用户口头提到副业): * { mention_keywords: ['side income', 'monetize'], chat_window_size: 5 } * * ⚠️ BYOK 红线: trigger_context **禁止**包含 api_key / cookie / token / bearer / session_id */ export interface BeaconDecideUserProfile { /** 必传 */ market: Market; /** 必传 */ is_pro: boolean; /** 订阅 tier 细分(免费 / 月付 / 年付 / team / trial) */ tier?: SubscriptionTier; /** 用户偏好 hash(client 同步给 Brain,让决策端考虑 quietHours / disabledCategories) */ preferences_hash?: string; /** 当前会话已经触发过的 rule_id(去重) */ session_already_suggested?: string[]; /** 当前 IANA 时区,Brain 决策端判断 quietHours */ timezone?: string; /** 可选用户标识(脱敏 hash,Brain 用作个性化 cache key);**不要** 传明文 user_id */ user_hash?: string; } export interface BeaconDecideRequest { /** 形如 'D3_domain_7d_warning';客户端必传 */ trigger_type: TriggerType; /** 触发上下文,见上方 BYOK 红线注释 */ trigger_context: Record; /** 用户画像 */ user_profile: BeaconDecideUserProfile; /** 决策时戳(client 端时间,ISO 8601);Brain 用作幂等 + 限流 */ client_timestamp?: string; } /** 200 OK 决策结果(无论是否建议都是 200) */ export interface BeaconDecideResponse { /** false → client 静默,不弹建议 */ should_suggest: boolean; /** 命中规则 id;should_suggest=false 时仍可填(便于 client 调试) */ rule_id?: string; /** should_suggest=true 时必填 */ suggestion?: BeaconSuggestion; /** 命中实验时透传变体名,client feedback 必带回 */ experiment_variant?: string; /** should_suggest=false 时给 client 的人话理由,便于本地决策树调优 */ reason?: 'no_match' | 'in_quiet_hours' | 'category_disabled' | 'session_quota_exceeded' | 'daily_quota_exceeded' | 'duplicate_in_session' | 'rolled_out_off' | 'other'; } /** * suggestion 跟 beacon-mcp-tools-v1.ts 中各 tool output 的 reasoning / estimated_value * 字段语义对齐;Pro-locked 规则在此显式标记,client 决定是否弹"升 Pro 解锁"卡片。 */ export interface BeaconSuggestion { /** 给 agent 解释给用户的英文提示 */ reasoning_en: string; /** 中文 */ reasoning_zh: string; /** 决策端置信度(0-1);可选 */ confidence?: number; /** 预估对用户的价值,如 { amount: 30, currency: 'USD' } */ estimated_value?: Money; /** Free 用户命中 Pro-only 规则时 = true;client 应渲染升级卡 */ is_pro_locked: boolean; /** 续费 / 升级 / 安装 skill 的跳转 */ action_url?: string; /** session 内本次建议唯一 id,feedback 上报必带回 */ suggestion_id?: string; } export declare const BEACON_RULE_ERROR_CODES: { readonly AUTH_MISSING_TOKEN: "BEACON.RULES.AUTH.MISSING_TOKEN"; readonly AUTH_BAD_TOKEN: "BEACON.RULES.AUTH.BAD_TOKEN"; readonly BAD_REQUEST: "BEACON.RULES.BAD_REQUEST"; /** trigger_context 含敏感字段 */ readonly BYOK_VIOLATION: "BEACON.RULES.BYOK_VIOLATION"; readonly RATE_LIMITED: "BEACON.RULES.RATE_LIMITED"; readonly INTERNAL: "BEACON.RULES.INTERNAL"; }; export type BeaconRuleErrorCode = (typeof BEACON_RULE_ERROR_CODES)[keyof typeof BEACON_RULE_ERROR_CODES]; export interface BeaconRuleErrorResponse { ok: false; error: { code: BeaconRuleErrorCode; message: string; details?: Record; }; } /** GET /v1/beacon/rules 的统一 envelope */ export type BeaconRulesEnvelope = { ok: true; data: BeaconRulesResponse; } | BeaconRuleErrorResponse; /** POST /v1/beacon/rules/decide 的统一 envelope */ export type BeaconDecideEnvelope = { ok: true; data: BeaconDecideResponse; } | BeaconRuleErrorResponse; //# sourceMappingURL=beacon-rule-protocol-v1.d.ts.map