Skip to content

Commit 803dc23

Browse files
refactor(client-runtime): share the thread catch-up check
Web will need the same check once it keeps sent messages beyond a view. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0721c8f commit 803dc23

5 files changed

Lines changed: 26 additions & 24 deletions

File tree

‎apps/mobile/src/features/threads/pending-thread-feed.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import {
55
} from "@t3tools/contracts";
66
import type { ThreadFeedEntry } from "../../lib/threadActivity";
77
import { scopedThreadKey } from "../../lib/scopedEntities";
8-
import {
9-
threadHasCaughtUpTo,
10-
type AcknowledgedThreadMessage,
11-
type QueuedThreadMessage,
8+
import { threadHasCaughtUpTo } from "@t3tools/client-runtime/state/thread-state";
9+
import type {
10+
AcknowledgedThreadMessage,
11+
QueuedThreadMessage,
1212
} from "../../state/thread-outbox-model";
1313

1414
/**

‎apps/mobile/src/state/acknowledged-thread-messages.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import * as Option from "effect/Option";
22
import { Atom } from "effect/reactivity";
33
import { appAtomRegistry } from "./atom-registry";
4-
import {
5-
threadHasCaughtUpTo,
6-
type AcknowledgedThreadMessage,
7-
type QueuedThreadMessage,
8-
} from "./thread-outbox-model";
4+
import { threadHasCaughtUpTo } from "@t3tools/client-runtime/state/thread-state";
5+
import type { AcknowledgedThreadMessage, QueuedThreadMessage } from "./thread-outbox-model";
96
import { environmentThreadDetails } from "./threads";
107

118
// Keep acknowledged rows until the thread catches up; command receipts can precede messages.

‎apps/mobile/src/state/thread-outbox-model.ts‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -292,18 +292,3 @@ export type AcknowledgedThreadMessage = QueuedThreadMessage & {
292292
/** The server sequence that committed the message; older servers do not report it. */
293293
readonly sequence?: number;
294294
};
295-
296-
/**
297-
* The thread holds the message once it has applied the message's sequence. A bounded
298-
* projection can page the message out later, so finding it is only a fallback.
299-
*/
300-
export function threadHasCaughtUpTo(
301-
message: AcknowledgedThreadMessage,
302-
thread: {
303-
readonly sequence: number;
304-
readonly messages: ReadonlyArray<{ readonly id: string }> | undefined;
305-
},
306-
): boolean {
307-
if (message.sequence !== undefined && thread.sequence >= message.sequence) return true;
308-
return thread.messages?.some((entry) => entry.id === message.messageId) ?? false;
309-
}

‎packages/client-runtime/package.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@
303303
"types": "./src/state/threads.ts",
304304
"default": "./src/state/threads.ts"
305305
},
306+
"./state/thread-state": {
307+
"types": "./src/state/threadState.ts",
308+
"default": "./src/state/threadState.ts"
309+
},
306310
"./state/subagent-display": {
307311
"types": "./src/state/subagentDisplay.ts",
308312
"default": "./src/state/subagentDisplay.ts"

‎packages/client-runtime/src/state/threadState.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,19 @@ export const EMPTY_ENVIRONMENT_THREAD_STATE: EnvironmentThreadState = {
2525
history: EMPTY_THREAD_HISTORY_META,
2626
sequence: 0,
2727
};
28+
29+
/**
30+
* A thread holds a write once it has applied the write's commit sequence. A bounded
31+
* projection can page the message out later, so finding it is only a fallback for
32+
* servers that do not report the sequence.
33+
*/
34+
export function threadHasCaughtUpTo(
35+
write: { readonly messageId: string; readonly sequence?: number | undefined },
36+
thread: {
37+
readonly sequence: number;
38+
readonly messages: ReadonlyArray<{ readonly id: string }> | undefined;
39+
},
40+
): boolean {
41+
if (write.sequence !== undefined && thread.sequence >= write.sequence) return true;
42+
return thread.messages?.some((entry) => entry.id === write.messageId) ?? false;
43+
}

0 commit comments

Comments
 (0)