diff --git a/.github/scripts/update-readme-version.sh b/.github/scripts/update-readme-version.sh new file mode 100755 index 0000000..fcfdc8b --- /dev/null +++ b/.github/scripts/update-readme-version.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +# +# Copyright 2024 Kazimierz Pogoda / Xemantic +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Ensure VERSION environment variable is set +if [ -z "$VERSION" ]; then + echo "Error: VERSION environment variable is not set" + exit 1 +fi + +# Check if settings.gradle.kts exists +if [ ! -f "settings.gradle.kts" ]; then + echo "Error: settings.gradle.kts not found" + exit 1 +fi + +# Extract groupId and name from settings.gradle.kts +GROUP_ID=$(grep "val groupId = " settings.gradle.kts | sed -n 's/.*groupId = "\(.*\)".*/\1/p') +ARTIFACT_ID=$(grep "val name = " settings.gradle.kts | sed -n 's/.*name = "\(.*\)".*/\1/p') + +if [ -z "$GROUP_ID" ] || [ -z "$ARTIFACT_ID" ]; then + echo "Error: Could not extract groupId or name from settings.gradle.kts" + exit 1 +fi + +# Check if README.md exists +if [ ! -f "README.md" ]; then + echo "Error: README.md not found" + exit 1 +fi + +# Escape special characters in the group ID for sed +ESCAPED_GROUP_ID=$(echo "$GROUP_ID" | sed 's/\./\\./g') + +# Create the pattern to match +PATTERN="\"$ESCAPED_GROUP_ID:$ARTIFACT_ID:[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\"" + +# Create the replacement string +REPLACEMENT="\"$GROUP_ID:$ARTIFACT_ID:$VERSION\"" + +# Check if the pattern exists in the file +if ! grep -q "$GROUP_ID:$ARTIFACT_ID:[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*" README.md; then + echo "Error: Dependency pattern not found in README.md" + exit 1 +fi + +# Perform the replacement and save to a temporary file +sed "s|$PATTERN|$REPLACEMENT|g" README.md > README.md.tmp + +# Check if sed made any changes +if cmp -s README.md README.md.tmp; then + echo "No version updates were needed" + rm README.md.tmp + exit 0 +fi + +# Move the temporary file back to the original +mv README.md.tmp README.md + +echo "Successfully updated version to $VERSION in README.md" diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index c39b750..2063d25 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -44,28 +44,17 @@ jobs: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} run: ./gradlew -Pversion=$VERSION -PjvmOnlyBuild=false build sourcesJar dokkaHtml publishToSonatype closeAndReleaseSonatypeStagingRepository - - name: Find branch from tag - id: find-branch - env: - TAG_NAME: ${{ github.event.release.tag_name }} - run: | - BRANCH=$(git branch -r --contains $TAG_NAME | grep -v '\->' | sed 's/origin\///' | head -n 1) - if [ -z "$BRANCH" ]; then - echo "Branch not found for tag $TAG" - exit 1 - fi - echo Branch: $BRANCH - echo "BRANCH=$BRANCH" >> $GITHUB_ENV - - - name: Checkout branch HEAD - run: git checkout ${BRANCH} + - name: Checkout main branch + uses: actions/checkout@v4.2.2 + with: + ref: main + fetch-depth: 0 -# - name: Update README -# run: sed -i "s/com\.xemantic\.anthropic:anthropic-sdk-kotlin:[0-9]\+\(\.[0-9]\+\)*\>/com.xemantic.anthropic:anthropic-sdk-kotlin:$VERSION/g" README.md + - name: Update README + run: sh .github/scripts/update-readme-version.sh - - name: Create Pull Request - uses: peter-evans/create-pull-request@v7.0.5 + - name: Commit README + uses: stefanzweifel/git-auto-commit-action@v5.0.1 with: - token: ${{ secrets.WORKFLOW_SECRET }} - commit-message: README.md gradle dependencies update to ${{ env.VERSION }} - title: PR Action - README.md gradle dependencies update to ${{ env.VERSION }} + commit_message: Dependency version in README.md updated to ${{ env.VERSION }} + file_pattern: 'README.md' diff --git a/README.md b/README.md index eef6259..c68dcd0 100644 --- a/README.md +++ b/README.md @@ -251,3 +251,15 @@ export ANTHROPIC_API_KEY=your-key-goes-here Many [unit tests](src/commonTest/kotlin) are actually integration tests calling Anthropic APIs and asserting against results. This is the reason why they might be flaky from time to time. For example if the test image is misinterpreted, or Claude is randomly fantasizing too much. + +## Project dependencies + +API dependencies (will be provided as transitive dependencies of `anthropic-sdk-kotlin`): + +* [xemantic-ai-tool-schema](https://github.com/xemantic/xemantic-ai-tool-schema) +* [xemantic-ai-money](https://github.com/xemantic/xemantic-ai-money) +* [kotlinx-datetime](https://github.com/Kotlin/kotlinx-datetime) + +Implementation dependencies: + +* [ktor](https://ktor.io/) diff --git a/build.gradle.kts b/build.gradle.kts index 008d028..8f9ccc5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,6 +7,7 @@ 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.swiftexport.ExperimentalSwiftExportDsl plugins { alias(libs.plugins.kotlin.multiplatform) @@ -134,21 +135,21 @@ kotlin { mingwX64() // watchosDeviceArm64() -// @OptIn(ExperimentalSwiftExportDsl::class) -// swiftExport {} + @OptIn(ExperimentalSwiftExportDsl::class) + swiftExport {} } sourceSets { commonMain { dependencies { - implementation(libs.kotlinx.datetime) + api(libs.xemantic.ai.tool.schema) + api(libs.xemantic.ai.money) + api(libs.kotlinx.datetime) implementation(libs.ktor.client.core) implementation(libs.ktor.client.content.negotiation) implementation(libs.ktor.client.logging) implementation(libs.ktor.serialization.kotlinx.json) - implementation(libs.xemantic.ai.tool.schema) - api(libs.xemantic.ai.money) } } diff --git a/gradle.properties b/gradle.properties index 4fe38ea..1a3abbb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,9 @@ 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 +kotlin.apple.xcodeCompatibility.nowarn=true +kotlin.experimental.swift-export.enabled=true +kotlin.native.enableKlibsCrossCompilation=true +kotlin.incremental.wasm=true +org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled +org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true +version=0.11-SNAPSHOT diff --git a/settings.gradle.kts b/settings.gradle.kts index 8035bda..619e707 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1 +1,7 @@ -rootProject.name = "anthropic-sdk-kotlin" +val groupId = "com.xemantic.anthropic" +val name = "anthropic-sdk-kotlin" + +rootProject.name = name +gradle.beforeProject { + group = groupId +} diff --git a/src/commonMain/kotlin/batch/Batches.kt b/src/commonMain/kotlin/batch/Batches.kt index a8d7f7f..400d5e6 100644 --- a/src/commonMain/kotlin/batch/Batches.kt +++ b/src/commonMain/kotlin/batch/Batches.kt @@ -18,7 +18,7 @@ package com.xemantic.anthropic.batch import com.xemantic.anthropic.Response import com.xemantic.anthropic.message.Message -import kotlinx.datetime.LocalDateTime +import kotlinx.datetime.Instant import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -74,13 +74,13 @@ data class MessageBatchResponse( @SerialName("request_counts") val requestCounts: RequestCounts, @SerialName("ended_at") - val endedAt: LocalDateTime?, + val endedAt: Instant?, @SerialName("created_at") - val createdAt: LocalDateTime, + val createdAt: Instant, @SerialName("expires_at") - val expiresAt: LocalDateTime, + val expiresAt: Instant, @SerialName("cancel_initiated_at") - val cancelInitiatedAt: LocalDateTime?, + val cancelInitiatedAt: Instant?, @SerialName("results_url") val resultsUrl: String? ) : Response(type = "message_batch")