profiles.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Delivery profile 过滤纯函数。
  2. // 通道层 flush 管线的第一步:filter → coalesce → 打帧。恢复回放走同一函数
  3. // (「先过该订阅者的 profile 过滤器再 coalesce」),保证断线重连的确定性重投递。
  4. //
  5. // 收口不变量(进黄金测试):被 profile 过滤的事件必须最终被某个不可过滤的事件收口——
  6. // row.delta(inputText) 被滤掉后,工具输入定稿时的 row.upserted 必须携带完整 inputText,
  7. // 否则 replayable 订阅者终态缺数据。任何 reducer 改动破坏该不变量会撞
  8. // 「两 profile 终态逐字节一致」测试。
  9. import type { DeliveryProfile } from "./core.js";
  10. import type { ConversationDelta } from "./delta.js";
  11. import type { ConversationRow } from "./rows.js";
  12. export function filterConversationRowsForProfile(
  13. rows: readonly ConversationRow[],
  14. _profile: DeliveryProfile,
  15. ): ConversationRow[] {
  16. // HookInvocationRow 已收敛为 desktop/mobile 共用的 client-safe summary;当前没有
  17. // profile-specific 完整行,仍保留纯函数边界供未来受控 row 使用。
  18. return [...rows];
  19. }
  20. /**
  21. * 按 profile 的 streamPaths 开关过滤 delta 序列。
  22. * row.delta 按流式能力过滤;结构性完整行在两个 profile 中保持同一产品事实。
  23. * 纯函数,不修改入参;输出保持权威日志序。
  24. */
  25. export function filterConversationDeltasForProfile(
  26. deltas: readonly ConversationDelta[],
  27. profile: DeliveryProfile,
  28. ): ConversationDelta[] {
  29. return deltas.filter((delta) => {
  30. if (delta.op === "row.delta") return profile.streamPaths[delta.path];
  31. return true;
  32. });
  33. }