diff --git a/.coderabbit.yaml b/.coderabbit.yaml new file mode 100644 index 00000000..b29c1c34 --- /dev/null +++ b/.coderabbit.yaml @@ -0,0 +1,4 @@ +# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json +language: en-US +reviews: + high_level_summary: false # disable auto summary generation diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 00000000..ddb86227 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,47 @@ +name-template: 'v$RESOLVED_VERSION' +tag-template: 'v$RESOLVED_VERSION' +categories: + - title: '🚀 Features' + labels: + - 'feature' + - 'enhancement' + - title: '🐛 Bug Fixes' + labels: + - 'fix' + - 'bugfix' + - 'bug' + - title: '🧰 Maintenance' + labels: + - 'chore' + - 'documentation' +autolabeler: + - label: 'chore' + files: + - '*.md' + branch: + - '/docs{0,1}\/.+/' + - label: 'bug' + branch: + - '/fix\/.+/' + title: + - '/fix/i' + - label: 'enhancement' + branch: + - '/feature\/.+/' +change-template: '- $TITLE @$AUTHOR (#$NUMBER)' +change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks. +version-resolver: + major: + labels: + - 'major' + minor: + labels: + - 'minor' + patch: + labels: + - 'patch' + default: patch +template: | + ## Changes + + $CHANGES diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 36ad6eee..2ce5bcb7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,39 +22,55 @@ jobs: - { java-version: "11", os: "macos-latest", os-label: "macOS" } steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + - name: Set up JDK ${{ matrix.java-version }} - uses: actions/setup-java@v1 + uses: actions/setup-java@v4 with: - java-version: ${{ matrix.java-version }} - - - name: Grant execute permission for gradlew - run: chmod +x gradlew + distribution: 'temurin' + java-version: ${{ matrix.java-version }} + cache: 'maven' - name: Code style check - run: | - ./gradlew spotlessCheck + run: mvn spotless:check - - name: Build and Test - run: ./gradlew build test + - name: Build and Test with Coverage + run: | + mvn -pl api clean test-compile + mvn -pl api test jacoco:report + - name: Debug Test Results (Unix) + if: runner.os != 'Windows' + run: | + echo "Test Results:" + find . -name "TEST-*.xml" -exec cat {} \; + echo "JaCoCo Report Location:" + ls -la api/target/site/jacoco/ + + - name: Debug Test Results (Windows) + if: runner.os == 'Windows' + run: | + echo "Test Results:" + Get-ChildItem -Recurse -Filter "TEST-*.xml" | Get-Content + echo "JaCoCo Report Location:" + Get-ChildItem -Path "api\target\site\jacoco" -Force + - name: Generate JaCoCo Report - run: ./gradlew jacocoTestReport + run: mvn -pl api jacoco:report - name: Upload coverage to Codecov uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} - files: ./build/reports/jacoco/test/jacocoTestReport.xml + files: ./api/target/site/jacoco/jacoco.xml flags: unittests fail_ci_if_error: true + verbose: true - - name: Cache Gradle packages - uses: actions/cache@v3 + - name: Cache Maven packages + uses: actions/cache@v4 with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: | - ${{ runner.os }}-gradle- \ No newline at end of file + ${{ runner.os }}-m2- \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..0a6f22aa --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,29 @@ +name: Release +on: + push: + tags: + - '*' + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: '8' + distribution: 'temurin' + server-id: 'central' + server-username: OSSRH_USERNAME + server-password: OSSRH_PASSWORD + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} + gpg-passphrase: SIGN_KEY_PASS + cache: 'maven' + + - name: Build and Release + env: + SIGN_KEY_PASS: ${{ secrets.GPG_PASSPHRASE }} + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }} + run: | + mvn -pl api clean deploy -P release \ No newline at end of file diff --git a/.gitignore b/.gitignore index b18ad698..14bfd82d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ **/build/* **/bin/* **/obj/* +.mvn # Compiled class file *.class @@ -36,4 +37,5 @@ hs_err_pid* replay_pid* # BlueJ files -*.ctxt \ No newline at end of file +*.ctxt +**/target \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f4e6a882..cf1f6bd3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,19 +2,19 @@ Ensure your development environment has: - JDK 1.8 (Java 8) -- Gradle 8.x +- Maven 3.x ## Building the Project After cloning the project, run in the project root: ```shell -./gradlew build ++mvn clean install ``` ## IDE Setup -IntelliJ IDEA is recommended. When importing the project, select import as a Gradle project. +IntelliJ IDEA is recommended. When importing the project, select import as a Maven project. ## Code Style @@ -26,32 +26,34 @@ This project follows Google Java Style guidelines. In IntelliJ IDEA: You can run following command on the terminal to format code: ```shell -./gradlew spotlessApply +mvn spotless:apply ``` ## Git Hooks -We use the Gradle spotless plugin to ensure code quality. The project is configured to run checks automatically before each commit. +We use the Maven spotless plugin to ensure code quality. The project is configured to run checks automatically before each commit. To manually format code, run: ```shell -./gradlew spotlessApply +mvn spotless:apply ``` ## Dependency Management -This project uses Gradle for dependency management. To add new dependencies, modify the `build.gradle` file. +This project uses Maven for dependency management. To add new dependencies, modify the `build.gradle` file. Example: -```groovy -dependencies { - implementation 'com.example:library:1.0.0' -} +```xml + + com.example + example + version + ``` Make sure to run tests before committing: ```shell -./gradlew test jacocoTestReport jacocoTestCoverageVerification +mvn -pl api test jacoco:report ``` \ No newline at end of file diff --git a/README.md b/README.md index f30e52bb..3c41e9ea 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,24 @@ Key Features: - Optimized list APIs with Iterator Page object returns - Simple and intuitive API design for ease of use +## Importing + +### Gradle +```groovy +dependencies { + implementation 'com.coze:coze-api:+' +} +``` + +### Maven +```xml + + com.coze + coze-api + version + + +``` ## Usage @@ -24,10 +42,10 @@ Key Features: | oauth by web code | [WebOAuthExample.java](example/src/main/java/example/auth/WebOAuthExample.java) | | oauth by jwt flow | [JWTsOauthExample.java](example/src/main/java/example/auth/JWTOAuthExample.java) | | oauth by pkce flow | [PKCEOauthExample.java](example/src/main/java/example/auth/PKCEOAuthExample.java) | -| oauth by device flow | [DevicesOAuthExample.java](example/src/main/java/example/auth/DevicesOAuthExample.java) | +| oauth by device flow | [DevicesOAuthExample.java](example/src/main/java/example/auth/DeviceOAuthExample.java) | | handle auth exception | [HandlerExceptionExample.java](example/src/main/java/example/auth/HandlerExceptionExample.java) | -| bot create, publish and chat | [PublishBotExample.java](example/src/main/java/example/bot/PublishBotExample.java) | -| get bot and bot list | [GetBotExample.java](example/src/main/java/example/bot/GetBotExample.java) | +| bot create, publish and chat | [PublishBotExample.java](example/src/main/java/example/bot/BotPublishExample.java) | +| get bot and bot list | [GetBotExample.java](example/src/main/java/example/bot/BotRetrieveExample.java) | | non-stream chat | [ChatExample.java](example/src/main/java/example/chat/ChatExample.java) | | steam chat | [StreamChatExample.java](example/src/main/java/example/chat/StreamChatExample.java) | | chat with local plugin | [SubmitToolOutputExample.java](example/src/main/java/example/chat/SubmitToolOutputExample.java) | @@ -35,12 +53,12 @@ Key Features: | non-stream workflow chat | [RunWorkflowExample.java](example/src/main/java/example/workflow/RunWorkflowExample.java) | | stream workflow chat | [StreamWorkflowExample.java](example/src/main/java/example/workflow/StreamWorkflowExample.java) | | async workflow run | [AsyncRunWorkflowExample.java](example/src/main/java/example/workflow/AsyncRunWorkflowExample.java) | -| conversation | [CreateConversationExample.java](example/src/main/java/example/conversation/CreateConversationExample.java) | -| list conversation | [ListConversationsExample.java](example/src/main/java/example/conversation/ListConversationsExample.java) | -| workspace | [ListWorkspaceExample.java](example/src/main/java/example/workspace/ListWorkspaceExample.java) | -| create update delete message | [ListWorkspaceExample.java](example/src/main/java/example/conversation/message/CrudMessageExample.java) | -| list message | [ListWorkspaceExample.java](example/src/main/java/example/conversation/message/ListMessageExample.java) | -| create update delete document | [ListWorkspaceExample.java](example/src/main/java/example/datasets/document/CrudDocumentExample.java) | +| conversation | [CreateConversationExample.java](example/src/main/java/example/conversation/ConversationCreateExample.java) | +| list conversation | [ListConversationsExample.java](example/src/main/java/example/conversation/ConversationsListExample.java) | +| workspace | [ListWorkspaceExample.java](example/src/main/java/example/workspace/WorkspaceListExample.java) | +| create update delete message | [ListWorkspaceExample.java](example/src/main/java/example/conversation/message/MessageCrudExample.java) | +| list message | [ListWorkspaceExample.java](example/src/main/java/example/conversation/message/MessageListExample.java) | +| create update delete document | [ListWorkspaceExample.java](example/src/main/java/example/datasets/document/DocumentCrudExample.java) | | initial client | [InitServiceExample.java](example/src/main/java/example/service/InitClientExample.java) | | how to handle exception | [HandlerExceptionExample.java](example/src/main/java/example/service/HandlerExceptionExample.java) | | get request log id | [GetLogExample.java](example/src/main/java/example/service/GetLogExample.java) | diff --git a/api/build.gradle b/api/build.gradle deleted file mode 100644 index 35dabd6a..00000000 --- a/api/build.gradle +++ /dev/null @@ -1,87 +0,0 @@ -plugins { - id 'java-library' - id 'jacoco' -} - -dependencies { - api 'com.squareup.retrofit2:retrofit:2.9.0' - api 'com.squareup.retrofit2:adapter-rxjava2:2.9.0' - api 'org.slf4j:slf4j-api:2.0.12' - api 'com.squareup.okhttp3:okhttp:4.9.3' - - compileOnly 'org.projectlombok:lombok:1.18.30' - annotationProcessor 'org.projectlombok:lombok:1.18.30' - annotationProcessor 'org.projectlombok:lombok-mapstruct-binding:0.2.0' - implementation 'com.fasterxml.jackson.core:jackson-annotations:2.14.2' - implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.2' - implementation 'com.squareup.retrofit2:converter-jackson:2.9.0' - implementation 'com.auth0:java-jwt:3.18.2' - implementation 'com.github.scribejava:scribejava-core:8.3.1' - implementation 'io.jsonwebtoken:jjwt-api:0.11.5' - runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' - runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' - - testImplementation 'junit:junit:4.12' - testImplementation 'org.junit.platform:junit-platform-commons:1.8.2' - testImplementation 'org.mockito:mockito-core:4.11.0' - testImplementation 'org.mockito:mockito-junit-jupiter:4.11.0' - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2' - testImplementation 'ch.qos.logback:logback-classic:1.2.3' - testImplementation 'com.squareup.retrofit2:retrofit-mock:2.9.0' -} - -jacoco { - toolVersion = "0.8.7" -} - -jacocoTestReport { - reports { - xml.required = true - csv.required = true - } - afterEvaluate { - classDirectories.setFrom(files(classDirectories.files.collect { - fileTree(dir: it, exclude: [ - '**/client/**', - ]) - })) - } -} - -jacocoTestCoverageVerification { - violationRules { - rule { - element = 'BUNDLE' - limit { - counter = 'LINE' - value = 'COVEREDRATIO' - minimum = 0.5 - } - } - } - doLast { - println "Verification files:" - classDirectories.files.each { file -> - println file - } - } -} - -test { - useJUnitPlatform() - finalizedBy jacocoTestReport // 测试完成后自动生成报告 -} - -sourceSets { - main { - java { - srcDirs = ['src/main/java', 'src/main/resources'] - } - } - test { - java { - srcDirs = ['src/test/java', 'src/test/resources'] - } - } -} \ No newline at end of file diff --git a/api/pom.xml b/api/pom.xml new file mode 100644 index 00000000..d08dade8 --- /dev/null +++ b/api/pom.xml @@ -0,0 +1,289 @@ + + + 4.0.0 + + Coze Java SDK + The Java SDK for the Coze API + https://github.com/coze-dev/coze-java + + + + MIT License + https://github.com/coze-dev/coze-java/blob/main/LICENSE + + + + + + Chris Gou + dev@coze.com + Spring (SG) Pte. Ltd. + https://www.coze.com + + + + + com.coze + coze-sdk + 0.1.0-SNAPSHOT + + + coze-api + 0.1.1 + + + scm:git:git://github.com/coze-dev/coze-java.git + scm:git:ssh://github.com/coze-dev/coze-java.git + https://github.com/coze-dev/coze-java/tree/main + + + + + + ossrh + https://s01.oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2 + + + + + 2.9.0 + 2.14.2 + 0.11.5 + + + + + + com.squareup.retrofit2 + retrofit + ${retrofit.version} + + + com.squareup.retrofit2 + adapter-rxjava2 + ${retrofit.version} + + + com.squareup.retrofit2 + converter-jackson + ${retrofit.version} + + + + + org.slf4j + slf4j-api + 2.0.12 + + + + + com.squareup.okhttp3 + okhttp + 4.9.3 + + + + + com.fasterxml.jackson.core + jackson-annotations + ${jackson.version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + + + com.auth0 + java-jwt + 3.18.2 + + + io.jsonwebtoken + jjwt-api + ${jwt.version} + + + io.jsonwebtoken + jjwt-impl + ${jwt.version} + runtime + + + io.jsonwebtoken + jjwt-jackson + ${jwt.version} + runtime + + + + + com.github.scribejava + scribejava-core + 8.3.1 + + + + + junit + junit + 4.12 + test + + + org.mockito + mockito-core + 4.11.0 + test + + + org.mockito + mockito-junit-jupiter + 4.11.0 + test + + + ch.qos.logback + logback-classic + 1.2.3 + test + + + com.squareup.retrofit2 + retrofit-mock + ${retrofit.version} + test + + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.5.0 + + none + 8 + + -Xdoclint:none + + + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + + 1.8 + 1.8 + UTF-8 + true + true + true + true + + -verbose + -Xlint:all + + + + org.projectlombok + lombok + ${lombok.version} + + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.1 + + + attach-sources + + jar + + + + + + + + + + + release + + + performRelease + true + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 3.2.5 + + + --pinentry-mode + loopback + + + + + sign-artifacts + verify + + sign + + + + --pinentry-mode + loopback + + + + + + + + org.sonatype.central + central-publishing-maven-plugin + 0.5.0 + true + + central + true + + + + + + + + \ No newline at end of file diff --git a/api/src/main/java/com/coze/openapi/client/connversations/message/CreateMessageReq.java b/api/src/main/java/com/coze/openapi/client/connversations/message/CreateMessageReq.java index 55a67277..d51e2c82 100644 --- a/api/src/main/java/com/coze/openapi/client/connversations/message/CreateMessageReq.java +++ b/api/src/main/java/com/coze/openapi/client/connversations/message/CreateMessageReq.java @@ -56,13 +56,8 @@ public class CreateMessageReq extends BaseReq { @JsonProperty("meta_data") private Map metadata; - public abstract static class CreateMessageReqBuilder< - C extends CreateMessageReq, B extends CreateMessageReqBuilder> - extends BaseReqBuilder { - public B objectContent(List objects) { - this.content = Utils.toJson(objects); - this.contentType = MessageContentType.OBJECT_STRING; - return self(); - } + public void setObjectContent(List objects) { + this.content = Utils.toJson(objects); + this.contentType = MessageContentType.OBJECT_STRING; } } diff --git a/api/src/main/java/com/coze/openapi/client/connversations/message/UpdateMessageReq.java b/api/src/main/java/com/coze/openapi/client/connversations/message/UpdateMessageReq.java index 8ef542ec..24d19251 100644 --- a/api/src/main/java/com/coze/openapi/client/connversations/message/UpdateMessageReq.java +++ b/api/src/main/java/com/coze/openapi/client/connversations/message/UpdateMessageReq.java @@ -50,13 +50,8 @@ public class UpdateMessageReq extends BaseReq { @JsonProperty("content_type") private MessageContentType contentType; - public abstract static class UpdateMessageReqBuilder< - C extends UpdateMessageReq, B extends UpdateMessageReqBuilder> - extends BaseReqBuilder { - public B objectContent(List objects) { - this.content = Utils.toJson(objects); - this.contentType = MessageContentType.OBJECT_STRING; - return self(); - } + public void setObjectContent(List objects) { + this.content = Utils.toJson(objects); + this.contentType = MessageContentType.OBJECT_STRING; } } diff --git a/api/src/main/java/com/coze/openapi/client/dataset/document/UpdateDocumentReq.java b/api/src/main/java/com/coze/openapi/client/dataset/document/UpdateDocumentReq.java index 1284e2b2..a52eff93 100644 --- a/api/src/main/java/com/coze/openapi/client/dataset/document/UpdateDocumentReq.java +++ b/api/src/main/java/com/coze/openapi/client/dataset/document/UpdateDocumentReq.java @@ -24,6 +24,7 @@ public class UpdateDocumentReq extends BaseReq { @NonNull @JsonProperty("document_id") private Long documentID; + /** The new name of the knowledge base file. */ @JsonProperty("document_name") private String documentName; diff --git a/api/src/main/java/com/coze/openapi/service/auth/JWTOAuthClient.java b/api/src/main/java/com/coze/openapi/service/auth/JWTOAuthClient.java index 0b977e2f..2de8db8d 100644 --- a/api/src/main/java/com/coze/openapi/service/auth/JWTOAuthClient.java +++ b/api/src/main/java/com/coze/openapi/service/auth/JWTOAuthClient.java @@ -90,7 +90,7 @@ private String generateJWT(int ttl, String sessionName) { Jwts.builder() .setHeader(header) .setIssuer(this.clientID) - .setAudience("api.coze.cn") + .setAudience(this.hostName) .setIssuedAt(new Date(now * 1000)) .setExpiration(new Date((now + ttl) * 1000)) .setId(Utils.genRandomSign(16)) diff --git a/api/src/main/java/com/coze/openapi/service/auth/OAuthClient.java b/api/src/main/java/com/coze/openapi/service/auth/OAuthClient.java index bf44b4ce..b3017503 100644 --- a/api/src/main/java/com/coze/openapi/service/auth/OAuthClient.java +++ b/api/src/main/java/com/coze/openapi/service/auth/OAuthClient.java @@ -48,12 +48,23 @@ public abstract class OAuthClient { protected final String baseURL; protected final CozeAuthAPI api; protected final ExecutorService executorService; + protected final String hostName; protected OAuthClient(OAuthBuilder builder) { builder.init(); this.clientSecret = builder.clientSecret; this.clientID = builder.clientID; this.baseURL = builder.baseURL; + if (this.baseURL != null && !this.baseURL.isEmpty()) { + try { + java.net.URL url = new java.net.URL(this.baseURL); + this.hostName = url.getHost(); + } catch (Exception e) { + throw new RuntimeException("Invalid base URL: " + this.baseURL, e); + } + } else { + throw new RuntimeException("Base URL is required"); + } Retrofit retrofit = defaultRetrofit(builder.client, mapper, getBaseURL()); diff --git a/api/src/main/java/com/coze/openapi/service/service/CozeAPI.java b/api/src/main/java/com/coze/openapi/service/service/CozeAPI.java index e29fcaa8..870846d8 100644 --- a/api/src/main/java/com/coze/openapi/service/service/CozeAPI.java +++ b/api/src/main/java/com/coze/openapi/service/service/CozeAPI.java @@ -194,6 +194,7 @@ public CozeAPI build() { chatAPI, audioAPI); } + // 确保加上了 Auth 拦截器 private OkHttpClient parseClient(OkHttpClient client) { boolean hasAuthInterceptor = false; diff --git a/api/src/main/java/com/coze/openapi/service/service/chat/ChatService.java b/api/src/main/java/com/coze/openapi/service/service/chat/ChatService.java index e7051cf6..16b82b59 100644 --- a/api/src/main/java/com/coze/openapi/service/service/chat/ChatService.java +++ b/api/src/main/java/com/coze/openapi/service/service/chat/ChatService.java @@ -58,6 +58,7 @@ public CreateChatResp create(CreateChatReq req) { BaseResponse resp = Utils.execute(chatAPI.chat(conversationID, req, req)); return CreateChatResp.builder().chat(resp.getData()).logID(resp.getLogID()).build(); } + /* * Call the Chat API with non-streaming to send messages to a published Coze bot and * fetch chat status & message. diff --git a/build.gradle b/build.gradle deleted file mode 100644 index ad58ed7e..00000000 --- a/build.gradle +++ /dev/null @@ -1,48 +0,0 @@ -plugins { - id 'com.diffplug.spotless' version '6.11.0' apply false -} - -allprojects { - apply plugin: 'java' - - group = 'com.bytedance' - version = '1.0-SNAPSHOT' - - repositories { - mavenCentral() - gradlePluginPortal() - } - -} - - -subprojects { - apply plugin: 'java' - apply plugin: 'idea' - - sourceCompatibility = '1.8' - targetCompatibility = '1.8' - - dependencies { - compileOnly 'org.projectlombok:lombok:1.18.24' - annotationProcessor 'org.projectlombok:lombok:1.18.24' - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2' - } - - tasks.withType(JavaCompile).configureEach { - options.compilerArgs << "-Xlint:deprecation" - } - apply plugin: 'com.diffplug.spotless' - - spotless { - java { - removeUnusedImports() - googleJavaFormat('1.7') - endWithNewline() - trimTrailingWhitespace() - importOrder('java', 'javax', 'org', 'com', '') - licenseHeader '/* (C)$YEAR */' - } - } -} diff --git a/example/build.gradle b/example/build.gradle deleted file mode 100644 index 234d713d..00000000 --- a/example/build.gradle +++ /dev/null @@ -1,11 +0,0 @@ -dependencies { - implementation project(':api') -} - -sourceSets { - main { - java { - srcDirs = ['src/main/java', 'src/main/resources'] - } - } -} \ No newline at end of file diff --git a/example/pom.xml b/example/pom.xml new file mode 100644 index 00000000..6e61c98f --- /dev/null +++ b/example/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + + + com.coze + coze-sdk + 0.1.0-SNAPSHOT + + + coze-example + + + + com.coze + coze-api + 0.1.1 + + + \ No newline at end of file diff --git a/example/src/main/java/example/chat/SubmitToolOutputExample.java b/example/src/main/java/example/chat/SubmitToolOutputExample.java index d24b9fb2..b80a54cd 100644 --- a/example/src/main/java/example/chat/SubmitToolOutputExample.java +++ b/example/src/main/java/example/chat/SubmitToolOutputExample.java @@ -1,5 +1,6 @@ /* (C)2024 */ package example.chat; + /* * This use case teaches you how to use local plugin. * */ diff --git a/example/src/main/java/example/conversation/ConversationCreateExample.java b/example/src/main/java/example/conversation/ConversationCreateExample.java index 3591ed7b..6f24065c 100644 --- a/example/src/main/java/example/conversation/ConversationCreateExample.java +++ b/example/src/main/java/example/conversation/ConversationCreateExample.java @@ -44,21 +44,14 @@ public static void main(String[] args) { System.out.println("retrieve conversations:" + getResp); // you can manually create message for conversation - CreateMessageResp msgs = - coze.conversations() - .messages() - .create( - CreateMessageReq.builder() - .role(MessageRole.USER) - .conversationID(conversationID) - // if you want to create object content, you can use followed method to simplify - // your code - .objectContent( - Arrays.asList( - MessageObjectString.buildText("hello"), - MessageObjectString.buildImageByURL(System.getenv("IMAGE_FILE_PATH")), - MessageObjectString.buildFileByURL(System.getenv("FILE_URL")))) - .build()); + CreateMessageReq createMessageReq = + CreateMessageReq.builder().role(MessageRole.USER).conversationID(conversationID).build(); + createMessageReq.setObjectContent( + Arrays.asList( + MessageObjectString.buildText("hello"), + MessageObjectString.buildImageByURL(System.getenv("IMAGE_FILE_PATH")), + MessageObjectString.buildFileByURL(System.getenv("FILE_URL")))); + CreateMessageResp msgs = coze.conversations().messages().create(createMessageReq); System.out.println(msgs); ClearConversationResp clearResp = diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 7454180f..00000000 Binary files a/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index a5952066..00000000 --- a/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,5 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew deleted file mode 100755 index 744e882e..00000000 --- a/gradlew +++ /dev/null @@ -1,185 +0,0 @@ -#!/usr/bin/env sh - -# -# Copyright 2015 the original author or authors. -# -# 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 -# -# https://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. -# - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MSYS* | MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=`expr $i + 1` - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat deleted file mode 100644 index 107acd32..00000000 --- a/gradlew.bat +++ /dev/null @@ -1,89 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000..90ff8a45 --- /dev/null +++ b/pom.xml @@ -0,0 +1,135 @@ + + + 4.0.0 + + com.coze + coze-sdk + 0.1.0-SNAPSHOT + pom + + + api + example + + + + UTF-8 + 1.8 + 1.8 + 1.18.24 + 5.8.2 + + + + + org.projectlombok + lombok + ${lombok.version} + provided + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + + + + + org.jacoco + jacoco-maven-plugin + 0.8.11 + + ${project.reporting.outputDirectory}/jacoco + + HTML + XML + CSV + + + **/client/**/* + + + + + prepare-agent + + prepare-agent + + + + report + test + + report + + + + check + + check + + + + + BUNDLE + + + LINE + COVEREDRATIO + 0.50 + + + + + + + + + + com.diffplug.spotless + spotless-maven-plugin + 2.22.8 + + + + src/main/java/**/*.java + src/test/java/**/*.java + + + 1.7 + + + + + + java,javax,org,com, + + + /* (C)$YEAR */ + + + + + + spotless-check + validate + + check + + + + + + + \ No newline at end of file diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index c92b9611..00000000 --- a/settings.gradle +++ /dev/null @@ -1,3 +0,0 @@ -rootProject.name = 'coze-java' -include 'api', 'example' -