mirror of
https://github.com/openai/codex.git
synced 2026-11-20 22:40:37 +00:00
Add model provider configuration writes to the app-server (#58876)
## What changed Add `modelProvider/config/write` to create custom gateways and patch existing custom gateway, Bedrock, and GCP settings. Return the saved provider using the same safe summary as `modelProvider/list`. Omitted fields retain their values; explicit `null` clears nullable user overrides. Apply patches through the shared configuration queue with last-write-wins semantics, enforce field editability and validation, and preserve unexposed authentication settings. Saving leaves provider selection and authentication unchanged. Saving the provider used by `model/list` invalidates its catalog for the next access. Include documentation and generated JSON, TypeScript, and Python protocol types. ## Testing Add coverage for gateway creation and ID allocation, patch and null semantics, configuration policy enforcement, authentication preservation, and catalog refresh after active-provider edits. Extend Python protocol tests to verify wire round trips and reject mismatched provider IDs or fields. GitOrigin-RevId: 850fe2c48ef5274944400efb5a859d720179c923
This commit is contained in:
@@ -220,6 +220,13 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"BedrockProviderId": {
|
||||
"enum": [
|
||||
"amazon-bedrock",
|
||||
"amazon-bedrock-runtime"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"ByteRange": {
|
||||
"properties": {
|
||||
"end": {
|
||||
@@ -1671,6 +1678,12 @@
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"GcpProviderId": {
|
||||
"enum": [
|
||||
"gcp"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"GetAccountParams": {
|
||||
"properties": {
|
||||
"refreshToken": {
|
||||
@@ -2445,6 +2458,18 @@
|
||||
"ModelProviderCapabilitiesReadParams": {
|
||||
"type": "object"
|
||||
},
|
||||
"ModelProviderConfigWriteParams": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"settings": {
|
||||
"$ref": "#/definitions/ProviderSettingsPatch"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"settings"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ModelProviderListParams": {
|
||||
"type": "object"
|
||||
},
|
||||
@@ -2883,6 +2908,124 @@
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"ProviderSettingsPatch": {
|
||||
"description": "Omitted patch fields preserve their values. Explicit null clears a nullable field.",
|
||||
"oneOf": [
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"baseUrl": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"envKey": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"providerId": {
|
||||
"description": "Omit or pass null to allocate a new custom provider ID.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"customGateway"
|
||||
],
|
||||
"title": "CustomGatewayProviderSettingsPatchType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "CustomGatewayProviderSettingsPatch",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"description": "AWS configuration fields for built-in Bedrock providers.",
|
||||
"properties": {
|
||||
"profile": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"providerId": {
|
||||
"$ref": "#/definitions/BedrockProviderId"
|
||||
},
|
||||
"region": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"bedrock"
|
||||
],
|
||||
"title": "BedrockProviderSettingsPatchType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"providerId",
|
||||
"type"
|
||||
],
|
||||
"title": "BedrockProviderSettingsPatch",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"description": "GCP configuration fields. Credential-file paths refer to the app-server host.",
|
||||
"properties": {
|
||||
"credentialFile": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"location": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"projectId": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"providerId": {
|
||||
"$ref": "#/definitions/GcpProviderId"
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"gcp"
|
||||
],
|
||||
"title": "GcpProviderSettingsPatchType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"providerId",
|
||||
"type"
|
||||
],
|
||||
"title": "GcpProviderSettingsPatch",
|
||||
"type": "object"
|
||||
}
|
||||
]
|
||||
},
|
||||
"RealtimeConversationVersion": {
|
||||
"enum": [
|
||||
"v1",
|
||||
@@ -8088,6 +8231,30 @@
|
||||
"title": "ModelProvider/listRequest",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"id": {
|
||||
"$ref": "#/definitions/RequestId"
|
||||
},
|
||||
"method": {
|
||||
"enum": [
|
||||
"modelProvider/config/write"
|
||||
],
|
||||
"title": "ModelProvider/config/writeRequestMethod",
|
||||
"type": "string"
|
||||
},
|
||||
"params": {
|
||||
"$ref": "#/definitions/ModelProviderConfigWriteParams"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"title": "ModelProvider/config/writeRequest",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"id": {
|
||||
|
||||
+182
@@ -1930,6 +1930,30 @@
|
||||
"title": "ModelProvider/listRequest",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"id": {
|
||||
"$ref": "#/definitions/v2/RequestId"
|
||||
},
|
||||
"method": {
|
||||
"enum": [
|
||||
"modelProvider/config/write"
|
||||
],
|
||||
"title": "ModelProvider/config/writeRequestMethod",
|
||||
"type": "string"
|
||||
},
|
||||
"params": {
|
||||
"$ref": "#/definitions/v2/ModelProviderConfigWriteParams"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"title": "ModelProvider/config/writeRequest",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"id": {
|
||||
@@ -8422,6 +8446,13 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"BedrockProviderId": {
|
||||
"enum": [
|
||||
"amazon-bedrock",
|
||||
"amazon-bedrock-runtime"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"BrowserUseAccessApprovalLifetime": {
|
||||
"enum": [
|
||||
"turn",
|
||||
@@ -13189,6 +13220,12 @@
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"GcpProviderId": {
|
||||
"enum": [
|
||||
"gcp"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"GetAccountParams": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"properties": {
|
||||
@@ -16254,6 +16291,33 @@
|
||||
"title": "ModelProviderCapabilitiesReadResponse",
|
||||
"type": "object"
|
||||
},
|
||||
"ModelProviderConfigWriteParams": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"settings": {
|
||||
"$ref": "#/definitions/v2/ProviderSettingsPatch"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"settings"
|
||||
],
|
||||
"title": "ModelProviderConfigWriteParams",
|
||||
"type": "object"
|
||||
},
|
||||
"ModelProviderConfigWriteResponse": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"properties": {
|
||||
"provider": {
|
||||
"$ref": "#/definitions/v2/ModelProviderSummary"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"provider"
|
||||
],
|
||||
"title": "ModelProviderConfigWriteResponse",
|
||||
"type": "object"
|
||||
},
|
||||
"ModelProviderError": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"description": "Structured JSON-RPC error data. Unknown errors must retain the client's normal fallback.",
|
||||
@@ -18949,6 +19013,124 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"ProviderSettingsPatch": {
|
||||
"description": "Omitted patch fields preserve their values. Explicit null clears a nullable field.",
|
||||
"oneOf": [
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"baseUrl": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"envKey": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"providerId": {
|
||||
"description": "Omit or pass null to allocate a new custom provider ID.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"customGateway"
|
||||
],
|
||||
"title": "CustomGatewayProviderSettingsPatchType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "CustomGatewayProviderSettingsPatch",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"description": "AWS configuration fields for built-in Bedrock providers.",
|
||||
"properties": {
|
||||
"profile": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"providerId": {
|
||||
"$ref": "#/definitions/v2/BedrockProviderId"
|
||||
},
|
||||
"region": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"bedrock"
|
||||
],
|
||||
"title": "BedrockProviderSettingsPatchType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"providerId",
|
||||
"type"
|
||||
],
|
||||
"title": "BedrockProviderSettingsPatch",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"description": "GCP configuration fields. Credential-file paths refer to the app-server host.",
|
||||
"properties": {
|
||||
"credentialFile": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"location": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"projectId": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"providerId": {
|
||||
"$ref": "#/definitions/v2/GcpProviderId"
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"gcp"
|
||||
],
|
||||
"title": "GcpProviderSettingsPatchType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"providerId",
|
||||
"type"
|
||||
],
|
||||
"title": "GcpProviderSettingsPatch",
|
||||
"type": "object"
|
||||
}
|
||||
]
|
||||
},
|
||||
"QueuedSubmission": {
|
||||
"properties": {
|
||||
"clientUserMessageId": {
|
||||
|
||||
+182
@@ -1598,6 +1598,13 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"BedrockProviderId": {
|
||||
"enum": [
|
||||
"amazon-bedrock",
|
||||
"amazon-bedrock-runtime"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"BrowserUseAccessApprovalLifetime": {
|
||||
"enum": [
|
||||
"turn",
|
||||
@@ -3667,6 +3674,30 @@
|
||||
"title": "ModelProvider/listRequest",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"id": {
|
||||
"$ref": "#/definitions/RequestId"
|
||||
},
|
||||
"method": {
|
||||
"enum": [
|
||||
"modelProvider/config/write"
|
||||
],
|
||||
"title": "ModelProvider/config/writeRequestMethod",
|
||||
"type": "string"
|
||||
},
|
||||
"params": {
|
||||
"$ref": "#/definitions/ModelProviderConfigWriteParams"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"title": "ModelProvider/config/writeRequest",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"id": {
|
||||
@@ -9081,6 +9112,12 @@
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"GcpProviderId": {
|
||||
"enum": [
|
||||
"gcp"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"GetAccountParams": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"properties": {
|
||||
@@ -12215,6 +12252,33 @@
|
||||
"title": "ModelProviderCapabilitiesReadResponse",
|
||||
"type": "object"
|
||||
},
|
||||
"ModelProviderConfigWriteParams": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"settings": {
|
||||
"$ref": "#/definitions/ProviderSettingsPatch"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"settings"
|
||||
],
|
||||
"title": "ModelProviderConfigWriteParams",
|
||||
"type": "object"
|
||||
},
|
||||
"ModelProviderConfigWriteResponse": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"properties": {
|
||||
"provider": {
|
||||
"$ref": "#/definitions/ModelProviderSummary"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"provider"
|
||||
],
|
||||
"title": "ModelProviderConfigWriteResponse",
|
||||
"type": "object"
|
||||
},
|
||||
"ModelProviderError": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"description": "Structured JSON-RPC error data. Unknown errors must retain the client's normal fallback.",
|
||||
@@ -14910,6 +14974,124 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"ProviderSettingsPatch": {
|
||||
"description": "Omitted patch fields preserve their values. Explicit null clears a nullable field.",
|
||||
"oneOf": [
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"baseUrl": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"envKey": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"providerId": {
|
||||
"description": "Omit or pass null to allocate a new custom provider ID.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"customGateway"
|
||||
],
|
||||
"title": "CustomGatewayProviderSettingsPatchType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "CustomGatewayProviderSettingsPatch",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"description": "AWS configuration fields for built-in Bedrock providers.",
|
||||
"properties": {
|
||||
"profile": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"providerId": {
|
||||
"$ref": "#/definitions/BedrockProviderId"
|
||||
},
|
||||
"region": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"bedrock"
|
||||
],
|
||||
"title": "BedrockProviderSettingsPatchType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"providerId",
|
||||
"type"
|
||||
],
|
||||
"title": "BedrockProviderSettingsPatch",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"description": "GCP configuration fields. Credential-file paths refer to the app-server host.",
|
||||
"properties": {
|
||||
"credentialFile": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"location": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"projectId": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"providerId": {
|
||||
"$ref": "#/definitions/GcpProviderId"
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"gcp"
|
||||
],
|
||||
"title": "GcpProviderSettingsPatchType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"providerId",
|
||||
"type"
|
||||
],
|
||||
"title": "GcpProviderSettingsPatch",
|
||||
"type": "object"
|
||||
}
|
||||
]
|
||||
},
|
||||
"QueuedSubmission": {
|
||||
"properties": {
|
||||
"clientUserMessageId": {
|
||||
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"additionalProperties": false,
|
||||
"definitions": {
|
||||
"BedrockProviderId": {
|
||||
"enum": [
|
||||
"amazon-bedrock",
|
||||
"amazon-bedrock-runtime"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"GcpProviderId": {
|
||||
"enum": [
|
||||
"gcp"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"ProviderSettingsPatch": {
|
||||
"description": "Omitted patch fields preserve their values. Explicit null clears a nullable field.",
|
||||
"oneOf": [
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"baseUrl": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"envKey": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"providerId": {
|
||||
"description": "Omit or pass null to allocate a new custom provider ID.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"customGateway"
|
||||
],
|
||||
"title": "CustomGatewayProviderSettingsPatchType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "CustomGatewayProviderSettingsPatch",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"description": "AWS configuration fields for built-in Bedrock providers.",
|
||||
"properties": {
|
||||
"profile": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"providerId": {
|
||||
"$ref": "#/definitions/BedrockProviderId"
|
||||
},
|
||||
"region": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"bedrock"
|
||||
],
|
||||
"title": "BedrockProviderSettingsPatchType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"providerId",
|
||||
"type"
|
||||
],
|
||||
"title": "BedrockProviderSettingsPatch",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"description": "GCP configuration fields. Credential-file paths refer to the app-server host.",
|
||||
"properties": {
|
||||
"credentialFile": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"location": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"projectId": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"providerId": {
|
||||
"$ref": "#/definitions/GcpProviderId"
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"gcp"
|
||||
],
|
||||
"title": "GcpProviderSettingsPatchType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"providerId",
|
||||
"type"
|
||||
],
|
||||
"title": "GcpProviderSettingsPatch",
|
||||
"type": "object"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"settings": {
|
||||
"$ref": "#/definitions/ProviderSettingsPatch"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"settings"
|
||||
],
|
||||
"title": "ModelProviderConfigWriteParams",
|
||||
"type": "object"
|
||||
}
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"definitions": {
|
||||
"GatewayAuth": {
|
||||
"oneOf": [
|
||||
{
|
||||
"properties": {
|
||||
"mode": {
|
||||
"enum": [
|
||||
"none"
|
||||
],
|
||||
"title": "NoneGatewayAuthMode",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"mode"
|
||||
],
|
||||
"title": "NoneGatewayAuth",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"envKey": {
|
||||
"type": "string"
|
||||
},
|
||||
"mode": {
|
||||
"enum": [
|
||||
"environmentVariable"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"envKey",
|
||||
"mode"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"description": "Authentication is configured outside the gateway form. Preserve it on edits.",
|
||||
"properties": {
|
||||
"envKey": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"mode": {
|
||||
"enum": [
|
||||
"externallyConfigured"
|
||||
],
|
||||
"title": "ModeGatewayAuthMode",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"mode"
|
||||
],
|
||||
"title": "ModeGatewayAuth",
|
||||
"type": "object"
|
||||
}
|
||||
]
|
||||
},
|
||||
"ModelProviderSummary": {
|
||||
"properties": {
|
||||
"baseUrl": {
|
||||
"description": "Null when the endpoint is absent or cannot be safely displayed.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"canEdit": {
|
||||
"description": "Whether a supported configuration field can be edited in the active user layer.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"settings": {
|
||||
"$ref": "#/definitions/ProviderSettings"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"canEdit",
|
||||
"id",
|
||||
"name",
|
||||
"settings"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ProviderSettings": {
|
||||
"oneOf": [
|
||||
{
|
||||
"properties": {
|
||||
"type": {
|
||||
"enum": [
|
||||
"openai"
|
||||
],
|
||||
"title": "OpenaiProviderSettingsType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "OpenaiProviderSettings",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"auth": {
|
||||
"$ref": "#/definitions/GatewayAuth"
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"customGateway"
|
||||
],
|
||||
"title": "CustomGatewayProviderSettingsType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"auth",
|
||||
"type"
|
||||
],
|
||||
"title": "CustomGatewayProviderSettings",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"profile": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"region": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"bedrock"
|
||||
],
|
||||
"title": "BedrockProviderSettingsType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "BedrockProviderSettings",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"credentialFile": {
|
||||
"description": "Path on the app-server host, without credential-file contents.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"location": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"projectId": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"gcp"
|
||||
],
|
||||
"title": "GcpProviderSettingsType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "GcpProviderSettings",
|
||||
"type": "object"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"provider": {
|
||||
"$ref": "#/definitions/ModelProviderSummary"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"provider"
|
||||
],
|
||||
"title": "ModelProviderConfigWriteResponse",
|
||||
"type": "object"
|
||||
}
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
File diff suppressed because one or more lines are too long
@@ -0,0 +1,5 @@
|
||||
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type BedrockProviderId = "amazon-bedrock" | "amazon-bedrock-runtime";
|
||||
@@ -0,0 +1,9 @@
|
||||
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { BedrockProviderId } from "./BedrockProviderId";
|
||||
|
||||
/**
|
||||
* AWS configuration fields for built-in Bedrock providers.
|
||||
*/
|
||||
export type BedrockSettingsParams = { providerId: BedrockProviderId, profile?: string | null, region?: string | null, };
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type CustomGatewaySettingsParams = {
|
||||
/**
|
||||
* Omit or pass null to allocate a new custom provider ID.
|
||||
*/
|
||||
providerId?: string | null, name?: string, baseUrl?: string | null, envKey?: string | null, };
|
||||
@@ -0,0 +1,5 @@
|
||||
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type GcpProviderId = "gcp";
|
||||
@@ -0,0 +1,9 @@
|
||||
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { GcpProviderId } from "./GcpProviderId";
|
||||
|
||||
/**
|
||||
* GCP configuration fields. Credential-file paths refer to the app-server host.
|
||||
*/
|
||||
export type GcpSettingsParams = { providerId: GcpProviderId, projectId?: string | null, location?: string | null, credentialFile?: string | null, };
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { ProviderSettingsPatch } from "./ProviderSettingsPatch";
|
||||
|
||||
export type ModelProviderConfigWriteParams = { settings: ProviderSettingsPatch, };
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { ModelProviderSummary } from "./ModelProviderSummary";
|
||||
|
||||
export type ModelProviderConfigWriteResponse = { provider: ModelProviderSummary, };
|
||||
@@ -0,0 +1,11 @@
|
||||
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { BedrockSettingsParams } from "./BedrockSettingsParams";
|
||||
import type { CustomGatewaySettingsParams } from "./CustomGatewaySettingsParams";
|
||||
import type { GcpSettingsParams } from "./GcpSettingsParams";
|
||||
|
||||
/**
|
||||
* Omitted patch fields preserve their values. Explicit null clears a nullable field.
|
||||
*/
|
||||
export type ProviderSettingsPatch = { "type": "customGateway" } & CustomGatewaySettingsParams | { "type": "bedrock" } & BedrockSettingsParams | { "type": "gcp" } & GcpSettingsParams;
|
||||
@@ -54,6 +54,8 @@ export type { AttestationGenerateResponse } from "./AttestationGenerateResponse"
|
||||
export type { AuthRecoveryNotification } from "./AuthRecoveryNotification";
|
||||
export type { AutoReviewDecisionSource } from "./AutoReviewDecisionSource";
|
||||
export type { AutoReviewRequirements } from "./AutoReviewRequirements";
|
||||
export type { BedrockProviderId } from "./BedrockProviderId";
|
||||
export type { BedrockSettingsParams } from "./BedrockSettingsParams";
|
||||
export type { BrowserUseAccessApprovalLifetime } from "./BrowserUseAccessApprovalLifetime";
|
||||
export type { BrowserUseConfig } from "./BrowserUseConfig";
|
||||
export type { BrowserUseExtensionRequirements } from "./BrowserUseExtensionRequirements";
|
||||
@@ -124,6 +126,7 @@ export type { ConsumeAccountRateLimitResetCreditParams } from "./ConsumeAccountR
|
||||
export type { ConsumeAccountRateLimitResetCreditResponse } from "./ConsumeAccountRateLimitResetCreditResponse";
|
||||
export type { ContextCompactedNotification } from "./ContextCompactedNotification";
|
||||
export type { CreditsSnapshot } from "./CreditsSnapshot";
|
||||
export type { CustomGatewaySettingsParams } from "./CustomGatewaySettingsParams";
|
||||
export type { CyberAccessProgram } from "./CyberAccessProgram";
|
||||
export type { DeprecationNoticeNotification } from "./DeprecationNoticeNotification";
|
||||
export type { DesktopOnboardingEntrypoint } from "./DesktopOnboardingEntrypoint";
|
||||
@@ -208,6 +211,8 @@ export type { GatewayOAuthChangedNotification } from "./GatewayOAuthChangedNotif
|
||||
export type { GatewayOAuthLoginResponse } from "./GatewayOAuthLoginResponse";
|
||||
export type { GatewayOAuthReadResponse } from "./GatewayOAuthReadResponse";
|
||||
export type { GatewayOAuthStatus } from "./GatewayOAuthStatus";
|
||||
export type { GcpProviderId } from "./GcpProviderId";
|
||||
export type { GcpSettingsParams } from "./GcpSettingsParams";
|
||||
export type { GetAccountParams } from "./GetAccountParams";
|
||||
export type { GetAccountRateLimitsParams } from "./GetAccountRateLimitsParams";
|
||||
export type { GetAccountRateLimitsResponse } from "./GetAccountRateLimitsResponse";
|
||||
@@ -330,6 +335,8 @@ export type { ModelListParams } from "./ModelListParams";
|
||||
export type { ModelListResponse } from "./ModelListResponse";
|
||||
export type { ModelProviderCapabilitiesReadParams } from "./ModelProviderCapabilitiesReadParams";
|
||||
export type { ModelProviderCapabilitiesReadResponse } from "./ModelProviderCapabilitiesReadResponse";
|
||||
export type { ModelProviderConfigWriteParams } from "./ModelProviderConfigWriteParams";
|
||||
export type { ModelProviderConfigWriteResponse } from "./ModelProviderConfigWriteResponse";
|
||||
export type { ModelProviderError } from "./ModelProviderError";
|
||||
export type { ModelProviderListParams } from "./ModelProviderListParams";
|
||||
export type { ModelProviderListResponse } from "./ModelProviderListResponse";
|
||||
@@ -427,6 +434,7 @@ export type { ProjectChangedNotification } from "./ProjectChangedNotification";
|
||||
export type { ProjectRoot } from "./ProjectRoot";
|
||||
export type { ProjectSortKey } from "./ProjectSortKey";
|
||||
export type { ProviderSettings } from "./ProviderSettings";
|
||||
export type { ProviderSettingsPatch } from "./ProviderSettingsPatch";
|
||||
export type { QueuedSubmission } from "./QueuedSubmission";
|
||||
export type { RateLimitReachedType } from "./RateLimitReachedType";
|
||||
export type { RateLimitResetCredit } from "./RateLimitResetCredit";
|
||||
|
||||
@@ -1179,6 +1179,11 @@ client_request_definitions! {
|
||||
serialization: global_shared_read("config"),
|
||||
response: v2::ModelProviderListResponse,
|
||||
},
|
||||
ModelProviderConfigWrite => "modelProvider/config/write" {
|
||||
params: v2::ModelProviderConfigWriteParams,
|
||||
serialization: global("config"),
|
||||
response: v2::ModelProviderConfigWriteResponse,
|
||||
},
|
||||
ModelProviderCapabilitiesRead => "modelProvider/capabilities/read" {
|
||||
params: v2::ModelProviderCapabilitiesReadParams,
|
||||
serialization: None,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Model provider discovery and the configuration fields visible to clients.
|
||||
//! Safe provider discovery and field patches for custom, AWS, and GCP configuration.
|
||||
|
||||
use crate::JsonSchema;
|
||||
use crate::TS;
|
||||
@@ -87,3 +87,164 @@ pub enum GatewayAuth {
|
||||
env_key: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
/// Omitted patch fields preserve their values. Explicit null clears a nullable field.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(tag = "type", rename_all = "camelCase", deny_unknown_fields)]
|
||||
#[ts(tag = "type", rename_all = "camelCase", export_to = "v2/")]
|
||||
pub enum ProviderSettingsPatch {
|
||||
CustomGateway(CustomGatewaySettingsParams),
|
||||
Bedrock(BedrockSettingsParams),
|
||||
Gcp(GcpSettingsParams),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
#[ts(rename_all = "kebab-case", export_to = "v2/")]
|
||||
pub enum BedrockProviderId {
|
||||
AmazonBedrock,
|
||||
AmazonBedrockRuntime,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(rename_all = "camelCase", export_to = "v2/")]
|
||||
pub enum GcpProviderId {
|
||||
Gcp,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct CustomGatewaySettingsParams {
|
||||
/// Omit or pass null to allocate a new custom provider ID.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional = nullable)]
|
||||
pub provider_id: Option<String>,
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "deserialize_patch_name",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
#[schemars(with = "String", skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub name: Option<String>,
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "crate::protocol::serde_helpers::deserialize_double_option",
|
||||
serialize_with = "crate::protocol::serde_helpers::serialize_double_option",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
#[schemars(with = "Option<String>", skip_serializing_if = "Option::is_none")]
|
||||
#[ts(type = "string | null")]
|
||||
#[ts(optional = nullable)]
|
||||
pub base_url: Option<Option<String>>,
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "crate::protocol::serde_helpers::deserialize_double_option",
|
||||
serialize_with = "crate::protocol::serde_helpers::serialize_double_option",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
#[schemars(with = "Option<String>", skip_serializing_if = "Option::is_none")]
|
||||
#[ts(type = "string | null")]
|
||||
#[ts(optional = nullable)]
|
||||
pub env_key: Option<Option<String>>,
|
||||
}
|
||||
|
||||
/// AWS configuration fields for built-in Bedrock providers.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct BedrockSettingsParams {
|
||||
pub provider_id: BedrockProviderId,
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "crate::protocol::serde_helpers::deserialize_double_option",
|
||||
serialize_with = "crate::protocol::serde_helpers::serialize_double_option",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
#[schemars(with = "Option<String>", skip_serializing_if = "Option::is_none")]
|
||||
#[ts(type = "string | null")]
|
||||
#[ts(optional = nullable)]
|
||||
pub profile: Option<Option<String>>,
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "crate::protocol::serde_helpers::deserialize_double_option",
|
||||
serialize_with = "crate::protocol::serde_helpers::serialize_double_option",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
#[schemars(with = "Option<String>", skip_serializing_if = "Option::is_none")]
|
||||
#[ts(type = "string | null")]
|
||||
#[ts(optional = nullable)]
|
||||
pub region: Option<Option<String>>,
|
||||
}
|
||||
|
||||
/// GCP configuration fields. Credential-file paths refer to the app-server host.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct GcpSettingsParams {
|
||||
pub provider_id: GcpProviderId,
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "crate::protocol::serde_helpers::deserialize_double_option",
|
||||
serialize_with = "crate::protocol::serde_helpers::serialize_double_option",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
#[schemars(with = "Option<String>", skip_serializing_if = "Option::is_none")]
|
||||
#[ts(type = "string | null")]
|
||||
#[ts(optional = nullable)]
|
||||
pub project_id: Option<Option<String>>,
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "crate::protocol::serde_helpers::deserialize_double_option",
|
||||
serialize_with = "crate::protocol::serde_helpers::serialize_double_option",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
#[schemars(with = "Option<String>", skip_serializing_if = "Option::is_none")]
|
||||
#[ts(type = "string | null")]
|
||||
#[ts(optional = nullable)]
|
||||
pub location: Option<Option<String>>,
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "crate::protocol::serde_helpers::deserialize_double_option",
|
||||
serialize_with = "crate::protocol::serde_helpers::serialize_double_option",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
#[schemars(with = "Option<String>", skip_serializing_if = "Option::is_none")]
|
||||
#[ts(type = "string | null")]
|
||||
#[ts(optional = nullable)]
|
||||
pub credential_file: Option<Option<String>>,
|
||||
}
|
||||
|
||||
// A missing name preserves it, but an explicitly supplied name must be a string.
|
||||
fn deserialize_patch_name<'de, D: serde::Deserializer<'de>>(
|
||||
deserializer: D,
|
||||
) -> Result<Option<String>, D::Error> {
|
||||
String::deserialize(deserializer).map(Some)
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for CustomGatewaySettingsParams {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("CustomGatewaySettingsParams")
|
||||
.field("name", &self.name)
|
||||
.field("base_url", &"[REDACTED]")
|
||||
.field("env_key", &self.env_key)
|
||||
.field("provider_id", &self.provider_id)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct ModelProviderConfigWriteParams {
|
||||
pub settings: ProviderSettingsPatch,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct ModelProviderConfigWriteResponse {
|
||||
pub provider: ModelProviderSummary,
|
||||
}
|
||||
|
||||
@@ -646,8 +646,8 @@ Status notifications include `providerId`. During browser sign-in, inference
|
||||
requests fail promptly and can be retried when sign-in succeeds.
|
||||
|
||||
`model/list` also checks gateway authentication before returning cached models.
|
||||
If authentication fails after the provider configuration changes, it asks the client
|
||||
to restart Codex so the retained catalog and gateway sign-in use the same provider.
|
||||
If authentication fails and the catalog's provider differs from the current configuration,
|
||||
it asks the client to restart Codex so the catalog and gateway sign-in use the same provider.
|
||||
|
||||
## Application network policy
|
||||
|
||||
@@ -763,6 +763,67 @@ whether a setup flow that also selects a default provider will succeed.
|
||||
`account/bedrock/setup` targets `amazon-bedrock`; edits to `amazon-bedrock-runtime`
|
||||
must use that provider's configuration paths instead.
|
||||
|
||||
Use `modelProvider/config/write` with a tagged `settings` patch. To create a
|
||||
custom gateway, send `type: "customGateway"`, `name`, and `baseUrl`. Omit
|
||||
`providerId` or pass null to allocate an ID. To edit an existing gateway,
|
||||
include its ID inside `settings`.
|
||||
|
||||
```json
|
||||
{
|
||||
"settings": {
|
||||
"type": "customGateway",
|
||||
"providerId": "team",
|
||||
"name": "New name",
|
||||
"envKey": null
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The Bedrock branch requires `amazon-bedrock` or `amazon-bedrock-runtime` and
|
||||
accepts `profile` and `region`. This patch changes only the runtime region.
|
||||
|
||||
```json
|
||||
{
|
||||
"settings": {
|
||||
"type": "bedrock",
|
||||
"providerId": "amazon-bedrock-runtime",
|
||||
"region": "us-east-1"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The GCP branch requires `gcp` and accepts `projectId`, `location`, and
|
||||
`credentialFile`. This patch clears the credential-file override.
|
||||
|
||||
```json
|
||||
{ "settings": { "type": "gcp", "providerId": "gcp", "credentialFile": null } }
|
||||
```
|
||||
|
||||
Omitted patch fields preserve their values. Setting a nullable field such as
|
||||
`region` to `null` removes its user-level override, so any inherited value takes effect.
|
||||
A supplied name must be a string. A supported built-in can receive its first
|
||||
override even when absent from the list. Custom gateways can share a display
|
||||
name with a built-in, except for names that select built-in behavior
|
||||
(`OpenAI`, `Amazon Bedrock`, `Amazon Bedrock Runtime`, and `Google Cloud Vertex AI`).
|
||||
Built-in provider IDs remain reserved.
|
||||
|
||||
Send only edited configuration fields. A null `baseUrl` in a summary can mean
|
||||
that the endpoint was redacted. When `settings.auth.mode` is `externallyConfigured`,
|
||||
including for an endpoint with embedded credentials, writes to `envKey` are rejected. Other edits preserve unexposed authentication,
|
||||
headers, query parameters, and commands, including when changing the endpoint.
|
||||
Each supplied field must be writable. A new user-layer custom override retains the
|
||||
inherited name because custom provider tables require a name.
|
||||
|
||||
The response is `{ "provider": ModelProviderSummary }`, using the same safe summary
|
||||
as list. There are no public version tokens. Provider, value, and batch writes in
|
||||
one app-server share the config queue: the last write to a field wins while omitted
|
||||
siblings are preserved. Patches apply without an expected-version check. The
|
||||
response summarizes the saved configuration.
|
||||
|
||||
Saving does not select a default, authenticate, or contact the provider. Use setup
|
||||
RPCs for authentication and selection. Saving the provider used by `model/list`
|
||||
invalidates its catalog for the next access. Existing threads keep their configuration.
|
||||
|
||||
# GCP provider account
|
||||
|
||||
The experimental `account/gcp/setup` method configures the built-in Vertex AI provider.
|
||||
|
||||
@@ -53,6 +53,8 @@ mod credential_edits;
|
||||
mod model_providers;
|
||||
#[path = "config_manager_service_provider_setup.rs"]
|
||||
mod provider_setup;
|
||||
#[path = "config_manager_service_provider_write.rs"]
|
||||
mod provider_write;
|
||||
|
||||
use credential_edits::CredentialProviderEdits;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Lists model providers and the configuration fields visible to clients.
|
||||
//! Projects safe provider summaries and shares field editability policy with provider writes.
|
||||
|
||||
use super::ConfigManager;
|
||||
use super::ConfigManagerError;
|
||||
@@ -10,6 +10,7 @@ use codex_app_server_protocol::ModelProviderSummary;
|
||||
use codex_app_server_protocol::ProviderSettings;
|
||||
use codex_config::ConfigLayerEntry;
|
||||
use codex_config::ConfigLayerStack;
|
||||
use codex_config::LoaderOverrides;
|
||||
use codex_model_provider_info::AMAZON_BEDROCK_PROVIDER_ID;
|
||||
use codex_model_provider_info::AMAZON_BEDROCK_PROVIDER_NAME;
|
||||
use codex_model_provider_info::AMAZON_BEDROCK_RUNTIME_PROVIDER_ID;
|
||||
@@ -17,19 +18,28 @@ use codex_model_provider_info::AMAZON_BEDROCK_RUNTIME_PROVIDER_NAME;
|
||||
use codex_model_provider_info::GCP_PROVIDER_ID;
|
||||
use codex_model_provider_info::GCP_PROVIDER_NAME;
|
||||
use codex_model_provider_info::LMSTUDIO_OSS_PROVIDER_ID;
|
||||
use codex_model_provider_info::ModelProviderInfo;
|
||||
use codex_model_provider_info::OLLAMA_OSS_PROVIDER_ID;
|
||||
use codex_model_provider_info::OPENAI_PROVIDER_ID;
|
||||
use codex_model_provider_info::OPENAI_PROVIDER_NAME;
|
||||
use codex_model_provider_info::built_in_model_providers;
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
fn string_field(config: Option<&TomlValue>, key: &str) -> Option<String> {
|
||||
config?.get(key)?.as_str().map(str::to_owned)
|
||||
}
|
||||
|
||||
fn has_external_auth(config: &TomlValue) -> bool {
|
||||
["auth", "gateway_oauth", "aws", "experimental_bearer_token"]
|
||||
.iter()
|
||||
.any(|key| config.get(key).is_some())
|
||||
pub(super) fn has_external_auth(config: &TomlValue) -> bool {
|
||||
config
|
||||
.get("base_url")
|
||||
.and_then(TomlValue::as_str)
|
||||
.and_then(|value| url::Url::parse(value).ok())
|
||||
.is_some_and(|url| {
|
||||
!url.username().is_empty() || url.password().is_some() || url.query().is_some()
|
||||
})
|
||||
|| ["auth", "gateway_oauth", "aws", "experimental_bearer_token"]
|
||||
.iter()
|
||||
.any(|key| config.get(key).is_some())
|
||||
|| config
|
||||
.get("requires_openai_auth")
|
||||
.and_then(TomlValue::as_bool)
|
||||
@@ -40,6 +50,17 @@ fn has_external_auth(config: &TomlValue) -> bool {
|
||||
.any(|headers| !headers.is_empty())
|
||||
}
|
||||
|
||||
pub(super) fn valid_endpoint(value: &str) -> bool {
|
||||
url::Url::parse(value).is_ok_and(|url| {
|
||||
matches!(url.scheme(), "http" | "https")
|
||||
&& url.has_host()
|
||||
&& url.username().is_empty()
|
||||
&& url.password().is_none()
|
||||
&& url.query().is_none()
|
||||
&& url.fragment().is_none()
|
||||
})
|
||||
}
|
||||
|
||||
impl ConfigManager {
|
||||
pub(crate) async fn model_provider_list(
|
||||
&self,
|
||||
@@ -50,9 +71,8 @@ impl ConfigManager {
|
||||
.await
|
||||
.map_err(|e| ConfigManagerError::io("failed to read providers", e))?;
|
||||
let effective = layers.effective_config();
|
||||
let user_layer = layers.get_active_user_layer();
|
||||
let writable_user_layer = user_layer
|
||||
.filter(|user| !user.is_disabled() && !self.loader_overrides().ignore_user_config);
|
||||
let builtins = built_in_model_providers(/*openai_base_url*/ None);
|
||||
let writable_user_layer = writable_user_layer(&layers, self.loader_overrides());
|
||||
let configured = effective
|
||||
.get("model_providers")
|
||||
.and_then(TomlValue::as_table);
|
||||
@@ -81,6 +101,7 @@ impl ConfigManager {
|
||||
summarize_provider(
|
||||
id,
|
||||
configured.and_then(|table| table.get(id)),
|
||||
builtins.get(id),
|
||||
&effective,
|
||||
&layers,
|
||||
writable_user_layer,
|
||||
@@ -95,47 +116,30 @@ impl ConfigManager {
|
||||
}
|
||||
}
|
||||
|
||||
fn summarize_provider(
|
||||
pub(super) fn summarize_provider(
|
||||
id: &str,
|
||||
config: Option<&TomlValue>,
|
||||
builtin: Option<&ModelProviderInfo>,
|
||||
effective: &TomlValue,
|
||||
layers: &ConfigLayerStack,
|
||||
writable_user_layer: Option<&ConfigLayerEntry>,
|
||||
) -> ModelProviderSummary {
|
||||
let display_name = match id {
|
||||
AMAZON_BEDROCK_PROVIDER_ID => "Amazon Bedrock Mantle",
|
||||
AMAZON_BEDROCK_RUNTIME_PROVIDER_ID => "Amazon Bedrock Runtime",
|
||||
GCP_PROVIDER_ID => GCP_PROVIDER_NAME,
|
||||
OPENAI_PROVIDER_ID => OPENAI_PROVIDER_NAME,
|
||||
_ => config.and_then(|c| c.get("name")?.as_str()).unwrap_or(id),
|
||||
let display_name = match builtin {
|
||||
Some(_) if id == AMAZON_BEDROCK_PROVIDER_ID => "Amazon Bedrock Mantle",
|
||||
Some(provider) => &provider.name,
|
||||
None => config.and_then(|c| c.get("name")?.as_str()).unwrap_or(id),
|
||||
};
|
||||
let builtin_auth = matches!(
|
||||
display_name,
|
||||
OPENAI_PROVIDER_NAME
|
||||
| AMAZON_BEDROCK_PROVIDER_NAME
|
||||
| AMAZON_BEDROCK_RUNTIME_PROVIDER_NAME
|
||||
| GCP_PROVIDER_NAME
|
||||
);
|
||||
let builtin_auth = uses_builtin_auth(display_name);
|
||||
let requires_rename = builtin.is_none() && (display_name.trim().is_empty() || builtin_auth);
|
||||
let external_auth = builtin_auth || config.is_some_and(has_external_auth);
|
||||
let base_url = if id == OPENAI_PROVIDER_ID {
|
||||
effective.get("openai_base_url")
|
||||
} else {
|
||||
config.and_then(|config| config.get("base_url"))
|
||||
}
|
||||
.and_then(TomlValue::as_str);
|
||||
let parsed_url = base_url.and_then(|value| url::Url::parse(value).ok());
|
||||
let url_has_auth = parsed_url.as_ref().is_some_and(|url| {
|
||||
!url.username().is_empty() || url.password().is_some() || url.query().is_some()
|
||||
});
|
||||
let base_url = base_url
|
||||
.filter(|_| {
|
||||
parsed_url.as_ref().is_some_and(|url| {
|
||||
matches!(url.scheme(), "http" | "https")
|
||||
&& url.has_host()
|
||||
&& !url_has_auth
|
||||
&& url.fragment().is_none()
|
||||
})
|
||||
})
|
||||
.map(str::to_owned);
|
||||
.and_then(TomlValue::as_str)
|
||||
.filter(|url| valid_endpoint(url))
|
||||
.map(str::to_owned);
|
||||
let settings = match id {
|
||||
OPENAI_PROVIDER_ID => ProviderSettings::OpenAi,
|
||||
AMAZON_BEDROCK_PROVIDER_ID | AMAZON_BEDROCK_RUNTIME_PROVIDER_ID => {
|
||||
@@ -152,7 +156,7 @@ fn summarize_provider(
|
||||
},
|
||||
_ => {
|
||||
let env_key = string_field(config, "env_key");
|
||||
let auth = if builtin_auth || url_has_auth || config.is_some_and(has_external_auth) {
|
||||
let auth = if external_auth {
|
||||
GatewayAuth::ExternallyConfigured { env_key }
|
||||
} else if let Some(env_key) = env_key {
|
||||
GatewayAuth::EnvironmentVariable { env_key }
|
||||
@@ -162,14 +166,11 @@ fn summarize_provider(
|
||||
ProviderSettings::CustomGateway { auth }
|
||||
}
|
||||
};
|
||||
let can_edit = can_edit_provider(
|
||||
id,
|
||||
config,
|
||||
&settings,
|
||||
display_name.trim().is_empty() || builtin_auth,
|
||||
layers,
|
||||
writable_user_layer,
|
||||
);
|
||||
let can_edit = supported_fields(id, config, builtin).iter().any(|&field| {
|
||||
(field == "name" || !requires_rename)
|
||||
&& (field != "env_key" || !external_auth)
|
||||
&& field_is_writable(layers, writable_user_layer, id, field)
|
||||
});
|
||||
ModelProviderSummary {
|
||||
id: id.to_owned(),
|
||||
name: display_name.to_owned(),
|
||||
@@ -179,13 +180,52 @@ fn summarize_provider(
|
||||
}
|
||||
}
|
||||
|
||||
fn can_edit_provider(
|
||||
pub(super) fn uses_builtin_auth(name: &str) -> bool {
|
||||
matches!(
|
||||
name,
|
||||
OPENAI_PROVIDER_NAME
|
||||
| AMAZON_BEDROCK_PROVIDER_NAME
|
||||
| AMAZON_BEDROCK_RUNTIME_PROVIDER_NAME
|
||||
| GCP_PROVIDER_NAME
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn writable_user_layer<'a>(
|
||||
layers: &'a ConfigLayerStack,
|
||||
overrides: &LoaderOverrides,
|
||||
) -> Option<&'a ConfigLayerEntry> {
|
||||
layers
|
||||
.get_active_user_layer()
|
||||
.filter(|user| !user.is_disabled() && !overrides.ignore_user_config)
|
||||
}
|
||||
|
||||
pub(super) fn supported_fields(
|
||||
id: &str,
|
||||
config: Option<&TomlValue>,
|
||||
settings: &ProviderSettings,
|
||||
requires_rename: bool,
|
||||
builtin: Option<&ModelProviderInfo>,
|
||||
) -> &'static [&'static str] {
|
||||
let aws_config = config.and_then(|config| config.get("aws"));
|
||||
match (builtin, id) {
|
||||
(Some(_), AMAZON_BEDROCK_PROVIDER_ID | AMAZON_BEDROCK_RUNTIME_PROVIDER_ID) => {
|
||||
if config.is_some_and(|config| config.get("auth").is_some()) {
|
||||
&[]
|
||||
} else if aws_config.is_some_and(|aws| aws.get("credential_export").is_some()) {
|
||||
&["aws.region"]
|
||||
} else {
|
||||
&["aws.profile", "aws.region"]
|
||||
}
|
||||
}
|
||||
(Some(_), GCP_PROVIDER_ID) => &["project_id", "location", "credential_file"],
|
||||
(Some(_), _) => &[],
|
||||
(None, _) => &["name", "base_url", "env_key"],
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn field_is_writable(
|
||||
layers: &ConfigLayerStack,
|
||||
writable_user_layer: Option<&ConfigLayerEntry>,
|
||||
id: &str,
|
||||
field: &str,
|
||||
) -> bool {
|
||||
let Some(user) = writable_user_layer else {
|
||||
return false;
|
||||
@@ -200,41 +240,17 @@ fn can_edit_provider(
|
||||
return false;
|
||||
}
|
||||
|
||||
let fields: &[&str] = match settings {
|
||||
ProviderSettings::Bedrock { .. } => {
|
||||
if config.is_some_and(|config| config.get("auth").is_some()) {
|
||||
&[]
|
||||
} else if config
|
||||
.and_then(|config| config.get("aws"))
|
||||
.is_some_and(|aws| aws.get("credential_export").is_some())
|
||||
{
|
||||
&["aws.region"]
|
||||
} else {
|
||||
&["aws.profile", "aws.region"]
|
||||
}
|
||||
}
|
||||
ProviderSettings::Gcp { .. } => &["project_id", "location", "credential_file"],
|
||||
ProviderSettings::OpenAi => &[],
|
||||
ProviderSettings::CustomGateway { .. } if requires_rename => &["name"],
|
||||
ProviderSettings::CustomGateway {
|
||||
auth: GatewayAuth::ExternallyConfigured { .. },
|
||||
} => &["name", "base_url"],
|
||||
ProviderSettings::CustomGateway { .. } => &["name", "base_url", "env_key"],
|
||||
};
|
||||
|
||||
fields.iter().any(|field| {
|
||||
!layers.layers_high_to_low().any(|layer| {
|
||||
layer.name.precedence() > user.name.precedence()
|
||||
&& layer
|
||||
.config
|
||||
.get("model_providers")
|
||||
.and_then(|providers| providers.get(id))
|
||||
.and_then(|provider| {
|
||||
field
|
||||
.split('.')
|
||||
.try_fold(provider, |value, key| value.get(key))
|
||||
})
|
||||
.is_some()
|
||||
})
|
||||
!layers.layers_high_to_low().any(|layer| {
|
||||
layer.name.precedence() > user.name.precedence()
|
||||
&& layer
|
||||
.config
|
||||
.get("model_providers")
|
||||
.and_then(|providers| providers.get(id))
|
||||
.and_then(|provider| {
|
||||
field
|
||||
.split('.')
|
||||
.try_fold(provider, |value, key| value.get(key))
|
||||
})
|
||||
.is_some()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,291 @@
|
||||
//! Applies provider field patches without selecting a provider or changing hidden credentials.
|
||||
//! RPC writes share the config queue and apply field patches with last-write-wins semantics.
|
||||
|
||||
use super::ApiConfigEdit;
|
||||
use super::ConfigManager;
|
||||
use super::ConfigManagerError;
|
||||
use super::MergeStrategy;
|
||||
use super::TomlValue;
|
||||
use super::model_providers::field_is_writable;
|
||||
use super::model_providers::has_external_auth;
|
||||
use super::model_providers::summarize_provider;
|
||||
use super::model_providers::supported_fields;
|
||||
use super::model_providers::uses_builtin_auth;
|
||||
use super::model_providers::valid_endpoint;
|
||||
use super::model_providers::writable_user_layer;
|
||||
use codex_app_server_protocol::BedrockProviderId;
|
||||
use codex_app_server_protocol::ConfigBatchWriteParams;
|
||||
use codex_app_server_protocol::ConfigWriteErrorCode;
|
||||
use codex_app_server_protocol::CustomGatewaySettingsParams;
|
||||
use codex_app_server_protocol::GcpProviderId;
|
||||
use codex_app_server_protocol::ModelProviderConfigWriteParams;
|
||||
use codex_app_server_protocol::ModelProviderConfigWriteResponse;
|
||||
use codex_app_server_protocol::ProviderSettingsPatch;
|
||||
use codex_config::ConfigLayerStack;
|
||||
use codex_config::LoaderOverrides;
|
||||
use codex_model_provider_info::AMAZON_BEDROCK_PROVIDER_ID;
|
||||
use codex_model_provider_info::AMAZON_BEDROCK_RUNTIME_PROVIDER_ID;
|
||||
use codex_model_provider_info::GCP_PROVIDER_ID;
|
||||
use codex_model_provider_info::LEGACY_OLLAMA_CHAT_PROVIDER_ID;
|
||||
use codex_model_provider_info::ModelProviderInfo;
|
||||
use codex_model_provider_info::built_in_model_providers;
|
||||
use std::collections::HashMap;
|
||||
|
||||
impl ConfigManager {
|
||||
pub(crate) async fn model_provider_config_write(
|
||||
&self,
|
||||
params: ModelProviderConfigWriteParams,
|
||||
) -> Result<ModelProviderConfigWriteResponse, ConfigManagerError> {
|
||||
let layers = self
|
||||
.load_thread_agnostic_config()
|
||||
.await
|
||||
.map_err(|err| ConfigManagerError::io("failed to read providers", err))?;
|
||||
let builtins = built_in_model_providers(/*openai_base_url*/ None);
|
||||
let (provider_id, edits) =
|
||||
provider_edits(¶ms, &layers, self.loader_overrides(), &builtins)?;
|
||||
let response = self
|
||||
.batch_write(ConfigBatchWriteParams {
|
||||
edits,
|
||||
file_path: None,
|
||||
expected_version: None,
|
||||
reload_user_config: false,
|
||||
})
|
||||
.await?;
|
||||
if let Some(overridden) = response.overridden_metadata {
|
||||
return Err(ConfigManagerError::write(
|
||||
ConfigWriteErrorCode::ConfigLayerReadonly,
|
||||
overridden.message,
|
||||
));
|
||||
}
|
||||
let saved = self
|
||||
.load_thread_agnostic_config()
|
||||
.await
|
||||
.map_err(|err| ConfigManagerError::io("failed to read saved provider", err))?;
|
||||
let effective = saved.effective_config();
|
||||
let provider = summarize_provider(
|
||||
&provider_id,
|
||||
effective
|
||||
.get("model_providers")
|
||||
.and_then(|providers| providers.get(&provider_id)),
|
||||
builtins.get(&provider_id),
|
||||
&effective,
|
||||
&saved,
|
||||
writable_user_layer(&saved, self.loader_overrides()),
|
||||
);
|
||||
Ok(ModelProviderConfigWriteResponse { provider })
|
||||
}
|
||||
}
|
||||
|
||||
fn provider_edits(
|
||||
params: &ModelProviderConfigWriteParams,
|
||||
layers: &ConfigLayerStack,
|
||||
overrides: &LoaderOverrides,
|
||||
builtins: &HashMap<String, ModelProviderInfo>,
|
||||
) -> Result<(String, Vec<ApiConfigEdit>), ConfigManagerError> {
|
||||
let effective = layers.effective_config();
|
||||
let configured = effective.get("model_providers");
|
||||
let (provider_id, mut fields) = match ¶ms.settings {
|
||||
ProviderSettingsPatch::CustomGateway(patch) => {
|
||||
let target = patch.provider_id.as_deref();
|
||||
if target
|
||||
.is_some_and(|id| builtins.contains_key(id) || id == LEGACY_OLLAMA_CHAT_PROVIDER_ID)
|
||||
{
|
||||
return Err(invalid(
|
||||
"A custom gateway cannot use a built-in provider ID.",
|
||||
));
|
||||
}
|
||||
let existing = target.and_then(|id| configured?.get(id));
|
||||
if target.is_some() && existing.is_none() {
|
||||
return Err(ConfigManagerError::write(
|
||||
ConfigWriteErrorCode::ConfigPathNotFound,
|
||||
"Unknown provider ID.",
|
||||
));
|
||||
}
|
||||
let name = validate_custom_patch(patch, existing)?;
|
||||
let id = if let Some(id) = target {
|
||||
id.to_owned()
|
||||
} else {
|
||||
if patch.base_url.as_ref().and_then(Option::as_deref).is_none() {
|
||||
return Err(invalid(
|
||||
"A base URL is required to create a custom provider.",
|
||||
));
|
||||
}
|
||||
let default_id = layers
|
||||
.required_model_provider()
|
||||
.or_else(|| effective.get("model_provider")?.as_str());
|
||||
allocate_custom_id(name, |id| {
|
||||
builtins.contains_key(id)
|
||||
|| configured.is_some_and(|table| table.get(id).is_some())
|
||||
|| default_id == Some(id)
|
||||
})
|
||||
};
|
||||
let mut fields =
|
||||
patch_fields([("base_url", &patch.base_url), ("env_key", &patch.env_key)]);
|
||||
if patch.name.is_some() {
|
||||
fields.push(("name", Some(name)));
|
||||
}
|
||||
(id, fields)
|
||||
}
|
||||
ProviderSettingsPatch::Bedrock(patch) => {
|
||||
let id = match patch.provider_id {
|
||||
BedrockProviderId::AmazonBedrock => AMAZON_BEDROCK_PROVIDER_ID,
|
||||
BedrockProviderId::AmazonBedrockRuntime => AMAZON_BEDROCK_RUNTIME_PROVIDER_ID,
|
||||
};
|
||||
(
|
||||
id.to_owned(),
|
||||
patch_fields([
|
||||
("aws.profile", &patch.profile),
|
||||
("aws.region", &patch.region),
|
||||
]),
|
||||
)
|
||||
}
|
||||
ProviderSettingsPatch::Gcp(patch) => {
|
||||
let GcpProviderId::Gcp = patch.provider_id;
|
||||
(
|
||||
GCP_PROVIDER_ID.to_owned(),
|
||||
patch_fields([
|
||||
("project_id", &patch.project_id),
|
||||
("location", &patch.location),
|
||||
("credential_file", &patch.credential_file),
|
||||
]),
|
||||
)
|
||||
}
|
||||
};
|
||||
if fields.iter().any(|(_, value)| *value == Some("")) {
|
||||
return Err(invalid(
|
||||
"Configuration values must not be empty; use null to clear a field.",
|
||||
));
|
||||
}
|
||||
let existing = configured.and_then(|providers| providers.get(&provider_id));
|
||||
let builtin = builtins.get(&provider_id);
|
||||
let user_layer = writable_user_layer(layers, overrides);
|
||||
let supported = supported_fields(&provider_id, existing, builtin);
|
||||
for (field, _) in &fields {
|
||||
if !supported.contains(field) {
|
||||
return Err(invalid(
|
||||
"A supplied field is not editable for this provider.",
|
||||
));
|
||||
}
|
||||
if !field_is_writable(layers, user_layer, &provider_id, field) {
|
||||
return Err(ConfigManagerError::write(
|
||||
ConfigWriteErrorCode::ConfigLayerReadonly,
|
||||
"This configuration field is read-only.",
|
||||
));
|
||||
}
|
||||
}
|
||||
// Custom override tables require a name, but clearing an absent leaf needs no table.
|
||||
let user_provider =
|
||||
user_layer.and_then(|layer| layer.config.get("model_providers")?.get(&provider_id));
|
||||
if builtin.is_none()
|
||||
&& !fields.is_empty()
|
||||
&& !fields.iter().any(|(field, _)| *field == "name")
|
||||
&& (user_provider.is_some() || fields.iter().any(|(_, value)| value.is_some()))
|
||||
&& user_provider
|
||||
.and_then(|provider| provider.get("name"))
|
||||
.is_none()
|
||||
&& let Some(name) = existing.and_then(|provider| provider.get("name")?.as_str())
|
||||
{
|
||||
fields.push(("name", Some(name)));
|
||||
}
|
||||
if builtin.is_none() && existing.is_none() {
|
||||
fields.push(("wire_api", Some("responses")));
|
||||
}
|
||||
let escaped_id = provider_id.replace('\\', "\\\\").replace('"', "\\\"");
|
||||
let edits = fields
|
||||
.into_iter()
|
||||
.map(|(field, value)| ApiConfigEdit {
|
||||
key_path: format!(r#"model_providers."{escaped_id}".{field}"#),
|
||||
value: value.into(),
|
||||
merge_strategy: MergeStrategy::Replace,
|
||||
})
|
||||
.collect();
|
||||
Ok((provider_id, edits))
|
||||
}
|
||||
|
||||
// Missing fields are excluded. A field with no value clears its TOML key.
|
||||
type PatchField<'a> = (&'static str, Option<&'a str>);
|
||||
|
||||
fn patch_fields<'a, const N: usize>(
|
||||
requested: [(&'static str, &'a Option<Option<String>>); N],
|
||||
) -> Vec<PatchField<'a>> {
|
||||
requested
|
||||
.into_iter()
|
||||
.filter_map(|(field, value)| {
|
||||
value
|
||||
.as_ref()
|
||||
.map(|value| (field, value.as_deref().map(str::trim)))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn validate_custom_patch<'a>(
|
||||
patch: &'a CustomGatewaySettingsParams,
|
||||
existing: Option<&'a TomlValue>,
|
||||
) -> Result<&'a str, ConfigManagerError> {
|
||||
if patch
|
||||
.base_url
|
||||
.as_ref()
|
||||
.and_then(Option::as_deref)
|
||||
.is_some_and(|url| !valid_endpoint(url.trim()))
|
||||
{
|
||||
return Err(invalid(
|
||||
"Enter an HTTP(S) base URL without credentials, a query, or a fragment.",
|
||||
));
|
||||
}
|
||||
if let Some(Some(key)) = &patch.env_key {
|
||||
let key = key.trim();
|
||||
if !key.starts_with(|c: char| c == '_' || c.is_ascii_alphabetic())
|
||||
|| !key.bytes().all(|c| c == b'_' || c.is_ascii_alphanumeric())
|
||||
{
|
||||
return Err(invalid("Invalid API key environment variable name."));
|
||||
}
|
||||
}
|
||||
let existing_name = existing.and_then(|config| config.get("name")?.as_str());
|
||||
if patch.env_key.is_some()
|
||||
&& existing.is_some_and(|config| {
|
||||
has_external_auth(config)
|
||||
|| existing_name
|
||||
.or(patch.provider_id.as_deref())
|
||||
.is_some_and(uses_builtin_auth)
|
||||
})
|
||||
{
|
||||
return Err(invalid(
|
||||
"Authentication is configured externally. Omit envKey to preserve it.",
|
||||
));
|
||||
}
|
||||
let name = patch
|
||||
.name
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.or(existing_name)
|
||||
.filter(|name| !name.trim().is_empty())
|
||||
.ok_or_else(|| invalid("Enter a provider name."))?;
|
||||
// Legacy names select built-in authentication even on a custom provider.
|
||||
if uses_builtin_auth(name) {
|
||||
return Err(invalid(
|
||||
"This name is reserved for a built-in provider. Enter a different custom provider name.",
|
||||
));
|
||||
}
|
||||
Ok(name)
|
||||
}
|
||||
|
||||
fn allocate_custom_id(name: &str, is_taken: impl Fn(&str) -> bool) -> String {
|
||||
let slug = name
|
||||
.split(|c: char| !c.is_ascii_alphanumeric())
|
||||
.filter(|part| !part.is_empty())
|
||||
.collect::<Vec<_>>()
|
||||
.join("-")
|
||||
.to_ascii_lowercase();
|
||||
let stem = if slug.is_empty() { "custom" } else { &slug };
|
||||
let mut id = stem.to_owned();
|
||||
let mut suffix = 2;
|
||||
while id == LEGACY_OLLAMA_CHAT_PROVIDER_ID || is_taken(&id) {
|
||||
id = format!("{stem}-{suffix}");
|
||||
suffix += 1;
|
||||
}
|
||||
id
|
||||
}
|
||||
|
||||
fn invalid(message: &str) -> ConfigManagerError {
|
||||
ConfigManagerError::write(ConfigWriteErrorCode::ConfigValidationError, message)
|
||||
}
|
||||
@@ -1189,7 +1189,7 @@ async fn write_value_reports_override() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn provider_setup_rejects_config_changed_after_preview() -> Result<()> {
|
||||
async fn provider_setup_checks_versions_and_provider_write_uses_last_write_wins() -> Result<()> {
|
||||
let tmp = tempdir()?;
|
||||
let service = ConfigManager::without_managed_config_for_tests(tmp.path().to_path_buf());
|
||||
let layers = service.load_config_layers(/*cwd*/ None).await?;
|
||||
@@ -1208,6 +1208,47 @@ async fn provider_setup_rejects_config_changed_after_preview() -> Result<()> {
|
||||
Some(ConfigWriteErrorCode::ConfigVersionConflict)
|
||||
);
|
||||
assert_eq!(std::fs::read_to_string(user_path)?, newer_config);
|
||||
// An intervening writer changes both the requested field and an omitted sibling.
|
||||
// The patch wins for the requested field and preserves the newer sibling value.
|
||||
std::fs::write(
|
||||
tmp.path().join(CONFIG_TOML_FILE),
|
||||
"model = 'before'\n[model_providers.gateway]\nname = 'Before'\nenv_key = 'BEFORE_KEY'",
|
||||
)?;
|
||||
let calls = std::sync::atomic::AtomicUsize::new(/*v*/ 0);
|
||||
let config_path = tmp.path().join(CONFIG_TOML_FILE);
|
||||
let loader = CloudConfigBundleLoader::from_getter(move || {
|
||||
if calls.fetch_add(/*val*/ 1, std::sync::atomic::Ordering::SeqCst) == 1 {
|
||||
std::fs::write(&config_path, "model = 'newer'\n[model_providers.gateway]\nname = 'Another writer'\nenv_key = 'OTHER_KEY'").expect("intervening config write");
|
||||
}
|
||||
std::future::ready(Ok(None))
|
||||
});
|
||||
let service = ConfigManager::new_for_tests(
|
||||
tmp.path().to_path_buf(),
|
||||
vec![],
|
||||
LoaderOverrides::without_managed_config_for_tests(),
|
||||
loader,
|
||||
);
|
||||
let response = service
|
||||
.model_provider_config_write(serde_json::from_value(serde_json::json!({
|
||||
"settings":{"type":"customGateway","providerId":"gateway","name":"Gateway", "baseUrl":"https://gateway.example.test"}
|
||||
}))?)
|
||||
.await?;
|
||||
assert_eq!(
|
||||
serde_json::to_value(response)?,
|
||||
serde_json::json!({"provider": {
|
||||
"id":"gateway", "name":"Gateway", "canEdit":true,
|
||||
"baseUrl":"https://gateway.example.test",
|
||||
"settings":{"type":"customGateway", "auth":{"mode":"environmentVariable", "envKey":"OTHER_KEY"}}
|
||||
}})
|
||||
);
|
||||
let saved: serde_json::Value =
|
||||
toml::from_str(&std::fs::read_to_string(tmp.path().join(CONFIG_TOML_FILE))?)?;
|
||||
assert_eq!(
|
||||
saved,
|
||||
serde_json::json!({"model":"newer", "model_providers":{
|
||||
"gateway":{"name":"Gateway", "base_url":"https://gateway.example.test", "env_key":"OTHER_KEY"}
|
||||
}})
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1259,6 +1300,142 @@ async fn write_value_defaults_to_user_config_path() {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn model_provider_settings_use_the_active_profile_layer() -> Result<()> {
|
||||
use codex_app_server_protocol::CustomGatewaySettingsParams;
|
||||
use codex_app_server_protocol::GatewayAuth;
|
||||
use codex_app_server_protocol::ModelProviderConfigWriteParams;
|
||||
use codex_app_server_protocol::ModelProviderListParams;
|
||||
use codex_app_server_protocol::ProviderSettings;
|
||||
use codex_app_server_protocol::ProviderSettingsPatch;
|
||||
|
||||
let home = tempdir()?;
|
||||
let profile = home.path().join("work.config.toml");
|
||||
let system = home.path().join("system.toml");
|
||||
std::fs::write(
|
||||
&system,
|
||||
"model_provider = 'gcp'\n[model_providers.gateway]\nname = 'System'\nenv_key = 'SYSTEM_KEY'",
|
||||
)?;
|
||||
let overrides = LoaderOverrides {
|
||||
system_config_path: Some(system.clone()),
|
||||
user_config_path: Some(AbsolutePathBuf::from_absolute_path(&profile)?),
|
||||
user_config_profile: Some("work".parse()?),
|
||||
..LoaderOverrides::without_managed_config_for_tests()
|
||||
};
|
||||
let service = |cli_overrides| {
|
||||
ConfigManager::new_for_tests(
|
||||
home.path().to_path_buf(),
|
||||
cli_overrides,
|
||||
overrides.clone(),
|
||||
CloudConfigBundleLoader::default(),
|
||||
)
|
||||
};
|
||||
let manager = service(vec![]);
|
||||
let list = ModelProviderListParams {};
|
||||
let initial = manager.model_provider_list(list.clone()).await?;
|
||||
assert_eq!(initial.default_provider_id, "gcp");
|
||||
assert!(initial.can_change_default);
|
||||
|
||||
std::fs::write(&profile, "model_provider = 'openai'")?;
|
||||
let write = ModelProviderConfigWriteParams {
|
||||
settings: ProviderSettingsPatch::CustomGateway(CustomGatewaySettingsParams {
|
||||
name: Some("Gateway".to_owned()),
|
||||
base_url: Some(Some("https://gateway.example.test".to_owned())),
|
||||
..Default::default()
|
||||
}),
|
||||
};
|
||||
let created = manager.model_provider_config_write(write).await?;
|
||||
let selected = manager.model_provider_list(list.clone()).await?;
|
||||
assert_eq!(selected.default_provider_id, "openai");
|
||||
assert!(selected.can_change_default);
|
||||
assert!(selected.data[0].can_edit);
|
||||
|
||||
let write = ModelProviderConfigWriteParams {
|
||||
settings: ProviderSettingsPatch::CustomGateway(CustomGatewaySettingsParams {
|
||||
provider_id: Some(created.provider.id.clone()),
|
||||
name: Some("Renamed".to_owned()),
|
||||
..Default::default()
|
||||
}),
|
||||
};
|
||||
manager.model_provider_config_write(write).await?;
|
||||
let saved: TomlValue = toml::from_str(&std::fs::read_to_string(&profile)?)?;
|
||||
assert_eq!(
|
||||
saved["model_providers"][&created.provider.id]["name"].as_str(),
|
||||
Some("Renamed")
|
||||
);
|
||||
assert!(!home.path().join(CONFIG_TOML_FILE).exists());
|
||||
|
||||
let inherited = |mut settings: serde_json::Value| {
|
||||
settings["type"] = "customGateway".into();
|
||||
settings["providerId"] = "gateway".into();
|
||||
serde_json::from_value(serde_json::json!({"settings":settings}))
|
||||
};
|
||||
let before = std::fs::read_to_string(&profile)?;
|
||||
manager
|
||||
.model_provider_config_write(inherited(serde_json::json!({"baseUrl":null}))?)
|
||||
.await?;
|
||||
assert_eq!(std::fs::read_to_string(&profile)?, before);
|
||||
|
||||
manager
|
||||
.model_provider_config_write(inherited(serde_json::json!({"envKey":"USER_KEY"}))?)
|
||||
.await?;
|
||||
let cleared = manager
|
||||
.model_provider_config_write(inherited(
|
||||
serde_json::json!({"name":"Work", "envKey":null}),
|
||||
)?)
|
||||
.await?;
|
||||
assert_eq!(
|
||||
cleared.provider.settings,
|
||||
ProviderSettings::CustomGateway {
|
||||
auth: GatewayAuth::EnvironmentVariable {
|
||||
env_key: "SYSTEM_KEY".to_owned()
|
||||
}
|
||||
}
|
||||
);
|
||||
let saved: serde_json::Value = toml::from_str(&std::fs::read_to_string(&profile)?)?;
|
||||
assert_eq!(
|
||||
saved["model_providers"]["gateway"],
|
||||
serde_json::json!({"name":"Work"})
|
||||
);
|
||||
let pinned_manager = service(vec![(
|
||||
"model_providers.gateway.env_key".to_owned(),
|
||||
"CLI_KEY".into(),
|
||||
)]);
|
||||
let before = std::fs::read_to_string(&profile)?;
|
||||
let err = pinned_manager
|
||||
.model_provider_config_write(inherited(
|
||||
serde_json::json!({"name":"Must not save", "envKey":"USER_KEY"}),
|
||||
)?)
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert_eq!(
|
||||
err.write_error_code(),
|
||||
Some(ConfigWriteErrorCode::ConfigLayerReadonly)
|
||||
);
|
||||
assert_eq!(std::fs::read_to_string(&profile)?, before);
|
||||
let renamed = pinned_manager
|
||||
.model_provider_config_write(inherited(serde_json::json!({"name":"Allowed"}))?)
|
||||
.await?;
|
||||
assert_eq!(
|
||||
(renamed.provider.name.as_str(), renamed.provider.settings),
|
||||
(
|
||||
"Allowed",
|
||||
ProviderSettings::CustomGateway {
|
||||
auth: GatewayAuth::EnvironmentVariable {
|
||||
env_key: "CLI_KEY".to_owned()
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
let pinned = service(vec![("model_provider".to_owned(), "gcp".into())])
|
||||
.model_provider_list(list)
|
||||
.await?;
|
||||
assert_eq!(pinned.default_provider_id, "gcp");
|
||||
assert!(!pinned.can_change_default);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn write_value_defaults_to_selected_user_config_path() {
|
||||
let tmp = tempdir().expect("tempdir");
|
||||
|
||||
@@ -1321,6 +1321,11 @@ impl MessageProcessor {
|
||||
.model_provider_list(params)
|
||||
.await
|
||||
.map(|r| Some(r.into())),
|
||||
ClientRequest::ModelProviderConfigWrite { params, .. } => self
|
||||
.config_processor
|
||||
.model_provider_config_write(params)
|
||||
.await
|
||||
.map(|r| Some(r.into())),
|
||||
ClientRequest::ModelProviderCapabilitiesRead { params: _, .. } => self
|
||||
.config_processor
|
||||
.model_provider_capabilities_read()
|
||||
|
||||
@@ -65,6 +65,13 @@ impl ModelCatalog {
|
||||
self.state.lock().await.needs_reload = true;
|
||||
}
|
||||
|
||||
pub(crate) async fn invalidate_if_current_provider(&self, provider_id: &str) {
|
||||
let mut state = self.state.lock().await;
|
||||
if state.config.model_provider_id == provider_id {
|
||||
state.needs_reload = true;
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn set_api_key_model_discovery_enabled(&self, enabled: bool) {
|
||||
self.state
|
||||
.lock()
|
||||
|
||||
@@ -204,7 +204,7 @@ impl CatalogRequestProcessor {
|
||||
.load_latest_config(/*fallback_cwd*/ None)
|
||||
.await
|
||||
.map_err(|err| config_load_error(&err))?;
|
||||
// Configuration edits without an account transition still require a restart to refresh the model catalog.
|
||||
// A direct config file edit can leave the catalog using the previous gateway.
|
||||
if current.model_provider_id != config.model_provider_id
|
||||
|| current.model_provider != config.model_provider
|
||||
{
|
||||
|
||||
@@ -221,6 +221,23 @@ impl ConfigRequestProcessor {
|
||||
.map_err(map_error)
|
||||
}
|
||||
|
||||
pub(crate) async fn model_provider_config_write(
|
||||
&self,
|
||||
params: codex_app_server_protocol::ModelProviderConfigWriteParams,
|
||||
) -> Result<codex_app_server_protocol::ModelProviderConfigWriteResponse, JSONRPCErrorError>
|
||||
{
|
||||
let result = self
|
||||
.config_manager
|
||||
.model_provider_config_write(params)
|
||||
.await
|
||||
.map_err(map_error);
|
||||
let response = self.handle_config_mutation_result(result).await?;
|
||||
self.model_catalog
|
||||
.invalidate_if_current_provider(&response.provider.id)
|
||||
.await;
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
pub(crate) async fn model_provider_capabilities_read(
|
||||
&self,
|
||||
) -> Result<ModelProviderCapabilitiesReadResponse, JSONRPCErrorError> {
|
||||
|
||||
@@ -105,6 +105,7 @@ mod model_auto_review;
|
||||
mod model_list;
|
||||
mod model_list_requirements_tests;
|
||||
mod model_provider_capabilities_read;
|
||||
mod model_provider_config_tests;
|
||||
#[path = "model_provider_enforcement_tests.rs"]
|
||||
mod model_provider_enforcement;
|
||||
mod model_provider_list_tests;
|
||||
|
||||
@@ -7,6 +7,7 @@ use codex_app_server_protocol::LoginAccountResponse;
|
||||
use codex_app_server_protocol::LogoutAccountResponse;
|
||||
use codex_app_server_protocol::ModelListParams;
|
||||
use codex_app_server_protocol::ModelListResponse;
|
||||
use codex_app_server_protocol::ModelProviderConfigWriteResponse;
|
||||
use codex_app_server_protocol::RequestId;
|
||||
use codex_config::types::AuthCredentialsStoreMode;
|
||||
use codex_protocol::openai_models::ModelInfo;
|
||||
@@ -19,6 +20,7 @@ use test_case::test_case;
|
||||
use wiremock::Mock;
|
||||
use wiremock::MockServer;
|
||||
use wiremock::ResponseTemplate;
|
||||
use wiremock::matchers::header;
|
||||
use wiremock::matchers::method;
|
||||
use wiremock::matchers::path_regex;
|
||||
|
||||
@@ -212,6 +214,85 @@ requires_openai_auth = true
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn model_list_follows_active_provider_auth_edit() -> Result<()> {
|
||||
let gateway = MockServer::start().await;
|
||||
for (token, model) in [("initial-key", "first-model"), ("saved-key", "saved-model")] {
|
||||
Mock::given(header("authorization", format!("Bearer {token}")))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(catalog(model)?))
|
||||
.mount(&gateway)
|
||||
.await;
|
||||
}
|
||||
let home = TempDir::new()?;
|
||||
let path = home.path().join("config.toml");
|
||||
let config = format!(
|
||||
r#"model_provider = 'gateway'
|
||||
[features]
|
||||
api_key_model_discovery = true
|
||||
[model_providers.gateway]
|
||||
name = 'Gateway'
|
||||
base_url = '{0}'
|
||||
model_catalog_url = '{0}/models'
|
||||
env_key = 'GATEWAY_KEY'
|
||||
[model_providers.other]
|
||||
name = 'Other'
|
||||
"#,
|
||||
gateway.uri(),
|
||||
);
|
||||
std::fs::write(&path, &config)?;
|
||||
let mut server = TestAppServer::builder()
|
||||
.with_codex_home(home.path())
|
||||
.without_managed_config()
|
||||
.with_env_overrides(&[
|
||||
("GATEWAY_KEY", Some("initial-key")),
|
||||
("NEW_GATEWAY_KEY", Some("saved-key")),
|
||||
("OPENAI_API_KEY", None),
|
||||
("CODEX_API_KEY", None),
|
||||
("CODEX_ACCESS_TOKEN", None),
|
||||
("OPENAI_FEDERATION_RULE_ID", None),
|
||||
("OPENAI_IDENTITY_TOKEN_FILE", None),
|
||||
("OPENAI_WORKLOAD_IDENTITY_CONTEXT", None),
|
||||
])
|
||||
.build_initialized()
|
||||
.await?;
|
||||
let initial = list_models(&mut server).await?;
|
||||
assert_eq!(initial.data[0].id, "first-model");
|
||||
|
||||
// Neither an unrelated save nor a rejected edit should pick up this manual change.
|
||||
std::fs::write(&path, config.replace("env_key = 'GATEWAY_KEY'", ""))?;
|
||||
let id = server
|
||||
.send_request(
|
||||
"modelProvider/config/write",
|
||||
Some(json!({
|
||||
"settings": {"type":"customGateway", "providerId": "other", "name": "Renamed"}
|
||||
})),
|
||||
)
|
||||
.await?;
|
||||
let _: ModelProviderConfigWriteResponse = server.read_response(id).await?;
|
||||
let id = server
|
||||
.send_request(
|
||||
"modelProvider/config/write",
|
||||
Some(json!({
|
||||
"settings": {"type":"customGateway", "providerId": "gateway", "baseUrl": "invalid"}
|
||||
})),
|
||||
)
|
||||
.await?;
|
||||
server
|
||||
.read_stream_until_error_message(RequestId::Integer(id))
|
||||
.await?;
|
||||
assert_eq!(list_models(&mut server).await?, initial);
|
||||
|
||||
let id = server
|
||||
.send_request(
|
||||
"modelProvider/config/write",
|
||||
Some(json!({"settings": {"type":"customGateway", "providerId": "gateway", "envKey": "NEW_GATEWAY_KEY"}})),
|
||||
)
|
||||
.await?;
|
||||
let _: ModelProviderConfigWriteResponse = server.read_response(id).await?;
|
||||
assert_eq!(list_models(&mut server).await?.data[0].id, "saved-model");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Warm lists reuse their configuration; a completed login reloads the catalog once.
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn model_list_reuses_catalog_until_account_change() -> Result<()> {
|
||||
|
||||
@@ -0,0 +1,356 @@
|
||||
//! Exercises provider management through the public app-server requests.
|
||||
#![cfg(test)]
|
||||
|
||||
use anyhow::Result;
|
||||
use app_test_support::TestAppServer;
|
||||
use codex_app_server_protocol::ClientRequest;
|
||||
use codex_app_server_protocol::RequestId;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use tempfile::TempDir;
|
||||
|
||||
const CLEARED_AUTH_ENV: &[(&str, Option<&str>)] = &[
|
||||
("OPENAI_API_KEY", None),
|
||||
("CODEX_API_KEY", None),
|
||||
("CODEX_ACCESS_TOKEN", None),
|
||||
("OPENAI_FEDERATION_RULE_ID", None),
|
||||
("OPENAI_IDENTITY_TOKEN_FILE", None),
|
||||
("OPENAI_WORKLOAD_IDENTITY_CONTEXT", None),
|
||||
];
|
||||
|
||||
#[tokio::test]
|
||||
async fn create_and_patch_gateway_providers_without_changing_the_default() -> Result<()> {
|
||||
let home = TempDir::new()?;
|
||||
let mut server = TestAppServer::builder()
|
||||
.with_codex_home(home.path())
|
||||
.with_env_overrides(CLEARED_AUTH_ENV)
|
||||
.build_initialized()
|
||||
.await?;
|
||||
let settings = json!({"type":"customGateway", "name":"Team Gateway", "baseUrl":"https://gateway.example.test/v1", "envKey":"TEAM_KEY"});
|
||||
// Pipeline creation requests: allocation must run against the preceding committed write.
|
||||
let first = server
|
||||
.send_request(
|
||||
"modelProvider/config/write",
|
||||
Some(json!({"settings":settings})),
|
||||
)
|
||||
.await?;
|
||||
let second = server
|
||||
.send_request(
|
||||
"modelProvider/config/write",
|
||||
Some(json!({"settings":settings})),
|
||||
)
|
||||
.await?;
|
||||
let saved: Value = server.read_response(first).await?;
|
||||
let duplicate: Value = server.read_response(second).await?;
|
||||
assert_eq!(duplicate["provider"]["id"], "team-gateway-2");
|
||||
let mut expected = json!({"id":"team-gateway", "name":"Team Gateway", "canEdit":true,
|
||||
"baseUrl":"https://gateway.example.test/v1",
|
||||
"settings":{"type":"customGateway", "auth":{"mode":"environmentVariable", "envKey":"TEAM_KEY"}}});
|
||||
assert_eq!(saved, json!({"provider":expected}));
|
||||
// Disjoint stale-client patches preserve siblings; writing a field again wins.
|
||||
for (mut patch, field, value) in [
|
||||
(json!({"name":"Renamed"}), "name", json!("Renamed")),
|
||||
(
|
||||
json!({"baseUrl":"https://new.example.test"}),
|
||||
"baseUrl",
|
||||
json!("https://new.example.test"),
|
||||
),
|
||||
(json!({"name":"Latest"}), "name", json!("Latest")),
|
||||
(
|
||||
json!({"envKey":null}),
|
||||
"settings",
|
||||
json!({"type":"customGateway", "auth":{"mode":"none"}}),
|
||||
),
|
||||
(json!({"baseUrl":null}), "baseUrl", Value::Null),
|
||||
] {
|
||||
patch["type"] = json!("customGateway");
|
||||
patch["providerId"] = json!("team-gateway");
|
||||
let params = serde_json::from_value(json!({"settings":patch}))?;
|
||||
let updated: Value = server
|
||||
.request(|request_id| ClientRequest::ModelProviderConfigWrite { request_id, params })
|
||||
.await?;
|
||||
expected[field] = value;
|
||||
assert_eq!(updated, json!({"provider":expected}));
|
||||
}
|
||||
let path = home.path().join("config.toml");
|
||||
let before = std::fs::read_to_string(&path)?;
|
||||
let clear = server.send_request("modelProvider/config/write", Some(json!({"settings":{"type":"customGateway","providerId":"team-gateway","name":null, "baseUrl":"https://must-not-save.example.test"}}))).await?;
|
||||
let error = server
|
||||
.read_stream_until_error_message(RequestId::Integer(clear))
|
||||
.await?;
|
||||
assert_eq!(error.error.code, -32600);
|
||||
assert_eq!(std::fs::read_to_string(&path)?, before);
|
||||
let list = server
|
||||
.send_request("modelProvider/list", Some(json!({})))
|
||||
.await?;
|
||||
let after: Value = server.read_response(list).await?;
|
||||
assert_eq!(
|
||||
after["data"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.find(|p| p["id"] == "team-gateway"),
|
||||
Some(&expected)
|
||||
);
|
||||
assert_eq!(after["defaultProviderId"], "openai");
|
||||
let persisted: Value = toml::from_str(&before)?;
|
||||
assert_eq!(
|
||||
persisted["model_providers"]["team-gateway"],
|
||||
json!({"name":"Latest", "wire_api":"responses"})
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn custom_provider_edits_preserve_other_fields_and_respect_policy() -> Result<()> {
|
||||
let home = TempDir::new()?;
|
||||
std::fs::write(
|
||||
home.path().join("requirements.toml"),
|
||||
"model_provider = 'corp.gateway'\n[model_providers.\"corp.gateway\"]\nname = 'Managed gateway'\nbase_url = 'https://managed.example.test'\n",
|
||||
)?;
|
||||
let config_path = home.path().join("config.toml");
|
||||
let mut expected = json!({
|
||||
"model_providers": {
|
||||
"basic": {"name":"Basic", "base_url":"https://user:password@basic.example.test/v1"},
|
||||
"external": {
|
||||
"name": "External",
|
||||
"base_url": "https://external.example.test",
|
||||
"http_headers": {"Authorization": "Bearer test-only"},
|
||||
"query_params": {"api-version": "v1"},
|
||||
}
|
||||
}
|
||||
});
|
||||
std::fs::write(&config_path, toml::to_string(&expected)?)?;
|
||||
let mut server = TestAppServer::builder()
|
||||
.with_codex_home(home.path())
|
||||
.with_env_overrides(CLEARED_AUTH_ENV)
|
||||
.build_initialized()
|
||||
.await?;
|
||||
let edit = server
|
||||
.send_request(
|
||||
"modelProvider/config/write",
|
||||
Some(json!({"settings": {"type":"customGateway", "providerId":"external", "name":"Renamed"}})),
|
||||
)
|
||||
.await?;
|
||||
let saved: Value = server.read_response(edit).await?;
|
||||
assert_eq!(saved["provider"]["id"], "external");
|
||||
expected["model_providers"]["external"]["name"] = json!("Renamed");
|
||||
let actual: Value = toml::from_str(&std::fs::read_to_string(&config_path)?)?;
|
||||
assert_eq!(actual, expected);
|
||||
|
||||
for (id, mut patch, error_code) in [
|
||||
(
|
||||
"corp.gateway",
|
||||
json!({"name": "Changed"}),
|
||||
"configLayerReadonly",
|
||||
),
|
||||
(
|
||||
"openai",
|
||||
json!({"name": "Changed"}),
|
||||
"configValidationError",
|
||||
),
|
||||
("external", json!({"envKey": null}), "configValidationError"),
|
||||
(
|
||||
"basic",
|
||||
json!({"envKey": "NEW_KEY"}),
|
||||
"configValidationError",
|
||||
),
|
||||
("basic", json!({"envKey": null}), "configValidationError"),
|
||||
("ollama", json!({}), "configValidationError"),
|
||||
("gcp", json!({}), "configValidationError"),
|
||||
] {
|
||||
patch["type"] = json!("customGateway");
|
||||
patch["providerId"] = json!(id);
|
||||
let edit = server
|
||||
.send_request(
|
||||
"modelProvider/config/write",
|
||||
Some(json!({"settings": patch})),
|
||||
)
|
||||
.await?;
|
||||
let error = server
|
||||
.read_stream_until_error_message(RequestId::Integer(edit))
|
||||
.await?;
|
||||
assert_eq!(
|
||||
error.error.data,
|
||||
Some(json!({"config_write_error_code": error_code}))
|
||||
);
|
||||
}
|
||||
let persisted: Value = toml::from_str(&std::fs::read_to_string(&config_path)?)?;
|
||||
assert_eq!(persisted, expected);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn custom_provider_writes_reject_builtin_auth_names_and_preserve_existing_ids() -> Result<()>
|
||||
{
|
||||
let home = TempDir::new()?;
|
||||
let config_path = home.path().join("config.toml");
|
||||
let ids = [r"team\gpu", "corp.gateway", r#"team"gpu"#];
|
||||
let mut providers = json!({});
|
||||
for id in ids {
|
||||
providers[id] = json!({"name":"Amazon Bedrock", "base_url":"https://old.example.test"});
|
||||
}
|
||||
std::fs::write(
|
||||
&config_path,
|
||||
toml::to_string(&json!({"model_providers":providers}))?,
|
||||
)?;
|
||||
let mut server = TestAppServer::builder()
|
||||
.with_codex_home(home.path())
|
||||
.with_env_overrides(CLEARED_AUTH_ENV)
|
||||
.build_initialized()
|
||||
.await?;
|
||||
|
||||
let new_url = "https://new.example.test";
|
||||
for (provider_id, mut settings) in [
|
||||
(None, json!({"name": "OpenAI", "baseUrl": new_url})),
|
||||
(
|
||||
None,
|
||||
json!({"name": " Amazon Bedrock ", "baseUrl": new_url}),
|
||||
),
|
||||
(Some(ids[0]), json!({"name": "Amazon Bedrock Runtime"})),
|
||||
(Some(ids[0]), json!({"name": "Google Cloud Vertex AI"})),
|
||||
(Some(ids[0]), json!({"baseUrl": new_url})),
|
||||
(Some(ids[0]), json!({"name":"Renamed", "envKey":null})),
|
||||
] {
|
||||
settings["type"] = json!("customGateway");
|
||||
settings["providerId"] = json!(provider_id);
|
||||
let request = server
|
||||
.send_request(
|
||||
"modelProvider/config/write",
|
||||
Some(json!({"settings":settings})),
|
||||
)
|
||||
.await?;
|
||||
let error = server
|
||||
.read_stream_until_error_message(RequestId::Integer(request))
|
||||
.await?;
|
||||
assert_eq!(
|
||||
error.error.data,
|
||||
Some(json!({"config_write_error_code":"configValidationError"}))
|
||||
);
|
||||
}
|
||||
|
||||
for id in ids {
|
||||
let request = server
|
||||
.send_request(
|
||||
"modelProvider/config/write",
|
||||
Some(json!({"settings":{"type":"customGateway","providerId":id,"name":"Amazon Bedrock Mantle","baseUrl":new_url}})),
|
||||
)
|
||||
.await?;
|
||||
let saved: Value = server.read_response(request).await?;
|
||||
assert_eq!(saved["provider"]["id"], id);
|
||||
providers[id] = json!({"name": "Amazon Bedrock Mantle", "base_url": new_url});
|
||||
}
|
||||
let saved: Value = toml::from_str(&std::fs::read_to_string(config_path)?)?;
|
||||
assert_eq!(saved["model_providers"], providers);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn builtin_provider_patches_preserve_auth_and_do_not_select_or_authenticate() -> Result<()> {
|
||||
let home = TempDir::new()?;
|
||||
let config_path = home.path().join("config.toml");
|
||||
std::fs::write(
|
||||
home.path().join("requirements.toml"),
|
||||
"model_provider = 'openai'\n",
|
||||
)?;
|
||||
let mut server = TestAppServer::builder()
|
||||
.with_codex_home(home.path())
|
||||
.with_env_overrides(CLEARED_AUTH_ENV)
|
||||
.build_initialized()
|
||||
.await?;
|
||||
let credential_file = home.path().join("missing-credentials.json");
|
||||
for mut settings in [
|
||||
json!({"type":"bedrock", "providerId":"amazon-bedrock", "profile":"work", "region":"us-east-1"}),
|
||||
json!({"type":"bedrock", "providerId":"amazon-bedrock-runtime", "profile":null, "region":"us-west-2"}),
|
||||
json!({"type":"gcp", "providerId":"gcp", "projectId":"test-project", "location":"global", "credentialFile":credential_file}),
|
||||
] {
|
||||
let params = serde_json::from_value(json!({"settings":settings}))?;
|
||||
let saved: Value = server
|
||||
.request(|request_id| ClientRequest::ModelProviderConfigWrite { request_id, params })
|
||||
.await?;
|
||||
let id = settings
|
||||
.as_object_mut()
|
||||
.unwrap()
|
||||
.remove("providerId")
|
||||
.unwrap();
|
||||
assert_eq!(saved["provider"]["id"], id);
|
||||
assert_eq!(saved["provider"]["settings"], settings);
|
||||
}
|
||||
let refresh = json!({"command":"aws", "args":["sso", "login"]});
|
||||
let export = json!({"command":"unused-credential-command", "args":["test-only"]});
|
||||
let mut configured: Value = toml::from_str(&std::fs::read_to_string(&config_path)?)?;
|
||||
configured["model_providers"]["amazon-bedrock"]["aws"]["auth_refresh"] = refresh.clone();
|
||||
configured["model_providers"]["amazon-bedrock-runtime"]["aws"]["credential_export"] =
|
||||
export.clone();
|
||||
std::fs::write(&config_path, toml::to_string(&configured)?)?;
|
||||
for settings in [
|
||||
json!({"type":"bedrock", "providerId":"amazon-bedrock", "region":null}),
|
||||
json!({"type":"bedrock", "providerId":"amazon-bedrock-runtime", "region":"eu-west-1"}),
|
||||
json!({"type":"gcp", "providerId":"gcp", "location":"us-central1", "credentialFile":null}),
|
||||
json!({"type":"gcp", "providerId":"gcp"}),
|
||||
] {
|
||||
let params = serde_json::from_value(json!({"settings":settings}))?;
|
||||
let saved: Value = server
|
||||
.request(|request_id| ClientRequest::ModelProviderConfigWrite { request_id, params })
|
||||
.await?;
|
||||
assert_eq!(saved["provider"]["id"], settings["providerId"]);
|
||||
}
|
||||
let list: Value = server
|
||||
.request(|request_id| ClientRequest::ModelProviderList {
|
||||
request_id,
|
||||
params: Default::default(),
|
||||
})
|
||||
.await?;
|
||||
assert_eq!(list["defaultProviderId"], "openai");
|
||||
assert_eq!(list["canChangeDefault"], false);
|
||||
let before_rejections = std::fs::read_to_string(&config_path)?;
|
||||
let actual: Value = toml::from_str(&before_rejections)?;
|
||||
assert_eq!(
|
||||
actual,
|
||||
json!({"model_providers": {
|
||||
"amazon-bedrock": {"aws":{"profile":"work", "auth_refresh":refresh}},
|
||||
"amazon-bedrock-runtime": {"aws":{"region":"eu-west-1", "credential_export":export}},
|
||||
"gcp":{"project_id":"test-project", "location":"us-central1"}
|
||||
}})
|
||||
);
|
||||
for settings in [
|
||||
json!({"type":"bedrock", "providerId":"amazon-bedrock-runtime", "profile":"conflicts-with-command", "region":"must-not-save"}),
|
||||
json!({"type":"gcp", "providerId":"gcp", "credentialFile":"relative/path", "location":"must-not-save"}),
|
||||
] {
|
||||
let write = server
|
||||
.send_request(
|
||||
"modelProvider/config/write",
|
||||
Some(json!({"settings":settings})),
|
||||
)
|
||||
.await?;
|
||||
let error = server
|
||||
.read_stream_until_error_message(RequestId::Integer(write))
|
||||
.await?;
|
||||
assert_eq!(
|
||||
error.error.data,
|
||||
Some(json!({"config_write_error_code":"configValidationError"}))
|
||||
);
|
||||
assert_eq!(std::fs::read_to_string(&config_path)?, before_rejections);
|
||||
}
|
||||
for settings in [
|
||||
json!({"type":"bedrock", "providerId":"gcp", "region":"must-not-save"}),
|
||||
json!({"type":"gcp", "providerId":"amazon-bedrock", "location":"must-not-save"}),
|
||||
json!({"type":"bedrock", "providerId":"amazon-bedrock", "envKey":"UNSUPPORTED"}),
|
||||
json!({"type":"gcp", "providerId":"gcp", "profile":"wrong-provider-field"}),
|
||||
json!({"type":"gcp", "location":"missing-id"}),
|
||||
] {
|
||||
let write = server
|
||||
.send_request(
|
||||
"modelProvider/config/write",
|
||||
Some(json!({"settings":settings})),
|
||||
)
|
||||
.await?;
|
||||
let error = server
|
||||
.read_stream_until_error_message(RequestId::Integer(write))
|
||||
.await?;
|
||||
assert_eq!(error.error.code, -32600);
|
||||
}
|
||||
assert_eq!(std::fs::read_to_string(&config_path)?, before_rejections);
|
||||
Ok(())
|
||||
}
|
||||
@@ -426,6 +426,11 @@ class AutoReviewRequirements(BaseModel):
|
||||
required_on_models: Annotated[list[str] | None, Field(alias="requiredOnModels")] = None
|
||||
|
||||
|
||||
class BedrockProviderId(Enum):
|
||||
amazon_bedrock = "amazon-bedrock"
|
||||
amazon_bedrock_runtime = "amazon-bedrock-runtime"
|
||||
|
||||
|
||||
class BrowserUseAccessApprovalLifetime(Enum):
|
||||
turn = "turn"
|
||||
thread = "thread"
|
||||
@@ -1850,6 +1855,10 @@ class GatewayOAuthStatus(Enum):
|
||||
failed = "failed"
|
||||
|
||||
|
||||
class GcpProviderId(RootModel[Literal["gcp"]]):
|
||||
root: Literal["gcp"]
|
||||
|
||||
|
||||
class GetAccountParams(BaseModel):
|
||||
model_config = ConfigDict(
|
||||
populate_by_name=True,
|
||||
@@ -3779,6 +3788,62 @@ class ProviderSettings(
|
||||
)
|
||||
|
||||
|
||||
class CustomGatewayProviderSettingsPatch(BaseModel):
|
||||
model_config = ConfigDict(
|
||||
extra="forbid",
|
||||
populate_by_name=True,
|
||||
)
|
||||
base_url: Annotated[str | None, Field(alias="baseUrl")] = None
|
||||
env_key: Annotated[str | None, Field(alias="envKey")] = None
|
||||
name: str | None = None
|
||||
provider_id: Annotated[
|
||||
str | None,
|
||||
Field(
|
||||
alias="providerId",
|
||||
description="Omit or pass null to allocate a new custom provider ID.",
|
||||
),
|
||||
] = None
|
||||
type: Annotated[Literal["customGateway"], Field(title="CustomGatewayProviderSettingsPatchType")]
|
||||
|
||||
|
||||
class BedrockProviderSettingsPatch(BaseModel):
|
||||
model_config = ConfigDict(
|
||||
extra="forbid",
|
||||
populate_by_name=True,
|
||||
)
|
||||
profile: str | None = None
|
||||
provider_id: Annotated[BedrockProviderId, Field(alias="providerId")]
|
||||
region: str | None = None
|
||||
type: Annotated[Literal["bedrock"], Field(title="BedrockProviderSettingsPatchType")]
|
||||
|
||||
|
||||
class GcpProviderSettingsPatch(BaseModel):
|
||||
model_config = ConfigDict(
|
||||
extra="forbid",
|
||||
populate_by_name=True,
|
||||
)
|
||||
credential_file: Annotated[str | None, Field(alias="credentialFile")] = None
|
||||
location: str | None = None
|
||||
project_id: Annotated[str | None, Field(alias="projectId")] = None
|
||||
provider_id: Annotated[GcpProviderId, Field(alias="providerId")]
|
||||
type: Annotated[Literal["gcp"], Field(title="GcpProviderSettingsPatchType")]
|
||||
|
||||
|
||||
class ProviderSettingsPatch(
|
||||
RootModel[
|
||||
CustomGatewayProviderSettingsPatch | BedrockProviderSettingsPatch | GcpProviderSettingsPatch
|
||||
]
|
||||
):
|
||||
root: Annotated[
|
||||
CustomGatewayProviderSettingsPatch
|
||||
| BedrockProviderSettingsPatch
|
||||
| GcpProviderSettingsPatch,
|
||||
Field(
|
||||
description="Omitted patch fields preserve their values. Explicit null clears a nullable field."
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
class RateLimitReachedType(Enum):
|
||||
rate_limit_reached = "rate_limit_reached"
|
||||
workspace_owner_credits_depleted = "workspace_owner_credits_depleted"
|
||||
@@ -9336,6 +9401,14 @@ class ModelListResponse(BaseModel):
|
||||
] = None
|
||||
|
||||
|
||||
class ModelProviderConfigWriteParams(BaseModel):
|
||||
model_config = ConfigDict(
|
||||
extra="forbid",
|
||||
populate_by_name=True,
|
||||
)
|
||||
settings: ProviderSettingsPatch
|
||||
|
||||
|
||||
class ModelProviderSummary(BaseModel):
|
||||
model_config = ConfigDict(
|
||||
populate_by_name=True,
|
||||
@@ -11409,6 +11482,18 @@ class ReviewStartRequest(BaseModel):
|
||||
params: ReviewStartParams
|
||||
|
||||
|
||||
class ModelProviderConfigWriteRequest(BaseModel):
|
||||
model_config = ConfigDict(
|
||||
populate_by_name=True,
|
||||
)
|
||||
id: RequestId
|
||||
method: Annotated[
|
||||
Literal["modelProvider/config/write"],
|
||||
Field(title="ModelProvider/config/writeRequestMethod"),
|
||||
]
|
||||
params: ModelProviderConfigWriteParams
|
||||
|
||||
|
||||
class McpServerStatusListRequest(BaseModel):
|
||||
model_config = ConfigDict(
|
||||
populate_by_name=True,
|
||||
@@ -11774,6 +11859,13 @@ class ListMcpServerStatusResponse(BaseModel):
|
||||
] = None
|
||||
|
||||
|
||||
class ModelProviderConfigWriteResponse(BaseModel):
|
||||
model_config = ConfigDict(
|
||||
populate_by_name=True,
|
||||
)
|
||||
provider: ModelProviderSummary
|
||||
|
||||
|
||||
class ModelProviderListResponse(BaseModel):
|
||||
model_config = ConfigDict(
|
||||
populate_by_name=True,
|
||||
@@ -13489,6 +13581,7 @@ class ClientRequest(
|
||||
| AccountGatewayOAuthLoginRequest
|
||||
| AccountGatewayOAuthCancelRequest
|
||||
| ModelProviderListRequest
|
||||
| ModelProviderConfigWriteRequest
|
||||
| ModelProviderCapabilitiesReadRequest
|
||||
| ExperimentalFeatureListRequest
|
||||
| PermissionProfileListRequest
|
||||
@@ -13599,6 +13692,7 @@ class ClientRequest(
|
||||
| AccountGatewayOAuthLoginRequest
|
||||
| AccountGatewayOAuthCancelRequest
|
||||
| ModelProviderListRequest
|
||||
| ModelProviderConfigWriteRequest
|
||||
| ModelProviderCapabilitiesReadRequest
|
||||
| ExperimentalFeatureListRequest
|
||||
| PermissionProfileListRequest
|
||||
|
||||
@@ -5,6 +5,7 @@ from pathlib import Path
|
||||
from typing import get_type_hints
|
||||
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
from openai_codex._runtime_requirements import CheckoutCapabilities
|
||||
from openai_codex.client import CodexClient, _params_dict
|
||||
@@ -20,6 +21,8 @@ from openai_codex.generated.v2_all import (
|
||||
AuthRecoveryNotification,
|
||||
CommandGuardianApprovalReviewAction,
|
||||
GetAccountResponse,
|
||||
ModelProviderConfigWriteParams,
|
||||
ModelProviderConfigWriteResponse,
|
||||
ModelProviderListResponse,
|
||||
PlanType,
|
||||
ReasoningEffort,
|
||||
@@ -42,7 +45,7 @@ from openai_codex.types import ThreadSource
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def test_model_provider_list_preserves_wire_fields_for_each_auth_mode() -> None:
|
||||
def test_model_provider_responses_preserve_wire_fields_for_each_auth_mode() -> None:
|
||||
wire = {
|
||||
"data": [
|
||||
{
|
||||
@@ -91,6 +94,37 @@ def test_model_provider_list_preserves_wire_fields_for_each_auth_mode() -> None:
|
||||
}
|
||||
response = ModelProviderListResponse.model_validate(wire)
|
||||
assert response.model_dump(mode="json", by_alias=True) == wire
|
||||
for provider in wire["data"]:
|
||||
saved = ModelProviderConfigWriteResponse.model_validate({"provider": provider})
|
||||
assert saved.model_dump(mode="json", by_alias=True) == {"provider": provider}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"settings",
|
||||
[
|
||||
{"type": "customGateway", "name": "Gateway", "baseUrl": "https://example.test"},
|
||||
{"type": "customGateway", "providerId": "team", "envKey": None},
|
||||
{"type": "bedrock", "providerId": "amazon-bedrock", "region": None},
|
||||
{"type": "bedrock", "providerId": "amazon-bedrock-runtime", "profile": "work"},
|
||||
{"type": "gcp", "providerId": "gcp", "credentialFile": None, "location": "global"},
|
||||
],
|
||||
)
|
||||
def test_provider_patch_preserves_explicit_null_and_omitted_fields(settings: dict) -> None:
|
||||
wire = {"settings": settings}
|
||||
params = ModelProviderConfigWriteParams.model_validate(wire)
|
||||
assert params.model_dump(mode="json", by_alias=True, exclude_unset=True) == wire
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"settings",
|
||||
[
|
||||
{"type": "bedrock", "providerId": "gcp", "region": "us-east-1"},
|
||||
{"type": "gcp", "providerId": "gcp", "region": "us-east-1"},
|
||||
],
|
||||
)
|
||||
def test_provider_patch_rejects_mismatched_id_or_fields(settings: dict) -> None:
|
||||
with pytest.raises(ValidationError):
|
||||
ModelProviderConfigWriteParams.model_validate({"settings": settings})
|
||||
|
||||
|
||||
def test_inline_review_delivery_round_trips_as_an_enum() -> None:
|
||||
|
||||
Reference in New Issue
Block a user