MCPcopy
hub / github.com/anomalyco/opencode / createTimelineModel

Function createTimelineModel

packages/app/src/pages/session/timeline/model.ts:10–95  ·  view source on GitHub ↗
(input: {
  sessionID: Accessor<string | undefined>
  revertMessageID: Accessor<string | undefined>
})

Source from the content-addressed store, hash-verified

8const sessionFreshness = 15_000
9
10export function createTimelineModel(input: {
11 sessionID: Accessor<string | undefined>
12 revertMessageID: Accessor<string | undefined>
13}) {
14 const serverSync = useServerSync()
15 const sync = useSync()
16 let refreshFrame: number | undefined
17 let refreshTimer: number | undefined
18
19 const [resource] = createResource(
20 () => input.sessionID(),
21 (id) => {
22 clearRefresh()
23 if (!id) return
24
25 const cached = untrack(() => sync().data.message[id] !== undefined)
26 const stale = cached && !serverSync().session.fresh(id, sessionFreshness)
27
28 refreshFrame = requestAnimationFrame(() => {
29 refreshFrame = undefined
30 refreshTimer = window.setTimeout(() => {
31 refreshTimer = undefined
32 if (input.sessionID() !== id) return
33 untrack(() => {
34 if (stale) void sync().session.sync(id, { force: true })
35 })
36 }, 0)
37 })
38
39 return sync().session.sync(id)
40 },
41 )
42 const messages = createMemo(() => {
43 const id = input.sessionID()
44 return id ? (sync().data.message[id] ?? []) : []
45 })
46 const ready = createMemo(() => {
47 const id = input.sessionID()
48 return !id || sync().data.message[id] !== undefined
49 })
50 const userMessages = createMemo(() => selectUserMessages(messages()), emptyUserMessages, { equals: same })
51 const visibleUserMessages = createMemo(
52 () => {
53 return selectVisibleUserMessages(userMessages(), input.revertMessageID())
54 },
55 emptyUserMessages,
56 { equals: same },
57 )
58 const more = createMemo(() => {
59 const id = input.sessionID()
60 return id ? sync().session.history.more(id) : false
61 })
62 const loading = createMemo(() => {
63 const id = input.sessionID()
64 return id ? sync().session.history.loading(id) : false
65 })
66 const loadOlder = async (options?: { before?: () => void; after?: (done: boolean) => void }) => {
67 return loadOlderTimeline({

Callers 1

PageFunction · 0.90

Calls 11

useSyncFunction · 0.90
clearRefreshFunction · 0.85
selectUserMessagesFunction · 0.85
userMessagesFunction · 0.85
visibleUserMessagesFunction · 0.85
syncMethod · 0.80
atMethod · 0.80
syncFunction · 0.50
serverSyncFunction · 0.50
messagesFunction · 0.50

Tested by

no test coverage detected