Skip to content

Commit

Permalink
refactor: move json config out of companion
Browse files Browse the repository at this point in the history
  • Loading branch information
realdavidvega committed Sep 26, 2024
1 parent 6b534ac commit 5d0d9bc
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import kotlinx.serialization.serializer
fun interface Tool<Input, out Output> {
suspend operator fun invoke(input: Input): Output

data class JsonConfig(val inputJson: Json, val outputJson: Json) {
companion object {
val Default = JsonConfig(inputJson = Json.Default, outputJson = Json.Default)
}
}

companion object {

data class ToolConfig<Input, out Output>(
Expand All @@ -25,15 +31,9 @@ fun interface Tool<Input, out Output> {

data class ToolSerializer(val serializer: KSerializer<*>, val json: Json)

data class ToolJson(val inputJson: Json, val outputJson: Json) {
companion object {
val Default = ToolJson(inputJson = Json.Default, outputJson = Json.Default)
}
}

inline fun <reified I, reified O> toolOf(
tool: Tool<I, O>,
jsonConfig: ToolJson = ToolJson.Default
jsonConfig: JsonConfig = JsonConfig.Default
): ToolConfig<I, O> {
val inputSerializer = ToolSerializer(serializer<I>(), jsonConfig.inputJson)
val outputSerializer = ToolSerializer(serializer<O>(), jsonConfig.outputJson)
Expand Down

0 comments on commit 5d0d9bc

Please sign in to comment.