Skip to content

Commit

Permalink
Feature/tool json schema externalized to library (#22)
Browse files Browse the repository at this point in the history
* JSON schema generation externalized to a library + more multiplatform targets

* build only jvm by default
  • Loading branch information
morisil authored Dec 4, 2024
1 parent 79e5841 commit 17747e4
Show file tree
Hide file tree
Showing 26 changed files with 780 additions and 411 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,3 @@ bin/
.DS_Store

/*.hprof

/kotlin-js-store
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Unofficial Kotlin multiplatform variant of the
[Antropic SDK](https://docs.anthropic.com/en/api/client-sdks).

[<img alt="Maven Central Version" src="https://img.shields.io/maven-central/v/com.xemantic.anthropic/anthropic-sdk-kotlin">](https://central.sonatype.com/namespace/com.xemantic.anthropic)
[<img alt="Maven Central Version" src="https://img.shields.io/maven-central/v/com.xemantic.anthropic/anthropic-sdk-kotlin">](https://central.sonatype.com/namespace/com.xemantic.anthropic/anthropic-sdk-kotlin)
[<img alt="GitHub Release Date" src="https://img.shields.io/github/release-date/xemantic/anthropic-sdk-kotlin">](https://github.com/xemantic/anthropic-sdk-kotlin/releases)
[<img alt="license" src="https://img.shields.io/github/license/xemantic/anthropic-sdk-kotlin?color=blue">](https://github.com/xemantic/anthropic-sdk-kotlin/blob/main/LICENSE)

Expand Down
141 changes: 92 additions & 49 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
@file:OptIn(ExperimentalKotlinGradlePluginApi::class)
@file:OptIn(ExperimentalKotlinGradlePluginApi::class, ExperimentalWasmDsl::class)

import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest

plugins {
alias(libs.plugins.kotlin.multiplatform)
Expand Down Expand Up @@ -40,10 +39,12 @@ val sonatypePassword: String? by project
val skipTests = isReleaseBuild

println("""
Project: ${project.name}
Version: ${project.version}
Release: $isReleaseBuild
""".trimIndent()
+--------------------------------------------
| Project: ${project.name}
| Version: ${project.version}
| Release build: $isReleaseBuild
+--------------------------------------------
"""
)

repositories {
Expand All @@ -52,11 +53,15 @@ repositories {

kotlin {

//explicitApi() // check with serialization?
compilerOptions {
apiVersion = kotlinTarget
languageVersion = kotlinTarget
extraWarnings.set(true)
freeCompilerArgs.add("-Xmulti-dollar-interpolation")
progressiveMode = true
}

jvm {
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
// set up according to https://jakewharton.com/gradle-toolchains-are-rarely-a-good-idea/
compilerOptions {
apiVersion = kotlinTarget
Expand All @@ -68,27 +73,68 @@ kotlin {
}

if (!isJvmOnlyBuild) {

js {
browser()
nodejs()
// browser tests switched off for a moment
browser {
testTask {
// for unknown reason browser tests are failing
enabled = false
useKarma {
useChromeHeadless()
}
}
}
nodejs {
testTask {
useMocha {
timeout = "20s"
}
}
}
binaries.library()
}

// linuxX64()
//
// mingwX64()
// macosArm64()

// val hostOs = System.getProperty("os.name")
// val isMingwX64 = hostOs.startsWith("Windows")
// val nativeTarget = when {
// hostOs == "Mac OS X" -> macosX64("native")
// hostOs == "Linux" -> linuxX64("native")
// isMingwX64 -> mingwX64("native")
// else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
// wasmJs {
// browser()
// nodejs()
// //d8()
// binaries.library()
// }

// wasmWasi {
// nodejs()
// binaries.library()
// }

// native, see https://kotlinlang.org/docs/native-target-support.html
// tier 1
macosX64()
macosArm64()
iosSimulatorArm64()
iosX64()
iosArm64()

// tier 2
linuxX64()
linuxArm64()
watchosSimulatorArm64()
watchosX64()
watchosArm32()
watchosArm64()
tvosSimulatorArm64()
tvosX64()
tvosArm64()

// // tier 3
// androidNativeArm32()
// androidNativeArm64()
// androidNativeX86()
// androidNativeX64()
mingwX64()
// watchosDeviceArm64()

// @OptIn(ExperimentalSwiftExportDsl::class)
// swiftExport {}
}

sourceSets {
Expand All @@ -100,6 +146,7 @@ kotlin {
implementation(libs.ktor.client.content.negotiation)
implementation(libs.ktor.client.logging)
implementation(libs.ktor.serialization.kotlinx.json)
implementation(libs.xemantic.ai.tool.schema)
}
}

Expand Down Expand Up @@ -146,6 +193,20 @@ kotlin {

}

if (!isJvmOnlyBuild) {
//// skip test for certain targets which are not fully supported by kotest
////tasks.named("compileTestKotlinWasmWasi") { enabled = false}
tasks.named("iosSimulatorArm64Test") { enabled = false }
tasks.named("watchosSimulatorArm64Test") { enabled = false }
tasks.named("tvosSimulatorArm64Test") { enabled = false }
//tasks.named("androidNativeArm64Test") { enabled = false }
//tasks.named("androidNativeX64Test") { enabled = false }
//tasks.named("androidNativeX86Test") { enabled = false }
//tasks.named("compileTestKotlinAndroidNativeX64") { enabled = false }
//
//// skip tests which require XCode components to be installed
}

fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
Expand All @@ -171,31 +232,16 @@ tasks.withType<Test> {
}
}



if (!isJvmOnlyBuild) {

tasks.withType<KotlinNativeTest> {
enabled = !skipTests
}

tasks.withType<KotlinJsTest> {
// for now always skip JS tests, until we will find how to safely pass apiKey to them
enabled = false
}

}

powerAssert {
functions = listOf(
"io.kotest.matchers.shouldBe"
)
includedSourceSets = listOf("commonTest", "jvmTest", "nativeTest")
// functions = listOf(
// "io.kotest.matchers.shouldBe"
// )
// includedSourceSets = listOf("commonTest", "jvmTest", "nativeTest")
}

// maybe this one is not necessary?
tasks.dokkaHtml.configure {
outputDirectory.set(buildDir.resolve("dokka"))
outputDirectory.set(layout.buildDirectory.dir("dokka"))
}

val javadocJar by tasks.registering(Jar::class) {
Expand All @@ -219,9 +265,6 @@ publishing {
publications {
withType<MavenPublication> {
artifact(javadocJar)
// from(components["kotlin"])
// artifact(javadocJar)
// artifact(sourcesJar)
pom {
name = "anthropic-sdk-kotlin"
description = "Kotlin multiplatform client for accessing Ahtropic APIs"
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
kotlin.code.style=official
kotlin.js.generate.executable.default=false
kotlin.native.ignoreDisabledTargets=true
kotlin.daemon.jvmargs=-Xmx1000m -Xms500m
group=com.xemantic.anthropic
version=0.10-SNAPSHOT
7 changes: 6 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
kotlinTarget = "2.0"
kotlinTarget = "2.1"
javaTarget = "17"

kotlin = "2.1.0"
Expand All @@ -8,6 +8,8 @@ kotlinxDatetime = "0.6.1"
ktor = "3.0.1"
kotest = "6.0.0.M1"

xemanticAiToolSchema = "0.1.1"

# logging is not used at the moment, might be enabled later
log4j = "2.24.2"
jackson = "2.18.2"
Expand All @@ -21,6 +23,9 @@ kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotl
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinxCoroutines" }
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinxDatetime" }

# xemantic
xemantic-ai-tool-schema = { module = "com.xemantic.ai:xemantic-ai-tool-schema", version.ref = "xemanticAiToolSchema"}

# logging libs
log4j-slf4j2 = { module = "org.apache.logging.log4j:log4j-slf4j2-impl", version.ref = "log4j" }
log4j-core = { module = "org.apache.logging.log4j:log4j-core", version.ref = "log4j" }
Expand Down
7 changes: 7 additions & 0 deletions karma.config.d/karma-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
config.set({
client: {
mocha: {
timeout: 20000
}
}
});
Loading

0 comments on commit 17747e4

Please sign in to comment.