Skip to content

Commit 803d973

Browse files
committed
Enable session restore.
1 parent 895d004 commit 803d973

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

embabel-chat-store/src/main/kotlin/com/embabel/chat/store/adapter/StoredConversationFactory.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,31 @@ class StoredConversationFactory @JvmOverloads constructor(
8181
return createInternal(id, user = null, agent = null)
8282
}
8383

84+
/**
85+
* Load an existing conversation from storage.
86+
*
87+
* If the session exists, returns a [StoredConversation] that will load
88+
* messages from the repository. The session owner becomes the default user
89+
* for message attribution.
90+
*
91+
* @param id the conversation/session ID to load
92+
* @return the conversation if found, null otherwise
93+
*/
94+
override fun load(id: String): Conversation? {
95+
return repository.findBySessionId(id).orElse(null)?.let { session ->
96+
StoredConversation(
97+
id = id,
98+
repository = repository,
99+
eventPublisher = eventPublisher,
100+
user = session.owner,
101+
agent = null,
102+
title = session.session.title,
103+
titleGenerator = titleGenerator,
104+
scope = scope
105+
)
106+
}
107+
}
108+
84109
/**
85110
* Create a conversation for a 1-1 chat between a user and an agent.
86111
*

0 commit comments

Comments
 (0)