fmode-api.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {
  2. Agent,
  3. AuthSession,
  4. Deliverable,
  5. DeliverableGroup,
  6. MatrixProvision,
  7. Me,
  8. Task,
  9. UploadTicket,
  10. } from './models';
  11. /**
  12. * 数据访问抽象接口 —— 应用层与数据源之间的**唯一闸门**
  13. *
  14. * 依据《数据访问层设计.md》§一/§四。硬约束:
  15. * ① 页面/components **禁止** inject(FmodeApi) 或其实现(FR-14 AC-14.2)
  16. * ② 业务服务**禁止**直接 fetch / 直接用 fmode-ng(黄金规则 5)
  17. * ③ 每个数据域**只有一个** owner 服务
  18. *
  19. * 实现:`ParseApi`(真实,走 fmode-ng)/ `MockApi`(演示数据)。
  20. * 切换由 `environment.useMockData` 单开关控制(api.provider.ts)。
  21. *
  22. * ⚠️ `Project` / `EventItem` **不在此接口**:它们是派生投影(由 Agent + Deliverable 组合),
  23. * 由对应服务计算,见《数据访问层设计.md》§四.1。
  24. */
  25. export abstract class FmodeApi {
  26. // ---------- 鉴权 ----------
  27. /** 发送手机验证码(REST R4:`code === 1` 才算成功) */
  28. abstract sendMobileCode(mobile: string): Promise<void>;
  29. /** 验证码登录(REST R5:`code === 200 && data.token` 才算成功) */
  30. abstract loginWithMobile(mobile: string, code: string): Promise<AuthSession>;
  31. /** Token 直登(REST R1:`POST /parse/users/me`) */
  32. abstract loginWithToken(token: string): Promise<AuthSession>;
  33. /** 用已有 token 取回身份 */
  34. abstract fetchMe(token: string): Promise<Me>;
  35. // ---------- 数字生命(实况) ----------
  36. /** 列表查询(云函数 xlosi3m46q,`op:'query'`) */
  37. abstract fetchAgents(): Promise<Agent[]>;
  38. /** 单条查询;`code` 404/403 时返回 null */
  39. abstract fetchAgentStatus(agentId: string): Promise<Agent | null>;
  40. // ---------- 会话(Matrix) ----------
  41. /** 开通 Matrix 身份(云函数 RP5Ht55NeX);绑定表命中时 `cached: true` */
  42. abstract provisionMatrix(agentId: string): Promise<MatrixProvision>;
  43. /** 校验/刷新凭据(`validate: 1`) */
  44. abstract validateMatrix(agentId: string): Promise<MatrixProvision>;
  45. // ---------- 交付成果 ----------
  46. /** 列表(云函数 lfYlgU7SkK,`action:'list'`) */
  47. abstract fetchDeliverables(opts?: { agentId?: string; limit?: number }): Promise<Deliverable[]>;
  48. /** 按项目分组(`action:'byProject'`) */
  49. abstract fetchDeliverablesByProject(limit?: number): Promise<DeliverableGroup[]>;
  50. // ---------- 任务看板(FR-07b) ----------
  51. /**
  52. * 任务列表(按 agentId 过滤)。
  53. * 🔴 云函数接收端**尚未实现**:就绪前实现方须返回**空数组**,**禁止伪造数据**
  54. * (SPEC FR-07b「依赖声明」)。
  55. */
  56. abstract fetchTasks(agentId: string): Promise<Task[]>;
  57. /** 任务详情(含 runs / comments / attachments) */
  58. abstract fetchTaskDetail(taskId: string): Promise<Task | null>;
  59. // ---------- 上传 ----------
  60. /** 取预签名(云函数 AlP56LCKFm);缺 uploadUrl 即抛错,不得静默降级 */
  61. abstract requestUploadUrl(filename: string, mimeType: string, size: number): Promise<UploadTicket>;
  62. /** 预签名直传(前端不经手任何 OBS 密钥) */
  63. abstract uploadFile(
  64. file: File,
  65. onProgress?: (pct: number) => void,
  66. ): Promise<{ key: string; publicUrl: string }>;
  67. }