MCPcopy Create free account
hub / github.com/tiann/hapi / refreshSession

Method refreshSession

hub/src/sync/sessionCache.ts:79–158  ·  view source on GitHub ↗
(sessionId: string)

Source from the content-addressed store, hash-verified

77 }
78
79 refreshSession(sessionId: string): Session | null {
80 let stored = this.store.sessions.getSession(sessionId)
81 if (!stored) {
82 const existed = this.sessions.delete(sessionId)
83 this.pendingThinkingUntilBySessionId.delete(sessionId)
84 this.runtimeConfigUpdatedAtBySessionId.delete(sessionId)
85 if (existed) {
86 this.publisher.emit({ type: 'session-removed', sessionId })
87 }
88 return null
89 }
90
91 const existing = this.sessions.get(sessionId)
92
93 if (stored.todos === null && !this.todoBackfillAttemptedSessionIds.has(sessionId)) {
94 this.todoBackfillAttemptedSessionIds.add(sessionId)
95 const messages = this.store.messages.getMessages(sessionId, 200)
96 for (let i = messages.length - 1; i >= 0; i -= 1) {
97 const message = messages[i]
98 const todos = extractTodoWriteTodosFromMessageContent(message.content)
99 if (todos) {
100 const updated = this.store.sessions.setSessionTodos(sessionId, todos, message.createdAt, stored.namespace)
101 if (updated) {
102 stored = this.store.sessions.getSession(sessionId) ?? stored
103 }
104 break
105 }
106 }
107 }
108
109 const metadata = (() => {
110 const parsed = MetadataSchema.safeParse(stored.metadata)
111 return parsed.success ? parsed.data : null
112 })()
113
114 const agentState = (() => {
115 const parsed = AgentStateSchema.safeParse(stored.agentState)
116 return parsed.success ? parsed.data : null
117 })()
118
119 const todos = (() => {
120 if (stored.todos === null) return undefined
121 const parsed = TodosSchema.safeParse(stored.todos)
122 return parsed.success ? parsed.data : undefined
123 })()
124
125 const teamState = (() => {
126 if (stored.teamState === null || stored.teamState === undefined) return undefined
127 const parsed = TeamStateSchema.safeParse(stored.teamState)
128 return parsed.success ? parsed.data : undefined
129 })()
130
131 const session: Session = {
132 id: stored.id,
133 namespace: stored.namespace,
134 seq: stored.seq,
135 createdAt: stored.createdAt,
136 updatedAt: stored.updatedAt,

Callers 15

resolveSessionAccessMethod · 0.95
getOrCreateSessionMethod · 0.95
reloadAllMethod · 0.95
handleSessionAliveMethod · 0.95
markMessageQueuedMethod · 0.95
recordSessionActivityMethod · 0.95
handleSessionEndMethod · 0.95
applySessionConfigMethod · 0.95
renameSessionMethod · 0.95
mergeSessionDataMethod · 0.95

Calls 6

getMethod · 0.80
setSessionTodosMethod · 0.80
getSessionMethod · 0.45
emitMethod · 0.45
getMessagesMethod · 0.45

Tested by

no test coverage detected