refactor(message-log-api): reorganize classes into separate files for clarity
ci / JVM build + tests (push) Has been cancelled
ci / JVM build + tests (push) Has been cancelled
- Extracted `TurnTokens`, `MessageOrigin`, and `MessageEvent` into standalone files. - Simplified `MessageContext` by externalizing `MessageOrigin`. - Improves modularity and code maintainability for append-only audit logs.
This commit is contained in:
@@ -1,25 +1,8 @@
|
||||
package pw.binom.agentik.messageLog
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
|
||||
/**
|
||||
* Контекст инициации хода (кто/что и почему). Дубликат типа из `:proto` —
|
||||
* живёт здесь чтобы не тащить `:proto` в слой хранения данных.
|
||||
*/
|
||||
@Serializable
|
||||
enum class MessageOrigin {
|
||||
@SerialName("user")
|
||||
USER,
|
||||
|
||||
@SerialName("system")
|
||||
SYSTEM,
|
||||
|
||||
@SerialName("event")
|
||||
EVENT,
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class MessageContext(
|
||||
val origin: MessageOrigin,
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package pw.binom.agentik.messageLog
|
||||
|
||||
sealed interface MessageEvent {
|
||||
val conversationId: String
|
||||
data class Appended(override val conversationId: String, val record: MessageRecord) : MessageEvent
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package pw.binom.agentik.messageLog
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* Контекст инициации хода (кто/что и почему). Дубликат типа из `:proto` —
|
||||
* живёт здесь чтобы не тащить `:proto` в слой хранения данных.
|
||||
*/
|
||||
@Serializable
|
||||
enum class MessageOrigin {
|
||||
@SerialName("user")
|
||||
USER,
|
||||
|
||||
@SerialName("system")
|
||||
SYSTEM,
|
||||
|
||||
@SerialName("event")
|
||||
EVENT,
|
||||
}
|
||||
@@ -4,21 +4,6 @@ import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlin.time.Instant
|
||||
|
||||
/**
|
||||
* Token usage одного assistant turn'а.
|
||||
*/
|
||||
@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" }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Запись в таблице `message` (append-only audit).
|
||||
*/
|
||||
|
||||
@@ -30,7 +30,3 @@ interface MessageStore : AutoCloseable {
|
||||
suspend fun tokenStats(conversationId: String): TokenStats
|
||||
}
|
||||
|
||||
sealed interface MessageEvent {
|
||||
val conversationId: String
|
||||
data class Appended(override val conversationId: String, val record: MessageRecord) : MessageEvent
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package pw.binom.agentik.messageLog
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* Token usage одного assistant turn'а.
|
||||
*/
|
||||
@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" }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user