export interface LocalizedText { zh: string; en: string; } /** PRD §4.5: 6 阶段用户画像 */ export type Stage = 'unknown' | 'onboarding' | 'activated' | 'producing' | 'earning' | 'champion'; export type MoodSignal = 'engaged' | 'exploring' | 'stalled' | 'churning' | 'celebrating'; /** envelope.user —— 客户端必依赖字段,platform 可扩展但不可删 */ export interface UserContractMinimal { userId: string | null; stage: Stage; mood_signal: MoodSignal; subscription: { plan: 'adulting_gift' | 'master' | null; status: 'active' | 'trialing' | 'canceled' | 'past_due' | 'none'; trialEndsAt: string | null; } | null; limits: { adultingGiftTrialEndsAt: string | null; solutionTrials: Record; }; journey: { days_since_signup: number; total_runs: number; last_active_at: string | null; last_brain_run_at: string | null; earned_total_cny: number; earned_this_month_cny: number; }; } /** PRD Book 4 §3 "六铁律": dialogue_flow 客户端必须原样呈现,不改写 */ export interface DialogueFlowContract { flow_id: string; current_turn: number; total_turns: number; this_turn: { semantic_goal: string; talk_points: string[]; end_with: 'question' | 'pause' | 'call_to_action'; }; next_turn_hints: { if_user_engages: string; if_user_hesitates: string; if_user_declines: string; }; gentle_exit: { semantic_goal: string; talk_points: string[]; }; success_criterion: string; } /** envelope.error —— 业务 (soft) 错误里的核心字段 */ export interface EnhancedErrorContract { code: string; severity: 'info' | 'warn' | 'block'; user_message: LocalizedText; agent_directive: LocalizedText; dialogue_flow: DialogueFlowContract | null; } /** * Apprentice/Tier-A 回流快照。 * The shape mirrors the capsule-sdk clean-room runtime schema. */ export interface CapsuleRuntimeState { confidence: number; success_streak: number; env_fingerprint: { platform: string; version: string; region: 'CN' | 'US' | 'EU' | 'CN_overseas'; }; outcome: { status: 'success' | 'failed' | 'pending' | 'aborted'; score: number; }; asset_id: string; blast_radius: { files: number; lines: number; }; skill_slug: string; capsule_case_id: string; emitted_at: string; } /** * §3.6 LlmTask kind + ImageGenParams — 2026-04-24 扩展 * 与 sdk/skill-sdk/src/types/contract.ts 和 platform/api/src/brain/types.ts 对齐 */ export type LlmTaskKindContract = 'text' | 'image_generation'; export interface ImageGenParamsContract { prompt: string; style_refs?: string[]; subject_ref?: string; aspect_ratio?: '1:1' | '4:3' | '3:4' | '16:9' | '9:16'; n?: number; image_model_hint?: string | null; } /** pending_llm_tasks item — agent 要执行的 LLM 任务 */ export interface LlmTaskContract { task_id: string; /** §3.6 缺省 'text' 向后兼容 */ kind?: LlmTaskKindContract; prompt: string; system?: string; schema?: Record; max_tokens?: number; temperature?: number; /** §3.6 仅 kind='image_generation' 时使用 */ image_params?: ImageGenParamsContract; visibility: 'protected' | 'private' | 'public'; narration_pre_zh?: string; narration_post_zh?: string; expected_seconds?: number; } /** pipeline 进度叙事(用户看的是 label,agent 看的是 round 数) */ export interface PipelineProgressContract { current_round: number; total_estimate: number; hard_cap: number; step_narration: { current_step_label_zh: string; current_step_label_en: string; current_step_icon: string; completed_steps: unknown[]; eta_seconds: number | null; }; } /** envelope.meta 契约子集 */ export interface MetaContract { requestId: string; ts: string; version: 'v2'; pending_llm_tasks?: LlmTaskContract[]; continuation_token?: string; pipeline_progress?: PipelineProgressContract; capsule_runtime_state?: import('./safe-skill-observation-v1.js').CapsuleRuntimeStateV1; capsule_case_id?: string; } /** envelope-at-top (PRD §4.6 业务错误 + 普通成功返回) */ export interface EnvelopeContract { ok: boolean; data: T | null; error: EnhancedErrorContract | null; capsule_runtime_state?: CapsuleRuntimeState; capsule_case_id?: string; user: UserContractMinimal; continuity: { last_topic: string | null; unfinished_task: unknown | null; pending_suggestion: unknown | null; }; next_actions: unknown[]; dialogue_flow: DialogueFlowContract | null; conversation_hints: unknown[]; meta: MetaContract; } /** * 5 维度算法指标 (0-1) — scoring.ts 输出. * 维度语义见 solutions/content-factory/business/scoring.ts. */ export interface AlgoMetrics { burstiness: number; lexical_diversity: number; readability: number; keyword_density: number; structural: number; } /** 反 AI 品牌徽章 — 给 SDK 渲染成"人味拉满/自然度 Plus/过关/再练一版" */ export interface AntiAiBadge { level: 'S' | 'A' | 'B' | 'C'; /** 用户面文案, 不含工程术语. e.g. "人味拉满 🏆" */ label_zh: string; /** 0-1, 最低维度距阈值的距离; 越高徽章越稳 */ confidence: number; } /** * 具体到位置的 evidence. PRD §2.6 文案规范要求: * - 正面 positive + 改进 improvement 双栏 * - 直呼"你", 不教师腔 (禁止"应该/必须/建议"成句) * - locator 指向具体段落 + snippet (≤ 24 字) */ export interface QualityEvidence { kind: 'positive' | 'improvement'; /** reason_code token. e.g. HUMAN_BURSTINESS_HIGH / IMPROVE_ANTI_PATTERN */ code: string; /** 用户面文案, ≤ 32 字 */ zh: string; locator?: { paragraph_index: number; char_span?: [number, number]; /** 原文片段 ≤ 24 字 */ snippet?: string; }; } /** * envelope.final.quality 新 shape. * - 向后兼容: 旧字段 (passed / dimensions / suggestions) 保留 * - 新字段: overall_score / dim_scores (强类型) / anti_ai_badge / human_like_score / * evidence[] / reason_codes[] */ export interface SkillRunQuality { /** 旧字段保留 */ passed: boolean; suggestions: string[]; /** 旧字段: dim_scores 的 legacy mirror (Record) — 兼容老客户端 */ dimensions?: Record; /** v1.1 新增 — 0-10 总分, 两位小数 */ overall_score: number; /** * v1.1 新增 — 强类型 5 维 (0-1 范围, 与 AlgoMetrics 一致). * 注: SDK 的 renderQualityCard 内部把 0-1 映射到 10 分制进度条用于显示. * overall_score 是另算的 0-10 加权综合分, 不要把这两组混淆. */ dim_scores: AlgoMetrics; /** v1.1 新增 — 品牌等级 */ anti_ai_badge: AntiAiBadge; /** v1.1 新增 — 专属人味指数 0-10, ≠ overall_score */ human_like_score: number; /** v1.1 新增 — 分 positive/improvement 双栏, 带 locator */ evidence: QualityEvidence[]; /** v1.1 新增 — 机读 token, 前端 tooltip 或统计 */ reason_codes: string[]; } /** * F1 - Brain run 成功 final 态 (wrapped) * HTTP: 200 * 形态: { task_id, is_trial, is_demo, output, envelope } */ export interface BrainRunFinalResponse { task_id: string; is_trial: boolean; is_demo: boolean; output: Record; quality_score?: number | null; /** * v1.1: quality_report 可以是新 SkillRunQuality 或老 Record 兼容形态. * 新版 SDK / skill 使用 SkillRunQuality; 老版 skill 仍可返回 loose Record. */ quality_report?: SkillRunQuality | Record | null; envelope: EnvelopeContract>; } /** * F2 - Brain run pipeline 中间态 (wrapped) * HTTP: 200 * 形态: { task_id, is_trial, is_demo, envelope: { meta.pending_llm_tasks + continuation_token + pipeline_progress } } */ export interface BrainRunPendingResponse { task_id: string; is_trial: boolean; is_demo: boolean; envelope: EnvelopeContract>; } /** * F3 - Brain run trial_exhausted (envelope-at-top, PRD §4.6) * HTTP: 200 * 形态: envelope 字段直接在 top level,没有外层包装 * error.code = 'BRAIN.QUOTA.TRIAL_EXHAUSTED' */ export type BrainRunTrialExhaustedResponse = EnvelopeContract; /** * F4 - Brain run pipeline_error (envelope-at-top, PRD §4.6) [问题 B 修后] * HTTP: 200 * 形态: 同 F3 * error.code = 'BRAIN.PIPELINE.ERROR' * * 修前(2.1.7 及之前): HTTP 500 + { error, error_type, envelope: {...} } wrapped * 修后: HTTP 200 + envelope-at-top (跟 trial_exhausted 一致) */ export type BrainRunPipelineErrorResponse = EnvelopeContract; /** 联合类型:任意一种 brain.run 响应 */ export type BrainRunResponse = BrainRunFinalResponse | BrainRunPendingResponse | BrainRunTrialExhaustedResponse | BrainRunPipelineErrorResponse; /** 是 top-level envelope 形态吗? (F3 / F4) * 判据: ok/meta/user 三个关键字段都在 top level(即可直接 envelope.error 读取), * legacy `envelope` 字段允许共存(向后兼容期 platform/api 双发 shape)。 */ export declare function isEnvelopeAtTopShape(r: unknown): r is EnvelopeContract; /** 是 wrapped 形态吗? (F1 / F2) —— 有 task_id top-level + envelope.ok===true 就是正常 wrapped */ export declare function isWrappedResponseShape(r: unknown): r is BrainRunFinalResponse | BrainRunPendingResponse; /** 是 pipeline 中间态吗? (F2) */ export declare function isPendingLlmTasksShape(r: unknown): r is BrainRunPendingResponse; /** 是 trial_exhausted 错误吗? */ export declare function isTrialExhaustedShape(r: unknown): r is BrainRunTrialExhaustedResponse; /** 是 pipeline_error 错误吗? (F4 — 问题 B 修后形态) */ export declare function isPipelineErrorShape(r: unknown): r is BrainRunPipelineErrorResponse; export * from './safe-action-envelope-v1.js'; //# sourceMappingURL=index.d.ts.map