windowHostControllerProjection.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. /* eslint-disable max-lines -- 投影状态、V4 帧与离线替换属于同一个一致性边界。 */
  2. import { isDeepStrictEqual } from "node:util";
  3. import type { ZCodeTaskMeta } from "@zcode/shared";
  4. import type { ZCodeArchivedTaskDeletionResult } from "@zcode/services";
  5. import {
  6. CONTROLLER_TASKS_INDEX_TOPIC,
  7. CONTROLLER_WORKSPACES_TOPIC,
  8. type ControllerSubscribeResult,
  9. type WindowHostControllerTaskDelta,
  10. type WindowHostControllerTaskFrame,
  11. type WindowHostControllerTaskRow,
  12. type WindowHostControllerTopic,
  13. type WindowHostControllerWorkspaceDelta,
  14. type WindowHostControllerWorkspaceFact,
  15. type WindowHostControllerWorkspaceFrame,
  16. type WindowHostTaskAddress,
  17. } from "@zcode/shared/zcode-protocol-v4";
  18. export type WindowHostControllerSourceScope =
  19. | {
  20. kind: "local";
  21. workspacePath: string;
  22. workspaceIdentity?: string;
  23. }
  24. | {
  25. kind: "remote";
  26. sourceServerId?: string;
  27. serverDisplayName?: string;
  28. remoteSessionId?: string;
  29. workspacePath: string;
  30. workspaceIdentity: string;
  31. };
  32. export interface WindowHostControllerTaskMembership {
  33. meta: ZCodeTaskMeta;
  34. membership: {
  35. pinned: boolean;
  36. archived: boolean;
  37. active: boolean;
  38. };
  39. searchSnippets?: string[];
  40. }
  41. export interface WindowHostControllerSessionOverlay {
  42. taskId: string;
  43. liveStatus: WindowHostControllerTaskRow["liveStatus"];
  44. title?: string;
  45. titleSource?: "default" | "generated" | "custom";
  46. updatedAt?: number;
  47. pendingInteraction?: ZCodeTaskMeta["pendingInteraction"];
  48. activity?: NonNullable<WindowHostControllerTaskRow["activity"]>;
  49. }
  50. export type WindowHostControllerMutation =
  51. | { kind: "rename"; title: string }
  52. | { kind: "pin"; pinned: boolean }
  53. | { kind: "archive"; archived: boolean }
  54. | { kind: "delete" }
  55. | { kind: "delete-archived" }
  56. | { kind: "delete-archived-batch"; taskIds: string[] }
  57. | { kind: "mark-read"; expectedUnreadAt?: number }
  58. | { kind: "mark-unread" }
  59. | { kind: "open" }
  60. | { kind: "resume" };
  61. export type WindowHostControllerMutationResult =
  62. | void
  63. | boolean
  64. | ZCodeArchivedTaskDeletionResult
  65. | ZCodeTaskMeta;
  66. interface ControllerSource {
  67. scope: WindowHostControllerSourceScope;
  68. sourceAvailability: "online" | "offline";
  69. connectionState: WindowHostControllerWorkspaceFact["connectionState"];
  70. memberships: Map<string, WindowHostControllerTaskMembership>;
  71. overlays: Map<string, WindowHostControllerSessionOverlay>;
  72. rows: Map<string, WindowHostControllerTaskRow>;
  73. mutate: (
  74. address: WindowHostTaskAddress,
  75. mutation: WindowHostControllerMutation,
  76. ) => Promise<WindowHostControllerMutationResult> | WindowHostControllerMutationResult;
  77. }
  78. interface ControllerSubscriber {
  79. topic: WindowHostControllerTopic;
  80. subscriptionId: string;
  81. onFrame: (frame: WindowHostControllerTaskFrame | WindowHostControllerWorkspaceFrame) => void;
  82. }
  83. interface TopicState {
  84. logEpoch: string;
  85. seq: number;
  86. }
  87. function sourceKey(scope: WindowHostControllerSourceScope): string {
  88. const workspaceKey = scope.workspaceIdentity?.trim() || scope.workspacePath;
  89. return scope.kind === "remote"
  90. ? `remote\0${scope.sourceServerId ?? scope.remoteSessionId}\0${workspaceKey}`
  91. : `local\0${workspaceKey}`;
  92. }
  93. function addressFor(scope: WindowHostControllerSourceScope, taskId: string): WindowHostTaskAddress {
  94. return {
  95. ...(scope.kind === "remote"
  96. ? {
  97. ...(scope.sourceServerId ? { sourceServerId: scope.sourceServerId } : {}),
  98. remoteSessionId: scope.remoteSessionId,
  99. }
  100. : {}),
  101. workspacePath: scope.workspacePath,
  102. ...(scope.workspaceIdentity ? { workspaceIdentity: scope.workspaceIdentity } : {}),
  103. taskId,
  104. };
  105. }
  106. function taskKey(address: WindowHostTaskAddress): string {
  107. return `${address.sourceServerId ?? address.remoteSessionId ?? "local"}\0${address.workspaceIdentity?.trim() || address.workspacePath}\0${address.taskId}`;
  108. }
  109. function defaultLiveStatus(meta: ZCodeTaskMeta): WindowHostControllerTaskRow["liveStatus"] {
  110. // live overlay 缺失表示当前没有可证明的 runtime;SQLite 里的 running/interaction
  111. // 可能来自上次进程退出,不能重新解释成当前运行或等待事实。
  112. switch (meta.status) {
  113. case "completed":
  114. return "completed";
  115. case "error":
  116. return "error";
  117. default:
  118. return "idle";
  119. }
  120. }
  121. function statusFromActivity(
  122. activity: NonNullable<WindowHostControllerSessionOverlay["activity"]>,
  123. ): ZCodeTaskMeta["status"] {
  124. switch (activity.phase) {
  125. case "prewarming":
  126. case "running":
  127. return "running";
  128. case "completedSuccess":
  129. case "completedInterrupted":
  130. return "completed";
  131. case "error":
  132. return "error";
  133. case "draft":
  134. return undefined;
  135. }
  136. }
  137. function buildSourceRows(source: ControllerSource): Map<string, WindowHostControllerTaskRow> {
  138. const rows = new Map<string, WindowHostControllerTaskRow>();
  139. for (const membership of source.memberships.values()) {
  140. const overlay = source.overlays.get(membership.meta.taskId);
  141. const shouldUseOverlayTitle =
  142. overlay?.title != null &&
  143. (membership.meta.titleOverridden !== true || overlay.titleSource === "custom");
  144. const meta = overlay
  145. ? {
  146. ...membership.meta,
  147. ...(shouldUseOverlayTitle ? { title: overlay.title } : {}),
  148. ...(overlay.titleSource === "custom" ? { titleOverridden: true } : {}),
  149. ...(overlay.updatedAt != null ? { updatedAt: overlay.updatedAt } : {}),
  150. ...(overlay.activity ? { status: statusFromActivity(overlay.activity) } : {}),
  151. pendingInteraction: overlay.pendingInteraction,
  152. }
  153. : membership.meta;
  154. const address = addressFor(source.scope, meta.taskId);
  155. rows.set(taskKey(address), {
  156. address,
  157. meta,
  158. membership: membership.membership,
  159. sourceAvailability: source.sourceAvailability,
  160. liveStatus: overlay?.liveStatus ?? defaultLiveStatus(meta),
  161. ...(overlay?.activity ? { activity: overlay.activity } : {}),
  162. ...(membership.searchSnippets ? { searchSnippets: membership.searchSnippets } : {}),
  163. });
  164. }
  165. return rows;
  166. }
  167. function validateMembershipScope(
  168. scope: WindowHostControllerSourceScope,
  169. membership: WindowHostControllerTaskMembership,
  170. ): void {
  171. if (
  172. membership.meta.workspacePath !== scope.workspacePath ||
  173. membership.meta.workspaceIdentity !== scope.workspaceIdentity
  174. ) {
  175. throw new Error(
  176. `task-index membership 与 source scope 不匹配,taskId=${membership.meta.taskId}`,
  177. );
  178. }
  179. }
  180. function workspaceFact(source: ControllerSource): WindowHostControllerWorkspaceFact {
  181. return {
  182. ...(source.scope.kind === "remote"
  183. ? {
  184. ...(source.scope.sourceServerId ? { sourceServerId: source.scope.sourceServerId } : {}),
  185. ...(source.scope.serverDisplayName
  186. ? { serverDisplayName: source.scope.serverDisplayName }
  187. : {}),
  188. remoteSessionId: source.scope.remoteSessionId,
  189. }
  190. : {}),
  191. workspacePath: source.scope.workspacePath,
  192. ...(source.scope.workspaceIdentity
  193. ? { workspaceIdentity: source.scope.workspaceIdentity }
  194. : {}),
  195. sourceAvailability: source.sourceAvailability,
  196. connectionState: source.connectionState,
  197. };
  198. }
  199. export function createWindowHostControllerProjection(options: { createId: () => string }) {
  200. const sources = new Map<string, ControllerSource>();
  201. const subscribers = new Map<string, ControllerSubscriber>();
  202. const topicStates: Record<WindowHostControllerTopic, TopicState> = {
  203. [CONTROLLER_TASKS_INDEX_TOPIC]: { logEpoch: options.createId(), seq: 0 },
  204. [CONTROLLER_WORKSPACES_TOPIC]: { logEpoch: options.createId(), seq: 0 },
  205. };
  206. function allRows(): WindowHostControllerTaskRow[] {
  207. return Array.from(sources.values())
  208. .flatMap((source) => Array.from(source.rows.values()))
  209. .sort(
  210. (left, right) =>
  211. right.meta.updatedAt - left.meta.updatedAt ||
  212. taskKey(left.address).localeCompare(taskKey(right.address)),
  213. );
  214. }
  215. function allWorkspaceFacts(): WindowHostControllerWorkspaceFact[] {
  216. return Array.from(sources.values(), workspaceFact).sort((left, right) => {
  217. const leftKey = `${left.sourceServerId ?? left.remoteSessionId ?? "local"}\0${left.workspaceIdentity ?? left.workspacePath}`;
  218. const rightKey = `${right.sourceServerId ?? right.remoteSessionId ?? "local"}\0${right.workspaceIdentity ?? right.workspacePath}`;
  219. return leftKey.localeCompare(rightKey);
  220. });
  221. }
  222. function snapshotFrame(
  223. subscriber: ControllerSubscriber,
  224. ): WindowHostControllerTaskFrame | WindowHostControllerWorkspaceFrame {
  225. const state = topicStates[subscriber.topic];
  226. const common = {
  227. subscriptionId: subscriber.subscriptionId,
  228. logEpoch: state.logEpoch,
  229. fromSeq: 0,
  230. toSeq: state.seq,
  231. sentAt: Date.now(),
  232. };
  233. if (subscriber.topic === CONTROLLER_TASKS_INDEX_TOPIC) {
  234. return {
  235. ...common,
  236. topic: CONTROLLER_TASKS_INDEX_TOPIC,
  237. payload: {
  238. kind: "snapshot",
  239. snapshot: {
  240. protocolVersion: 1,
  241. logEpoch: state.logEpoch,
  242. tasks: allRows(),
  243. },
  244. },
  245. };
  246. }
  247. return {
  248. ...common,
  249. topic: CONTROLLER_WORKSPACES_TOPIC,
  250. payload: {
  251. kind: "snapshot",
  252. snapshot: {
  253. protocolVersion: 1,
  254. logEpoch: state.logEpoch,
  255. workspaces: allWorkspaceFacts(),
  256. },
  257. },
  258. };
  259. }
  260. function publishTaskDeltas(deltas: WindowHostControllerTaskDelta[]): void {
  261. if (deltas.length === 0) {
  262. return;
  263. }
  264. const state = topicStates[CONTROLLER_TASKS_INDEX_TOPIC];
  265. const fromSeq = state.seq;
  266. state.seq += 1;
  267. for (const subscriber of subscribers.values()) {
  268. if (subscriber.topic !== CONTROLLER_TASKS_INDEX_TOPIC) {
  269. continue;
  270. }
  271. subscriber.onFrame({
  272. topic: CONTROLLER_TASKS_INDEX_TOPIC,
  273. subscriptionId: subscriber.subscriptionId,
  274. logEpoch: state.logEpoch,
  275. fromSeq,
  276. toSeq: state.seq,
  277. sentAt: Date.now(),
  278. payload: { kind: "deltas", deltas },
  279. });
  280. }
  281. }
  282. function publishWorkspaceDeltas(deltas: WindowHostControllerWorkspaceDelta[]): void {
  283. if (deltas.length === 0) {
  284. return;
  285. }
  286. const state = topicStates[CONTROLLER_WORKSPACES_TOPIC];
  287. const fromSeq = state.seq;
  288. state.seq += 1;
  289. for (const subscriber of subscribers.values()) {
  290. if (subscriber.topic !== CONTROLLER_WORKSPACES_TOPIC) {
  291. continue;
  292. }
  293. subscriber.onFrame({
  294. topic: CONTROLLER_WORKSPACES_TOPIC,
  295. subscriptionId: subscriber.subscriptionId,
  296. logEpoch: state.logEpoch,
  297. fromSeq,
  298. toSeq: state.seq,
  299. sentAt: Date.now(),
  300. payload: { kind: "deltas", deltas },
  301. });
  302. }
  303. }
  304. function requireSource(scope: WindowHostControllerSourceScope): ControllerSource {
  305. const source = sources.get(sourceKey(scope));
  306. if (!source) {
  307. throw new Error(
  308. `没有与 scope 匹配的 Controller source,workspacePath=${scope.workspacePath}`,
  309. );
  310. }
  311. return source;
  312. }
  313. return {
  314. registerSource(params: {
  315. scope: WindowHostControllerSourceScope;
  316. mutate: ControllerSource["mutate"];
  317. }): void {
  318. if (params.scope.kind === "remote" && !params.scope.workspaceIdentity.trim()) {
  319. throw new Error("远程 Controller source 必须携带 workspaceIdentity");
  320. }
  321. if (
  322. params.scope.kind === "remote" &&
  323. !params.scope.sourceServerId &&
  324. !params.scope.remoteSessionId
  325. )
  326. throw new Error("远程 Controller source 必须携带 Source 身份或 attachment");
  327. const key = sourceKey(params.scope);
  328. const existing = sources.get(key);
  329. if (existing) {
  330. existing.mutate = params.mutate;
  331. return;
  332. }
  333. sources.set(key, {
  334. scope: params.scope,
  335. sourceAvailability: "offline",
  336. connectionState: "connecting",
  337. memberships: new Map(),
  338. overlays: new Map(),
  339. rows: new Map(),
  340. mutate: params.mutate,
  341. });
  342. },
  343. replaceSourceSnapshot(params: {
  344. scope: WindowHostControllerSourceScope;
  345. taskIndex: WindowHostControllerTaskMembership[];
  346. sessionsIndex: WindowHostControllerSessionOverlay[];
  347. replacesScope?: WindowHostControllerSourceScope;
  348. }): void {
  349. const source = requireSource(params.scope);
  350. const previousWorkspaceFact = workspaceFact(source);
  351. const currentSourceKey = sourceKey(params.scope);
  352. const replacementCandidate = params.replacesScope
  353. ? sources.get(sourceKey(params.replacesScope))
  354. : undefined;
  355. const replacedSource =
  356. replacementCandidate && sourceKey(replacementCandidate.scope) !== currentSourceKey
  357. ? replacementCandidate
  358. : undefined;
  359. if (replacedSource) {
  360. // 重连的 remoteSessionId 会变化;先在内存里摘掉旧 source,再用一个 task delta frame
  361. // 同时发布 old removals + new upserts,消费者不会看到中间空投影。
  362. sources.delete(sourceKey(replacedSource.scope));
  363. }
  364. const previousRows = source.rows;
  365. const nextMemberships = new Map<string, WindowHostControllerTaskMembership>();
  366. for (const membership of params.taskIndex) {
  367. validateMembershipScope(params.scope, membership);
  368. const address = addressFor(params.scope, membership.meta.taskId);
  369. nextMemberships.set(taskKey(address), membership);
  370. }
  371. source.memberships = nextMemberships;
  372. source.overlays = new Map(params.sessionsIndex.map((overlay) => [overlay.taskId, overlay]));
  373. source.sourceAvailability = "online";
  374. const nextRows = buildSourceRows(source);
  375. source.rows = nextRows;
  376. source.connectionState = "online";
  377. const deltas: WindowHostControllerTaskDelta[] = [];
  378. for (const previous of replacedSource?.rows.values() ?? []) {
  379. deltas.push({ op: "task.removed", address: previous.address });
  380. }
  381. for (const [key, previous] of previousRows) {
  382. if (!nextRows.has(key)) {
  383. deltas.push({ op: "task.removed", address: previous.address });
  384. }
  385. }
  386. for (const task of nextRows.values()) {
  387. const previous = previousRows.get(taskKey(task.address));
  388. if (!previous || !isDeepStrictEqual(previous, task)) {
  389. deltas.push({ op: "task.upserted", task });
  390. }
  391. }
  392. publishTaskDeltas(deltas);
  393. const nextWorkspaceFact = workspaceFact(source);
  394. const workspaceDeltas: WindowHostControllerWorkspaceDelta[] = [
  395. ...(replacedSource
  396. ? [
  397. {
  398. op: "workspace.removed" as const,
  399. ...(replacedSource.scope.kind === "remote"
  400. ? {
  401. ...(replacedSource.scope.sourceServerId
  402. ? { sourceServerId: replacedSource.scope.sourceServerId }
  403. : {}),
  404. remoteSessionId: replacedSource.scope.remoteSessionId,
  405. }
  406. : {}),
  407. workspacePath: replacedSource.scope.workspacePath,
  408. ...(replacedSource.scope.workspaceIdentity
  409. ? { workspaceIdentity: replacedSource.scope.workspaceIdentity }
  410. : {}),
  411. },
  412. ]
  413. : []),
  414. ...(!isDeepStrictEqual(previousWorkspaceFact, nextWorkspaceFact) || replacedSource
  415. ? [{ op: "workspace.upserted" as const, workspace: nextWorkspaceFact }]
  416. : []),
  417. ];
  418. publishWorkspaceDeltas(workspaceDeltas);
  419. },
  420. replaceSourceSessionOverlays(
  421. scope: WindowHostControllerSourceScope,
  422. sessionsIndex: WindowHostControllerSessionOverlay[],
  423. ): void {
  424. const source = requireSource(scope);
  425. const previousRows = source.rows;
  426. source.overlays = new Map(sessionsIndex.map((overlay) => [overlay.taskId, overlay]));
  427. source.rows = buildSourceRows(source);
  428. const deltas: WindowHostControllerTaskDelta[] = [];
  429. for (const task of source.rows.values()) {
  430. const previous = previousRows.get(taskKey(task.address));
  431. if (!previous || !isDeepStrictEqual(previous, task)) {
  432. deltas.push({ op: "task.upserted", task });
  433. }
  434. }
  435. publishTaskDeltas(deltas);
  436. },
  437. disconnectSource(scope: WindowHostControllerSourceScope): void {
  438. const source = requireSource(scope);
  439. source.sourceAvailability = "offline";
  440. source.connectionState = "disconnected";
  441. const deltas: WindowHostControllerTaskDelta[] = [];
  442. for (const [key, row] of source.rows) {
  443. const offlineRow = { ...row, sourceAvailability: "offline" as const };
  444. source.rows.set(key, offlineRow);
  445. deltas.push({ op: "task.upserted", task: offlineRow });
  446. }
  447. publishTaskDeltas(deltas);
  448. publishWorkspaceDeltas([{ op: "workspace.upserted", workspace: workspaceFact(source) }]);
  449. },
  450. removeSource(scope: WindowHostControllerSourceScope): void {
  451. const key = sourceKey(scope);
  452. const source = sources.get(key);
  453. if (!source) {
  454. return;
  455. }
  456. sources.delete(key);
  457. publishTaskDeltas(
  458. Array.from(source.rows.values(), (task) => ({
  459. op: "task.removed" as const,
  460. address: task.address,
  461. })),
  462. );
  463. publishWorkspaceDeltas([
  464. {
  465. op: "workspace.removed",
  466. ...(scope.kind === "remote"
  467. ? {
  468. ...(scope.sourceServerId ? { sourceServerId: scope.sourceServerId } : {}),
  469. remoteSessionId: scope.remoteSessionId,
  470. }
  471. : {}),
  472. workspacePath: scope.workspacePath,
  473. ...(scope.workspaceIdentity ? { workspaceIdentity: scope.workspaceIdentity } : {}),
  474. },
  475. ]);
  476. },
  477. discardSource(scope: WindowHostControllerSourceScope): void {
  478. // provisional source 尚未发布过 snapshot;CAS 失效时只应撤销内部注册,不能向订阅者
  479. // 伪造一次 workspace.removed,也不能触碰仍在展示的上一代离线 source。
  480. sources.delete(sourceKey(scope));
  481. },
  482. getTasks: allRows,
  483. async mutate(
  484. address: WindowHostTaskAddress,
  485. mutation: WindowHostControllerMutation,
  486. ): Promise<WindowHostControllerMutationResult> {
  487. const source = Array.from(sources.values()).find((candidate) => {
  488. if (candidate.scope.workspacePath !== address.workspacePath) {
  489. return false;
  490. }
  491. if (candidate.scope.workspaceIdentity !== address.workspaceIdentity) {
  492. return false;
  493. }
  494. if (candidate.scope.kind === "remote") {
  495. return address.sourceServerId
  496. ? candidate.scope.sourceServerId === address.sourceServerId
  497. : candidate.scope.remoteSessionId === address.remoteSessionId;
  498. }
  499. return address.remoteSessionId == null;
  500. });
  501. if (
  502. !source ||
  503. (mutation.kind !== "delete-archived" &&
  504. mutation.kind !== "delete-archived-batch" &&
  505. !source.rows.has(taskKey(address)))
  506. ) {
  507. throw new Error("没有与任务地址匹配的 source");
  508. }
  509. if (source.sourceAvailability !== "online") {
  510. if (source.scope.kind === "remote") {
  511. throw new Error("远程 source 当前离线,禁止列表写操作");
  512. }
  513. throw new Error("本地 source 当前不可用");
  514. }
  515. return source.mutate(address, mutation);
  516. },
  517. subscribe(params: {
  518. topic: WindowHostControllerTopic;
  519. onFrame: ControllerSubscriber["onFrame"];
  520. }): ControllerSubscribeResult["ack"] & {
  521. ack: ControllerSubscribeResult["ack"];
  522. dispose(): void;
  523. } {
  524. const subscriptionId = options.createId();
  525. const subscriber: ControllerSubscriber = {
  526. topic: params.topic,
  527. subscriptionId,
  528. onFrame: params.onFrame,
  529. };
  530. subscribers.set(subscriptionId, subscriber);
  531. const state = topicStates[params.topic];
  532. const ack: ControllerSubscribeResult["ack"] = {
  533. subscriptionId,
  534. mode: "snapshot",
  535. logEpoch: state.logEpoch,
  536. };
  537. params.onFrame(snapshotFrame(subscriber));
  538. return {
  539. ...ack,
  540. ack,
  541. dispose() {
  542. subscribers.delete(subscriptionId);
  543. },
  544. };
  545. },
  546. resync(subscriptionId: string): ControllerSubscribeResult["ack"] {
  547. const subscriber = subscribers.get(subscriptionId);
  548. if (!subscriber) {
  549. throw new Error(`未找到 Controller subscription,subscriptionId=${subscriptionId}`);
  550. }
  551. paramsOnFrameSafe(subscriber, snapshotFrame(subscriber));
  552. const state = topicStates[subscriber.topic];
  553. return { subscriptionId, mode: "snapshot", logEpoch: state.logEpoch };
  554. },
  555. };
  556. }
  557. function paramsOnFrameSafe(
  558. subscriber: ControllerSubscriber,
  559. frame: WindowHostControllerTaskFrame | WindowHostControllerWorkspaceFrame,
  560. ): void {
  561. subscriber.onFrame(frame);
  562. }