初始化提交

This commit is contained in:
chenxin committed 2026-08-21 16:00:13 +08:00
commit 887c1f449e
963 files changed
+166869

No files matched your search

File diff suppressed because it is too large. Load diff
+254
View File
@@ -0,0 +1,254 @@
/**
* 归档页(记忆时间河)类型定义。
*
* 从后端 Run 模型映射到 UI 展示层的 ArchiveEvent 中间表示。
* Run → ArchiveEvent 映射关系:
* - 每个 completed/failed run → 一个事件卡片
* - run.origin → 事件类型(chat→episodic, evolution→evolution, reflection→reflection)
* - run.goal → 事件标题
* - run.created_at → 时间戳
*/
import type { Run } from "./api";
/** 时间河事件类型(与 TimeRiver 筛选同) */
export type ArchiveEventType =
| "episodic"
| "emotional"
| "evolution"
| "reflection"
| "milestone";
/** 归档页展示的一条事件 */
export interface ArchiveEvent {
id: string;
type: ArchiveEventType;
title: string;
desc: string;
timeLabel: string;
tags: string[];
milestone?: boolean;
content: string;
createdAt: string;
source: string;
}
/** 按月分卷的归档月 */
export interface ArchiveMonth {
month: number;
year: number;
label: string;
events: ArchiveEvent[];
}
/** 卷宗目录条目(侧栏) */
export interface ArchiveScroll {
seal: string;
name: string;
meta: string;
count: number;
}
/** 归档统计数据 */
export interface ArchiveStats {
totalMonths: number;
totalEvents: number;
firstEventTime: string;
lastEventTime: string;
}
/** 将后端 Run 对象转换为 ArchiveEvent 列表 */
export function runsToArchiveEvents(runs: Run[]): ArchiveEvent[] {
const events: ArchiveEvent[] = [];
for (const run of runs) {
const createdAt = run.created_at ?? "";
const eventType = mapRunOriginToEventType(run.origin ?? "chat");
const title =
run.goal ?? `${eventTypeToLabel(eventType)}运行 ${run.id.slice(0, 8)}`;
const statusLabel = runStatusLabel(run.status);
events.push({
id: run.id,
type: eventType,
title,
desc: `运行状态:${statusLabel}${run.goal ? ` · ${run.goal.slice(0, 60)}` : ""}`,
timeLabel: formatTimeLabel(createdAt),
tags: [eventType, run.status, run.origin ?? "chat"].filter(Boolean),
milestone: run.status === "completed" && run.goal != null,
content: buildRunContent(run),
createdAt,
source: run.origin ?? "chat",
});
}
return events;
}
/** 按月份分组归档事件 */
export function groupEventsByMonth(events: ArchiveEvent[]): ArchiveMonth[] {
const monthMap = new Map<string, ArchiveEvent[]>();
for (const evt of events) {
const date = new Date(evt.createdAt);
if (isNaN(date.getTime())) continue;
const key = `${date.getFullYear()}-${date.getMonth() + 1}`;
if (!monthMap.has(key)) monthMap.set(key, []);
monthMap.get(key)!.push(evt);
}
const monthNames = [
"一月",
"二月",
"三月",
"四月",
"五月",
"六月",
"七月",
"八月",
"九月",
"十月",
"十一月",
"十二月",
];
const seasonLabels = [
"孟春",
"仲春",
"季春",
"孟夏",
"仲夏",
"季夏",
"孟秋",
"仲秋",
"季秋",
"孟冬",
"仲冬",
"季冬",
];
return Array.from(monthMap.entries())
.sort(([a], [b]) => b.localeCompare(a)) // 倒序(最新在前)
.map(([key, evts]) => {
const [yearStr, monthStr] = key.split("-");
const year = parseInt(yearStr, 10);
const month = parseInt(monthStr, 10);
const monthName = monthNames[month - 1] ?? `${month}月`;
const season = seasonLabels[month - 1] ?? "";
return {
month,
year,
label: `${monthName} · ${season}`,
events: evts,
};
});
}
/** 从归档事件计算统计信息 */
export function computeArchiveStats(months: ArchiveMonth[]): ArchiveStats {
const allEvents = months.flatMap((m) => m.events);
const firstEvent =
months.length > 0
? allEvents.reduce((a, b) => (a.createdAt < b.createdAt ? a : b))
: null;
const lastEvent =
months.length > 0
? allEvents.reduce((a, b) => (a.createdAt > b.createdAt ? a : b))
: null;
return {
totalMonths: months.length,
totalEvents: allEvents.length,
firstEventTime: firstEvent?.createdAt ?? "",
lastEventTime: lastEvent?.createdAt ?? "",
};
}
/** 从归档月份生成卷宗目录 */
export function monthsToScrolls(months: ArchiveMonth[]): ArchiveScroll[] {
const chineseSeals = [
"零",
"壹",
"贰",
"叁",
"肆",
"伍",
"陆",
"柒",
"捌",
"玖",
"拾",
"拾壹",
"拾贰",
];
return months.map((m, i) => ({
seal: chineseSeals[Math.min(i + 1, 12)] ?? String(i + 1),
name: m.label,
meta: `${m.year}-${String(m.month).padStart(2, "0")} · ${m.events.length} 条`,
count: m.events.length,
}));
}
/* ── 内部工具函数 ── */
function mapRunOriginToEventType(origin: string): ArchiveEventType {
switch (origin) {
case "evolution":
case "big_cycle":
return "evolution";
case "reflection":
return "reflection";
case "knocking":
return "emotional";
default:
return "episodic";
}
}
function eventTypeToLabel(type: ArchiveEventType): string {
const labels: Record<ArchiveEventType, string> = {
episodic: "情景",
emotional: "情绪",
evolution: "演化",
reflection: "反思",
milestone: "里程碑",
};
return labels[type] ?? "运行";
}
function runStatusLabel(status: string): string {
const labels: Record<string, string> = {
completed: "已完成",
failed: "失败",
running: "运行中",
cancelled: "已取消",
queued: "排队中",
};
return labels[status] ?? status;
}
function formatTimeLabel(iso: string): string {
try {
const d = new Date(iso);
const month = String(d.getMonth() + 1).padStart(2, "0");
const day = String(d.getDate()).padStart(2, "0");
const hour = String(d.getHours()).padStart(2, "0");
const minute = String(d.getMinutes()).padStart(2, "0");
return `${month}-${day} · ${hour}:${minute}`;
} catch {
return iso;
}
}
function buildRunContent(run: Run): string {
const parts: string[] = [];
if (run.goal) parts.push(`目标:${run.goal}`);
if (run.model_hint) parts.push(`模型:${run.model_hint}`);
if (run.started_at && run.completed_at) {
const start = new Date(run.started_at);
const end = new Date(run.completed_at);
const duration = Math.round((end.getTime() - start.getTime()) / 1000);
parts.push(`耗时:${duration}秒`);
}
parts.push(`状态:${runStatusLabel(run.status)}`);
return parts.join("\n") || `运行记录 ${run.id.slice(0, 8)}`;
}
+38
View File
@@ -0,0 +1,38 @@
/** 认证相关类型定义。 */
export interface UserResponse {
id: string;
username: string;
email: string;
is_admin: boolean;
permissions?: string[];
created_at: string;
}
export interface LoginRequest {
username: string;
password: string;
}
export interface RegisterRequest {
username: string;
email: string;
password: string;
}
export interface LoginResponse {
access_token: string;
refresh_token: string;
token_type: string;
expires_in: number;
user: UserResponse;
}
export interface CurrentUser {
user_id: string;
username: string;
email: string;
owner_scope: string;
is_admin: boolean;
permissions?: string[];
}
+323
View File
@@ -0,0 +1,323 @@
/**
* 领域枚举定义。
*
* 所有取值严格对应 docs/contracts/contract-glossary.md(单一事实源)。
* 下游文档与代码均引用此处,禁止复制取值列表造成漂移。
*/
/** 人物生命周期状态(契约字典 §6.1) */
export type CharacterStatus =
| "wuji"
| "named"
| "seeded"
| "initialized"
| "active"
| "paused"
| "archived";
/** 归属范围(契约字典 §6.2),当前开发周期固定 local-user */
export type OwnerScope = "local-user";
/** Run 运行状态(契约字典 §7.1) */
export type RunStatus =
| "queued"
| "running"
| "waiting_confirmation"
| "completed"
| "failed"
| "cancelled";
/** 会话状态(契约字典 §7.2) */
export type ChatSessionStatus = "active" | "archived" | "deleted";
/** 消息角色(契约字典 §7.3) */
export type ChatMessageRole = "user" | "assistant" | "system" | "tool";
/** 消息模态(契约字典 §7.4),当前阶段仅支持 text */
export type ChatMessageModality = "text" | "image" | "audio" | "file";
/** 记忆类型(契约字典 §8.1) */
export type MemoryType =
| "identity"
| "user"
| "episodic"
| "semantic"
| "procedural"
| "relational"
| "emotional"
| "world"
| "reflection"
| "evolution";
/** 记忆来源(契约字典 §8.2) */
export type MemorySource =
| "user_explicit"
| "conversation"
| "material_import"
| "tool_result"
| "reflection";
/** 记忆状态(契约字典 §8.3) */
export type MemoryStatus = "active" | "archived" | "deleted" | "superseded";
/** 敏感等级(契约字典 §5.1) */
export type Sensitivity = "none" | "low" | "medium" | "high";
/** 事件可见性(契约字典 §5.2) */
export type EventVisibility = "public" | "internal" | "audit";
/** 隐私等级(契约字典 §5.4) */
export type PrivacyLevel = "normal" | "sensitive" | "local_only";
/** 风险等级(契约字典 §5.5) */
export type RiskLevel = "L0" | "L1" | "L2" | "L3" | "L4";
/** 事件来源(契约字典 §7.5) */
export type EventSource =
| "user"
| "sensor"
| "model"
| "tool"
| "memory"
| "planner"
| "system";
/** 核心运行事件类型(契约字典 §7.5) */
export type RunEventType =
| "run.started"
| "run.completed"
| "run.failed"
| "run.cancelled"
| "message.delta"
| "message.completed"
| "reasoning.delta"
| "reasoning.completed"
| "tool.started"
| "tool.completed"
| "tool.requires_confirmation"
| "plan.created"
| "plan.step.started"
| "plan.step.completed"
| "plan.step.failed"
| "safety.decision"
| "heartbeat";
/** 记忆与世界事件类型(契约字典 §7.5) */
export type MemoryEventType =
| "memory.created"
| "memory.updated"
| "memory.deleted"
| "memory.retrieved";
/** 事件类型合集 */
export type EventType = RunEventType | MemoryEventType | (string & {});
/** API 标准错误码(契约字典 §15.1) */
export type ErrorCode =
| "invalid_request"
| "validation_failed"
| "unauthorized"
| "permission_denied"
| "requires_confirmation"
| "not_found"
| "conflict"
| "payload_too_large"
| "unsupported_media_type"
| "context_overflow"
| "rate_limited"
| "model_error"
| "tool_error"
| "safety_rejected"
| "internal_error"
| "not_implemented";
/** 九枢模块标识(契约字典 §5.9),取值与九象工程映射一致 */
export type Pivot =
| "personality_core"
| "goal_orchestrator"
| "safety_governor"
| "perception"
| "world_model"
| "planner"
| "memory"
| "tool_runtime"
| "agent_society";
/** 九枢健康状态(契约字典 §5.10),与前端铜镜 MirrorState 一一对应 */
export type PivotHealth = "void" | "breathing" | "steady" | "cracked";
/** 审计裁定结果(契约字典 §13.3) */
export type AuditDecision = "auto" | "approved" | "denied" | "blocked";
/** 授权状态(契约字典 §5.7),烛照枢感知授权 */
export type ConsentStatus = "unknown" | "granted" | "restricted" | "revoked";
/** 目标层级(契约字典 §5.11),太一枢 */
export type GoalLevel = "highest" | "long_term" | "session" | "task" | "action";
/** 目标类型(契约字典 §5.15),太一枢 */
export type GoalType =
| "mission"
| "relationship"
| "skill"
| "knowledge"
| "maintenance"
| "exploration";
/** 目标状态(契约字典 §5.12),太一枢 */
export type GoalStatus =
| "pending"
| "active"
| "completed"
| "blocked"
| "cancelled";
/** 计划状态(契约字典 §5.13),洛书枢 */
export type PlanStatus =
| "draft"
| "approved"
| "running"
| "completed"
| "failed";
/** 天工阁角色(契约字典 §5.14),天工阁枢九角色 */
export type AgentRole =
| "historian"
| "diviner"
| "engineer"
| "debater"
| "medic"
| "herald"
| "charioteer"
| "scholar"
| "mirror";
/** 世界实体类型(契约字典 §11.1),河图枢 */
export type WorldEntityType =
| "self"
| "person"
| "object"
| "place"
| "device"
| "project"
| "task"
| "concept";
/** 世界状态类型(契约字典 §11.2),河图枢区分事实与推断 */
export type WorldStateType =
| "fact"
| "observation"
| "inference"
| "hypothesis"
| "stale";
/** 烛照感知通道(九象与九枢 §7) */
export type PerceptionChannelType =
| "vision"
| "audio"
| "sensor"
| "digital"
| "user_input"
| "external_api";
/** 主题 */
export type ThemeMode = "light" | "dark" | "system";
// —— 模型配置(契约字典 §16)——
// 前端只见逻辑模型 / provider / 能力 / 脱敏状态,真实 model、base URL、API Key 由后端持有。
/** 模型供应商(契约字典 §16.1) */
export type ModelProvider =
| "openai"
| "deepseek"
| "anthropic"
| "google"
| "minimax"
| "zhipu"
| "tencentcloud"
| "volcengine"
| "bailian";
/** 路由策略(契约字典 §16.2) */
export type RoutingStrategy =
| "single"
| "priority_failover"
| "round_robin"
| "weighted_random"
| "sticky_weighted_random";
/** endpoint 状态(契约字典 §16.3),前端只见脱敏状态,不见 URL / 密钥 */
export type EndpointStatus = "active" | "inactive" | "unhealthy" | "cooldown";
/** 模型能力(契约字典 §16.4) */
export type ModelCapability =
| "chat"
| "tool_use"
| "structured_output"
| "reasoning"
| "long_context"
| "vision";
// —— 资料导入流水线(契约字典 §10)——
/** 资料类型(契约字典 §10.1) */
export type MaterialType =
| "chat_history"
| "character_profile"
| "background_story"
| "role_card"
| "world_setting"
| "style_sample"
| "voice_sample"
| "diary"
| "other";
/** 导入来源类型(契约字典 §10.2) */
export type ImportSourceType =
| "uploaded_file"
| "pasted_text"
| "external_export"
| "manual_profile"
| "media_upload";
/** 导入任务状态(契约字典 §10.3),长状态机 */
export type ImportStatus =
| "pending"
| "uploaded"
| "parsing"
| "parsed"
| "safety_scanning"
| "safety_blocked"
| "extracting_profile"
| "extracting_memory"
| "generating_personality_proposals"
| "reviewing"
| "partially_applied"
| "completed"
| "failed"
| "cancelled"
| "deleted";
/** 导入条目类型(契约字典 §10.4) */
export type ImportItemType =
| "message"
| "profile_field"
| "paragraph"
| "world_fact"
| "style_sample"
| "audio_segment"
| "transcript_segment";
/** 导入条目角色(契约字典 §10.5) */
export type ImportItemRole = "user" | "assistant" | "system" | "other";
/** 候选审核状态(契约字典 §10.6),适用于档案/记忆/人格候选 */
export type CandidateStatus =
| "pending"
| "approved"
| "rejected"
| "merged"
| "applied";
/** 世界实体审核状态(契约字典 §11.3) */
export type WorldEntityStatus = "pending" | "confirmed" | "rejected";
+2
View File
@@ -0,0 +1,2 @@
export * from "./domain";
export * from "./api";
+50
View File
@@ -0,0 +1,50 @@
/**
* 计划领域类型(洛书枢 / 规划器)。
*
* ⚠️ 前瞻原型:字段取自 docs/domain/core-domains.md §5,后端计划 API 尚未落地
* (见 docs/operations/capability-matrix.md,自动任务规划属后续阶段)。此处仅用于
* 前端 Mock 验证 UI;待后端接口稳定后,迁移至 types/api.ts 并对齐契约字典,
* 此文件随即移除。
*/
import type { RiskLevel } from "./domain";
/** 计划状态(planner-design.md §5) */
export type PlanStatus =
| "draft"
| "approved"
| "running"
| "completed"
| "failed";
/** 计划步骤状态(planner-design.md §5) */
export type PlanStepStatus =
| "pending"
| "running"
| "waiting_confirmation"
| "completed"
| "failed"
| "skipped";
/** 计划步骤 */
export interface PlanStep {
id: string;
title: string;
description: string;
tool?: string;
status: PlanStepStatus;
risk_level: RiskLevel;
result_summary?: string;
}
/** 计划 */
export interface Plan {
id: string;
goal_id: string;
steps: PlanStep[];
assumptions: string[];
risks: string[];
required_tools: string[];
success_criteria: string[];
status: PlanStatus;
}
+8
View File
@@ -0,0 +1,8 @@
/**
* 思考模式类型(前瞻原型)。
*
* 对齐 docs/architecture/service-boundaries.md §11.4 的 reasoning_effort。
* 完整取值为 low/medium/high/xhigh/max;当前前端交互仅暴露 low/medium/high 三档,
* 待后端模型网关契约稳定后迁移至 types/api.ts 并对齐契约字典。
*/
export type ThinkingEffort = "low" | "medium" | "high";