Add private model catalog SDK support (AddCatalog, SelectCatalog, GetCatalogNames)#601
Add private model catalog SDK support (AddCatalog, SelectCatalog, GetCatalogNames)#601kobby-kobbs wants to merge 13 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Adds C# SDK support for managing private model catalogs (MDS integration) by extending the catalog API surface, implementing the new interop commands, and adding tests—while also reducing the risk of credential leakage in logs.
Changes:
- Extends
ICatalogwithAddCatalogAsync,SelectCatalogAsync, andGetCatalogNamesAsync. - Implements the new catalog-management commands in
Catalog, including forced refresh behavior. - Removes logging of command input in
CoreInteroperror paths and adds AOT JSON context forList<string>.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/cs/src/ICatalog.cs | Adds new public async catalog-management methods to the catalog interface. |
| sdk/cs/src/Catalog.cs | Implements add/select/list catalog operations and introduces a forceRefresh option for model updates. |
| sdk/cs/src/Detail/CoreInterop.cs | Stops logging command input in error paths to avoid leaking secrets. |
| sdk/cs/src/Detail/JsonSerializationContext.cs | Registers List<string> for source-generated JSON serialization (AOT). |
| sdk/cs/test/FoundryLocal.Tests/CatalogManagementTests.cs | Adds tests covering add/select/reset and catalog name listing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| private async Task UpdateModels(CancellationToken? ct) | ||
| private async Task UpdateModels(CancellationToken? ct, bool forceRefresh = false) |
There was a problem hiding this comment.
There is a function for invalidating the cache: InvalidateCache. Could you use that instead of adding forceRefresh?
There was a problem hiding this comment.
I reverted to the original signature, it now calls InvalidateCache in UpdateModels in both AddCatalogAsync and SelectCatalogAsync
| string? clientSecret = null, string? bearerToken = null, | ||
| string? tokenEndpoint = null, string? audience = null, |
There was a problem hiding this comment.
Can we keep only the essential arguments in the function and move all the optional arguments in a map argument.
Different catalogs may have different arguments that may be needed. So, the basic ones can be explicit arguments and the optional ones can be in a map?
There was a problem hiding this comment.
I see, I changed the signature to AddCatalogAsync(string name, Uri uri, Dictionary<string, string>? options = null, CancellationToken? ct = null)
| if (uri.Scheme != "https" && uri.Scheme != "http") | ||
| { | ||
| throw new ArgumentException($"Catalog URI must use http or https scheme, got '{uri.Scheme}'.", nameof(uri)); | ||
| } | ||
|
|
||
| if (tokenEndpoint != null) | ||
| { | ||
| if (!Uri.TryCreate(tokenEndpoint, UriKind.Absolute, out var parsedEndpoint)) | ||
| { | ||
| throw new ArgumentException($"Token endpoint is not a valid URL: '{tokenEndpoint}'.", nameof(tokenEndpoint)); | ||
| } | ||
| if (parsedEndpoint.Scheme != "https" && parsedEndpoint.Scheme != "http") | ||
| { | ||
| throw new ArgumentException($"Token endpoint must use http or https scheme, got '{parsedEndpoint.Scheme}'.", nameof(tokenEndpoint)); | ||
| } | ||
| } | ||
|
|
||
| await Utils.CallWithExceptionHandling(async () => | ||
| { | ||
| var request = new CoreInteropRequest | ||
| { | ||
| Params = new Dictionary<string, string> | ||
| { | ||
| ["Name"] = name, | ||
| ["Uri"] = uri.ToString(), | ||
| ["ClientId"] = clientId ?? "", | ||
| ["ClientSecret"] = clientSecret ?? "", | ||
| ["BearerToken"] = bearerToken ?? "", | ||
| ["TokenEndpoint"] = tokenEndpoint ?? "", | ||
| ["Audience"] = audience ?? "" | ||
| } | ||
| }; |
There was a problem hiding this comment.
Can all of this logic be moved to Core so each sdk need not have this logic?
There was a problem hiding this comment.
I think the actual catalog registration logic already lives in Core, the SDK calls the native add_catalog interop command which handles it. What is left in the SDK is just input validation (C# type safety), parameter marshaling into the interop request, and refreshing the local model cache afterward. These are all SDK-specific concerns that each SDK needs to handle in its own language, so there isn't much to move.
Aligns the C# SDK with the updated FoundryLocalCore native contract: - AddCatalogAsync now includes Type=AzurePrivate (overridable via options) in the add_catalog interop params, which the native dispatcher now requires. - Remove SelectCatalogAsync from ICatalog/Catalog and its unit test; the corresponding select_catalog handler was removed from the native layer. Callers can re-introduce per-catalog filtering when an Id-clash scenario becomes real.
End-to-end C# sample demonstrating ICatalog.AddCatalogAsync: - signs an RS256 JWT from a customer private key - registers a private MDS-backed catalog at runtime - lists public + private models, partitioned by registry Uri - downloads and streams chat with the selected model Falls back to public-only if AddCatalogAsync is unavailable.
f3f7d58 to
c550364
Compare
Summary
ICatalog:AddCatalogAsync,SelectCatalogAsync,GetCatalogNamesAsyncChanges by file
sdk/cs/src/ICatalog.csAdds three new interface methods with full XML documentation:
AddCatalogAsync— Register a private catalog with OAuth2/bearer auth supportSelectCatalogAsync— Filter models to a specific catalog (or null to show all)GetCatalogNamesAsync— List all registered catalog namessdk/cs/src/Catalog.csImplements the three new methods with:
forceRefreshparameter onUpdateModelsso Add/Select immediately refresh the model listGetCatalogNamesAsyncsdk/cs/src/Detail/CoreInterop.csRemoves logging of
commandInputin error paths to prevent leaking credentials (client secrets, bearer tokens) in debug logs.sdk/cs/src/Detail/JsonSerializationContext.csRegisters
List<string>for AOT-compatible JSON serialization of catalog names.sdk/cs/test/FoundryLocal.Tests/CatalogManagementTests.csNew test class with two tests:
Test_AddAndSelectCatalog— Verifies add + select + reset flowTest_GetCatalogNames— Verifies catalog name retrieval and deserialization