Added updateApiConfigurationPartial with FieldMask to allow for partial ApiProvider updates (#6731)
This commit is contained in:
1 parent
bb4211ff2a
commit
835204c7eb
3 files changed
+80
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"claude-dev": patch
|
||||
---
|
||||
|
||||
Added updateApiConfigurationPartial with FieldMask to allow for partial ApiProvider updates
|
||||
@@ -2,6 +2,7 @@ syntax = "proto3";
|
||||
|
||||
package cline;
|
||||
import "cline/common.proto";
|
||||
import "google/protobuf/field_mask.proto";
|
||||
option go_package = "github.com/cline/grpc-go/cline";
|
||||
option java_package = "bot.cline.proto";
|
||||
option java_multiple_files = true;
|
||||
@@ -28,6 +29,8 @@ service ModelsService {
|
||||
rpc subscribeToOpenRouterModels(EmptyRequest) returns (stream OpenRouterCompatibleModelInfo);
|
||||
// Updates API configuration
|
||||
rpc updateApiConfigurationProto(UpdateApiConfigurationRequest) returns (Empty);
|
||||
// Updates API configuration with partial values (only updates fields that are explicitly set)
|
||||
rpc updateApiConfigurationPartial(UpdateApiConfigurationPartialRequest) returns (Empty);
|
||||
// Refreshes and returns Groq models
|
||||
rpc refreshGroqModels(EmptyRequest) returns (OpenRouterCompatibleModelInfo);
|
||||
// Refreshes and returns Baseten models
|
||||
@@ -130,6 +133,21 @@ message UpdateApiConfigurationRequest {
|
||||
ModelsApiConfiguration api_configuration = 2;
|
||||
}
|
||||
|
||||
// Request for partially updating API configuration using FieldMask
|
||||
// Only fields specified in update_mask will be updated from api_configuration
|
||||
message UpdateApiConfigurationPartialRequest {
|
||||
Metadata metadata = 1;
|
||||
|
||||
// The API configuration with values to update.
|
||||
// Only fields listed in update_mask will be applied from this configuration.
|
||||
ModelsApiConfiguration api_configuration = 2;
|
||||
|
||||
// Mask specifying which top-level fields from api_configuration to update.
|
||||
// Field names should use camelCase (e.g., "apiKey", "planModeApiProvider").
|
||||
// If a field is in the mask but not set in api_configuration, it will be cleared (set to undefined).
|
||||
google.protobuf.FieldMask update_mask = 3;
|
||||
}
|
||||
|
||||
// Model info for OCA (OpenAI-compatible) models exposed by the OCA provider
|
||||
message OcaModelInfo {
|
||||
// Maximum completion tokens per request supported by this model
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { buildApiHandler } from "@core/api"
|
||||
import { Empty } from "@shared/proto/cline/common"
|
||||
import { UpdateApiConfigurationPartialRequest } from "@shared/proto/cline/models"
|
||||
import { convertProtoToApiConfiguration } from "@shared/proto-conversions/models/api-configuration-conversion"
|
||||
import type { Controller } from "../index"
|
||||
|
||||
/**
|
||||
* Updates API configuration with partial values using FieldMask
|
||||
*
|
||||
* Allows clients to update individual API configuration fields without
|
||||
* overwriting the entire configuration. Only fields specified in the update_mask
|
||||
* are updated from api_configuration.
|
||||
*
|
||||
* @param controller The controller instance
|
||||
* @param request The partial update API configuration request with FieldMask
|
||||
* @returns Empty response
|
||||
*/
|
||||
export async function updateApiConfigurationPartial(
|
||||
controller: Controller,
|
||||
request: UpdateApiConfigurationPartialRequest,
|
||||
): Promise<Empty> {
|
||||
try {
|
||||
// Validate request
|
||||
if (!request.updateMask || request.updateMask.length === 0) {
|
||||
throw new Error("update_mask is required and must contain at least one field")
|
||||
}
|
||||
|
||||
if (!request.apiConfiguration) {
|
||||
throw new Error("api_configuration is required")
|
||||
}
|
||||
|
||||
// Get current config and convert new values from proto format
|
||||
const currentConfig = controller.stateManager.getApiConfiguration()
|
||||
const newConfigValues = convertProtoToApiConfiguration(request.apiConfiguration)
|
||||
|
||||
// Apply only the fields specified in the mask
|
||||
const updatedConfig = { ...currentConfig }
|
||||
for (const field of request.updateMask) {
|
||||
;(updatedConfig as Record<string, any>)[field] = (newConfigValues as Record<string, any>)[field]
|
||||
}
|
||||
|
||||
// Update storage and task API handler
|
||||
controller.stateManager.setApiConfiguration(updatedConfig)
|
||||
if (controller.task) {
|
||||
const currentMode = controller.stateManager.getGlobalSettingsKey("mode")
|
||||
controller.task.api = buildApiHandler({ ...updatedConfig, ulid: controller.task.ulid }, currentMode)
|
||||
}
|
||||
|
||||
// Notify webview
|
||||
await controller.postStateToWebview()
|
||||
|
||||
return Empty.create()
|
||||
} catch (error) {
|
||||
console.error(`Failed to update API configuration (partial): ${error}`)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user