refactor: migrate EventStore and MessageStore to :outbox-api and :journal-api
ci / JVM build + tests (push) Failing after 1m9s
ci / JVM build + tests (push) Failing after 1m9s
- Replaced usages of `:message-store-api` and `:working-memory-api` with `:journal-api`, `:outbox-api`, and `:context-api`. - Deprecated legacy `EventStore` and `MessageStore` interfaces, added `typealias` for backward compatibility. - Updated imports across all modules with references to `:journal-api` and `:outbox-api`. - Introduced `journalRoutes` and `outboxRoutes` in `:server` for audit log and live event stream endpoints. - Adjusted `Agent` to expose read-only `journal` and `outbox` stores for improved modularity and clarity. - Removed legacy Event and AgentEvent definitions from `:proto`, migrated to `:outbox-api`. - Storage-related modules have been updated to support the new APIs consistently.
This commit is contained in:
@@ -20,6 +20,9 @@ kotlin {
|
||||
api(libs.kotlinx.coroutines.core)
|
||||
api(libs.kotlinx.serialization.core)
|
||||
api(libs.kotlinx.serialization.json)
|
||||
// typealias-обёртки указывают на :journal-api — без него
|
||||
// компиляция падает на Unresolved reference 'journal'.
|
||||
api(project(":journal-api"))
|
||||
}
|
||||
commonTest.dependencies {
|
||||
implementation(kotlin("test"))
|
||||
|
||||
@@ -1,24 +1,13 @@
|
||||
package pw.binom.agentik.messageLog
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* Часть контента сообщения на уровне хранилища. Намеренно НЕ зависит от
|
||||
* `pw.binom.agentik.proto.Content` — маппинг `:proto.Content ↔ Content` живёт
|
||||
* в `Mapping.kt` storage impl'ов.
|
||||
* @Deprecated
|
||||
* Перенесено в `:journal-api`. Используй `pw.binom.agentik.journal.Content`.
|
||||
*
|
||||
* Backward-compat typealias.
|
||||
*/
|
||||
@Serializable
|
||||
sealed interface Content {
|
||||
@Serializable
|
||||
@SerialName("text")
|
||||
data class Text(val body: String) : Content
|
||||
|
||||
@Serializable
|
||||
@SerialName("image")
|
||||
data class Image(val data: ByteArray, val mime: String) : Content {
|
||||
override fun equals(other: Any?): Boolean =
|
||||
this === other || (other is Image && mime == other.mime && data.contentEquals(other.data))
|
||||
override fun hashCode(): Int = 31 * mime.hashCode() + data.contentHashCode()
|
||||
}
|
||||
}
|
||||
@Deprecated(
|
||||
message = "Перенесено в :journal-api. Используй pw.binom.agentik.journal.Content.",
|
||||
replaceWith = ReplaceWith("Content", "pw.binom.agentik.journal.Content"),
|
||||
)
|
||||
typealias Content = pw.binom.agentik.journal.Content
|
||||
|
||||
+10
-9
@@ -1,12 +1,13 @@
|
||||
package pw.binom.agentik.messageLog
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
|
||||
@Serializable
|
||||
data class MessageContext(
|
||||
val origin: MessageOrigin,
|
||||
val sourceId: String? = null,
|
||||
val description: String? = null,
|
||||
val metadata: JsonElement? = null,
|
||||
/**
|
||||
* @Deprecated
|
||||
* Перенесено в `:journal-api`. Используй `pw.binom.agentik.journal.MessageContext`.
|
||||
*
|
||||
* Backward-compat typealias.
|
||||
*/
|
||||
@Deprecated(
|
||||
message = "Перенесено в :journal-api. Используй pw.binom.agentik.journal.MessageContext.",
|
||||
replaceWith = ReplaceWith("MessageContext", "pw.binom.agentik.journal.MessageContext"),
|
||||
)
|
||||
typealias MessageContext = pw.binom.agentik.journal.MessageContext
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
package pw.binom.agentik.messageLog
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* Контекст инициации хода (кто/что и почему). Дубликат типа из `:proto` —
|
||||
* живёт здесь чтобы не тащить `:proto` в слой хранения данных.
|
||||
* @Deprecated
|
||||
* Перенесено в `:journal-api`. Используй `pw.binom.agentik.journal.MessageOrigin`.
|
||||
*
|
||||
* Backward-compat typealias.
|
||||
*/
|
||||
@Serializable
|
||||
enum class MessageOrigin {
|
||||
@SerialName("user")
|
||||
USER,
|
||||
|
||||
@SerialName("system")
|
||||
SYSTEM,
|
||||
|
||||
@SerialName("event")
|
||||
EVENT,
|
||||
}
|
||||
@Deprecated(
|
||||
message = "Перенесено в :journal-api. Используй pw.binom.agentik.journal.MessageOrigin.",
|
||||
replaceWith = ReplaceWith("MessageOrigin", "pw.binom.agentik.journal.MessageOrigin"),
|
||||
)
|
||||
typealias MessageOrigin = pw.binom.agentik.journal.MessageOrigin
|
||||
|
||||
@@ -1,71 +1,13 @@
|
||||
package pw.binom.agentik.messageLog
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlin.time.Instant
|
||||
|
||||
/**
|
||||
* Запись в таблице `message` (append-only audit).
|
||||
* @Deprecated
|
||||
* Перенесено в `:journal-api`. Используй `pw.binom.agentik.journal.MessageRecord`.
|
||||
*
|
||||
* Backward-compat typealias.
|
||||
*/
|
||||
@Serializable
|
||||
sealed interface MessageRecord {
|
||||
val id: String
|
||||
val conversationId: String
|
||||
val createdAt: Instant
|
||||
|
||||
@Serializable
|
||||
sealed interface Body : MessageRecord {
|
||||
val content: List<Content>
|
||||
}
|
||||
|
||||
@Serializable
|
||||
@SerialName("user")
|
||||
data class UserMessage(
|
||||
override val id: String,
|
||||
override val conversationId: String,
|
||||
override val content: List<Content>,
|
||||
override val createdAt: Instant,
|
||||
val context: MessageContext? = null,
|
||||
) : Body
|
||||
|
||||
@Serializable
|
||||
@SerialName("assistant")
|
||||
data class AssistantMessage(
|
||||
override val id: String,
|
||||
override val conversationId: String,
|
||||
override val content: List<Content>,
|
||||
override val createdAt: Instant,
|
||||
val tokens: TurnTokens? = null,
|
||||
) : Body
|
||||
|
||||
@Serializable
|
||||
@SerialName("tool_call")
|
||||
data class ToolCall(
|
||||
override val id: String,
|
||||
override val conversationId: String,
|
||||
val toolName: String,
|
||||
val toolTitle: String?,
|
||||
val toolArgsJson: String,
|
||||
override val createdAt: Instant,
|
||||
) : MessageRecord
|
||||
|
||||
@Serializable
|
||||
@SerialName("tool_result")
|
||||
data class ToolResult(
|
||||
override val id: String,
|
||||
override val conversationId: String,
|
||||
val toolCallId: String,
|
||||
val result: String?,
|
||||
override val createdAt: Instant,
|
||||
) : MessageRecord
|
||||
|
||||
@Serializable
|
||||
@SerialName("error")
|
||||
data class Error(
|
||||
override val id: String,
|
||||
override val conversationId: String,
|
||||
val message: String,
|
||||
val code: String?,
|
||||
override val createdAt: Instant,
|
||||
) : MessageRecord
|
||||
}
|
||||
@Deprecated(
|
||||
message = "Перенесено в :journal-api. Используй pw.binom.agentik.journal.MessageRecord.",
|
||||
replaceWith = ReplaceWith("MessageRecord", "pw.binom.agentik.journal.MessageRecord"),
|
||||
)
|
||||
typealias MessageRecord = pw.binom.agentik.journal.MessageRecord
|
||||
|
||||
@@ -1,41 +1,17 @@
|
||||
package pw.binom.agentik.messageLog
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlin.time.Instant
|
||||
|
||||
/**
|
||||
* Append-only audit log сообщений — read-only представление.
|
||||
* @Deprecated
|
||||
* Перенесено в `:journal-api`. Используй `pw.binom.agentik.journal.JournalStore`.
|
||||
*
|
||||
* Producer-операция [MutableMessageStore.append] находится на
|
||||
* [MutableMessageStore] — этот интерфейс только для чтения, чтобы
|
||||
* consumer'ы физически не могли писать в audit log.
|
||||
* Backward-compat typealias. Все существующие consumer'ы
|
||||
* (`:standalone`, `:storage-ksqlite`, `:storage-inmemory`, тесты) импортируют
|
||||
* `pw.binom.agentik.messageLog.MessageStore`. Буквально тот же тип.
|
||||
*
|
||||
* Никаких обновлений, никакого удаления (кроме каскадного вместе
|
||||
* с ConversationStore.delete).
|
||||
* Удалить когда все импорты будут на `:journal-api`.
|
||||
*/
|
||||
interface MessageStore : AutoCloseable {
|
||||
|
||||
suspend fun list(conversationId: String, after: Instant, offset: Int, limit: Int): List<MessageRecord>
|
||||
|
||||
/**
|
||||
* Cold-flow paging через [list]. Default-реализация делает N+1 round-trip
|
||||
* (по странице через `list()` пока не получит короткую страницу). Для
|
||||
* in-memory backend'ов это OK; remote/SQLite impl'ы могут override'нуть
|
||||
* на `Channel` / cursor-батчинг, чтобы избежать per-page round-trip.
|
||||
*/
|
||||
fun listFlow(conversationId: String, after: Instant, pageSize: Int = PAGE_SIZE): Flow<MessageRecord> = flow {
|
||||
var offset = 0
|
||||
while (true) {
|
||||
val page = list(conversationId, after, offset, pageSize)
|
||||
if (page.isEmpty()) return@flow
|
||||
for (rec in page) emit(rec)
|
||||
if (page.size < pageSize) return@flow
|
||||
offset += page.size
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val PAGE_SIZE = 100
|
||||
}
|
||||
}
|
||||
@Deprecated(
|
||||
message = "Перенесено в :journal-api. Используй pw.binom.agentik.journal.JournalStore.",
|
||||
replaceWith = ReplaceWith("JournalStore", "pw.binom.agentik.journal.JournalStore"),
|
||||
)
|
||||
typealias MessageStore = pw.binom.agentik.journal.JournalStore
|
||||
|
||||
+9
-11
@@ -1,17 +1,15 @@
|
||||
package pw.binom.agentik.messageLog
|
||||
|
||||
/**
|
||||
* Mutable вариант [MessageStore] — добавляет producer-операцию [append].
|
||||
* @Deprecated
|
||||
* Перенесено в `:journal-api`. Используй `pw.binom.agentik.journal.MutableJournalStore`.
|
||||
*
|
||||
* Этот интерфейс предназначен **только для producer'ов** (ChatAgent,
|
||||
* ConversationLoop, ToolDispatcher, sub-agents, A2A-bridge).
|
||||
* Consumer'ы (DebugRoutes, admin dashboards, parent agents) должны
|
||||
* принимать **read-only** [MessageStore] — тогда невозможно случайно
|
||||
* записать в audit log из observer'а.
|
||||
* Backward-compat typealias. `MutableMessageStore` == `MutableJournalStore` (один тип).
|
||||
*
|
||||
* **Append семантика**: см. KDoc [MessageStore.append][MessageStore] —
|
||||
* на этом интерфейсе (не дублируем).
|
||||
* Удалить когда все импорты будут на `:journal-api`.
|
||||
*/
|
||||
interface MutableMessageStore : MessageStore {
|
||||
suspend fun append(record: MessageRecord)
|
||||
}
|
||||
@Deprecated(
|
||||
message = "Перенесено в :journal-api. Используй pw.binom.agentik.journal.MutableJournalStore.",
|
||||
replaceWith = ReplaceWith("MutableJournalStore", "pw.binom.agentik.journal.MutableJournalStore"),
|
||||
)
|
||||
typealias MutableMessageStore = pw.binom.agentik.journal.MutableJournalStore
|
||||
|
||||
@@ -1,47 +1,13 @@
|
||||
package pw.binom.agentik.messageLog
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.builtins.ListSerializer
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
private val bodyJson = Json {
|
||||
ignoreUnknownKeys = true
|
||||
encodeDefaults = true
|
||||
explicitNulls = false
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class MessageBodyPayload(
|
||||
val content: List<Content>,
|
||||
@SerialName("context")
|
||||
val context: MessageContext? = null,
|
||||
val tokens: TurnTokens? = null,
|
||||
/**
|
||||
* @Deprecated
|
||||
* Перенесено в `:journal-api`. Используй `pw.binom.agentik.journal.MessageBodyPayload`.
|
||||
*
|
||||
* Backward-compat typealias.
|
||||
*/
|
||||
@Deprecated(
|
||||
message = "Перенесено в :journal-api. Используй pw.binom.agentik.journal.MessageBodyPayload.",
|
||||
replaceWith = ReplaceWith("MessageBodyPayload", "pw.binom.agentik.journal.MessageBodyPayload"),
|
||||
)
|
||||
|
||||
fun encodeBodyPayload(
|
||||
content: List<Content>,
|
||||
context: MessageContext? = null,
|
||||
tokens: TurnTokens? = null,
|
||||
): String = bodyJson.encodeToString(
|
||||
MessageBodyPayload.serializer(),
|
||||
MessageBodyPayload(content = content, context = context, tokens = tokens),
|
||||
)
|
||||
|
||||
fun decodeBodyPayload(json: String): BodyDecoded = readPayload(json)
|
||||
|
||||
data class BodyDecoded(
|
||||
val content: List<Content>,
|
||||
val context: MessageContext?,
|
||||
val tokens: TurnTokens? = null,
|
||||
)
|
||||
|
||||
private fun readPayload(json: String): BodyDecoded {
|
||||
return try {
|
||||
val p = bodyJson.decodeFromString(MessageBodyPayload.serializer(), json)
|
||||
BodyDecoded(p.content, p.context, p.tokens)
|
||||
} catch (e: kotlinx.serialization.SerializationException) {
|
||||
val arr = bodyJson.decodeFromString(ListSerializer(Content.serializer()), json)
|
||||
BodyDecoded(arr, null, null)
|
||||
}
|
||||
}
|
||||
typealias MessageBodyPayload = pw.binom.agentik.journal.MessageBodyPayload
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
package pw.binom.agentik.messageLog
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* Token usage одного assistant turn'а.
|
||||
* @Deprecated
|
||||
* Перенесено в `:journal-api`. Используй `pw.binom.agentik.journal.TurnTokens`.
|
||||
*
|
||||
* Backward-compat typealias.
|
||||
*/
|
||||
@Serializable
|
||||
data class TurnTokens(
|
||||
val input: Int,
|
||||
val output: Int,
|
||||
) {
|
||||
val total: Int get() = input + output
|
||||
init {
|
||||
require(input >= 0) { "input tokens must be non-negative, got $input" }
|
||||
require(output >= 0) { "output tokens must be non-negative, got $output" }
|
||||
}
|
||||
}
|
||||
@Deprecated(
|
||||
message = "Перенесено в :journal-api. Используй pw.binom.agentik.journal.TurnTokens.",
|
||||
replaceWith = ReplaceWith("TurnTokens", "pw.binom.agentik.journal.TurnTokens"),
|
||||
)
|
||||
typealias TurnTokens = pw.binom.agentik.journal.TurnTokens
|
||||
|
||||
Reference in New Issue
Block a user