-
Notifications
You must be signed in to change notification settings - Fork 1
Development - Sdk refactoring and general changes #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Added <IsTrimmable>true</IsTrimmable> to Core, Sdk, and Tools .csproj files to support trimming and reduce application size for publish scenarios.
Renamed ICivitaiSdkClient to ISdkClient, CivitaiSdkClient to SdkClient, and CivitaiSdkClientOptions to SdkClientOptions for improved naming consistency and clarity. Updated exception documentation to distinguish between ArgumentNullException and ArgumentException where appropriate.
Replaces CivitaiSdkClientOptions with SdkClientOptions.
Introduces a Validate() method to ImageJobControlNet to ensure that exactly one of ImageUrl or Image is provided. JobsService now calls this validation for ControlNet configurations in job requests to prevent invalid input.
Introduces MinModifier and MaxModifier constants to define valid range for priority modifier. The Priority constructor now throws ArgumentOutOfRangeException if the modifier is outside the allowed range, improving input validation and robustness.
Replaces string-based AIR source with the AirSource enum throughout the SDK for improved type safety and intellisense. Adds AirBuilder for fluent, immutable AIR construction. Updates parsing, serialization, and service interfaces to use AirIdentifier and AirSource. Documentation and JSON converters are updated to reflect the new types and usage patterns.
Renamed CivitaiSdkClientOptionsTests to SdkClientOptionsTests and updated references to SdkClientOptions. Updated AirIdentifierTests to use AirSource enum instead of string for source, removed string source validation tests, and expanded parsing tests to cover all AirSource values. Added comprehensive AirBuilderTests for builder behavior and immutability. Added ToolsTestFixture to Tools test project for shared test setup.
Introduces a comprehensive guide for the AIR Builder, detailing its fluent API for constructing AIR identifiers. Updates AIR identifier documentation to use strongly-typed classes and enums, adds builder pattern examples, and clarifies supported sources. Refactors references from ICivitaiSdkClient to ISdkClient and updates configuration and SDK introduction docs for consistency. Enhances tools introduction with AIR Builder feature.
Introduces immutable builder classes for constructing ImageJobControlNet, ImageJobNetworkParams, ImageJobParams, and TextToImageJobRequest objects. These builders provide a fluent API for configuring image generation jobs, including support for additional networks, ControlNet, and job submission via IJobsService.
Refactored CoverageService, JobsService, and UsageService to use C# primary constructors, removing explicit field assignments and constructor logic. Updated Priority struct to use a primary constructor. Added CreateTextToImage builder method to IJobsService and JobsService for fluent job creation.
Updated XML documentation for NullableControlNetPreprocessorConverter and NullableSchedulerConverter to specify handling of null values during JSON serialization and deserialization.
Changed BatchJobRequest from internal to public to allow usage outside its assembly. Also removed unnecessary JsonSerializable attribute for nullable Priority in SdkJsonContext.
Changed Priority from a readonly struct to a sealed record for improved immutability and clarity.
Improves and clarifies XML documentation comments across QueryStringBuilder, ISdkClient, SdkClientOptions, ICoverageService, IJobsService, and IUsageService. Updates include more concise summaries, improved parameter and return descriptions, and an added usage example for QueryStringBuilder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request represents a significant refactoring of the SDK with improvements to type safety, API design, and developer experience. The changes introduce strongly-typed AIR identifiers, fluent builder patterns for job creation, and modernize the codebase with primary constructors and record types.
Key Changes:
- Refactored AIR identifiers from string-based to enum-based sources (AirSource enum)
- Introduced fluent builder APIs (TextToImageJobBuilder, ImageJobParamsBuilder, etc.) for job creation
- Renamed SDK classes for consistency (CivitaiSdkClient → SdkClient, CivitaiSdkClientOptions → SdkClientOptions)
- Converted Priority from struct to record and added validation constants
- Modernized service constructors using primary constructor syntax
- Added comprehensive test coverage for new builder classes
Reviewed changes
Copilot reviewed 48 out of 48 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| Sdk/Air/AirIdentifier.cs | Refactored source from string to AirSource enum for type safety |
| Sdk/Air/AirSource.cs | New enum defining supported platforms (Civitai, HuggingFace, OpenAI, Leonardo) |
| Sdk/Air/AirBuilder.cs | New immutable builder for constructing AIR identifiers with validation |
| Sdk/Request/TextToImageJobBuilder.cs | New fluent builder for text-to-image job requests |
| Sdk/Request/ImageJobParamsBuilder.cs | New fluent builder for image generation parameters |
| Sdk/Request/ImageJobNetworkParamsBuilder.cs | New fluent builder for additional network parameters |
| Sdk/Request/ImageJobControlNetBuilder.cs | New fluent builder for ControlNet configurations |
| Sdk/SdkClient.cs | Renamed from CivitaiSdkClient for consistency |
| Sdk/SdkClientOptions.cs | Renamed from CivitaiSdkClientOptions with improved documentation |
| Sdk/Services/*.cs | Refactored to use primary constructors and updated to reference renamed types |
| Sdk/Models/Jobs/Priority.cs | Converted from struct to record with added validation constants |
| Sdk/Models/Jobs/ImageJobControlNet.cs | Added Validate method for ControlNet image source validation |
| Sdk/Json/Converters/AirIdentifierConverter.cs | New JSON converter for AirIdentifier serialization |
| Tests/**/*Tests.cs | Comprehensive test coverage for all new builder classes and updated tests for renamed types |
| Documentation/Guides/air-builder.md | New guide for AirBuilder usage (contains documentation issues) |
| Documentation/Guides/*.md | Updated documentation to reflect API changes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
No description provided.