Define the startup OAuth protocol for config servers (#62859)

## What changed

Add the optional `target` field to `account/gatewayOAuth/login`.
The startup protocol defines `{"kind":"configServer"}` as a target
for `--startup-oauth`, mutually exclusive with `modelProvider`.
The regular app-server login handler rejects explicit targets.

Define `StartupGatewayOAuthChangedNotification` with the target,
status, and authorization URL for the browser handoff. Export the
new types in the JSON schemas, TypeScript bindings, and Python SDK.

## Testing

Update the TUI device login regression test to expect `target: null`
when signing in to a resumed thread's saved gateway.

GitOrigin-RevId: fb3ce66a143cad9ad56c93f3ac37f8b6f1abdb0e
This commit is contained in:
arnavpatidar-OAI
2026-11-20 23:24:10 +00:00
committed by copyberry
parent beac2ef8fc
commit b392250f48
18 changed files with 360 additions and 40 deletions
+32 -1
View File
@@ -1702,7 +1702,7 @@
"type": "object"
},
"GatewayOAuthLoginParams": {
"description": "Authorize a configured provider without changing the default or any thread's provider.",
"description": "Authorize a configured service without changing the selected model provider.",
"properties": {
"deviceAuth": {
"description": "Select device authorization when the server advertises support for it.",
@@ -1714,6 +1714,17 @@
"string",
"null"
]
},
"target": {
"anyOf": [
{
"$ref": "#/definitions/GatewayOAuthTarget"
},
{
"type": "null"
}
],
"description": "Available only on `--startup-oauth`. Mutually exclusive with `modelProvider`."
}
},
"type": "object"
@@ -1731,6 +1742,26 @@
},
"type": "object"
},
"GatewayOAuthTarget": {
"description": "An explicit service to authorize instead of the selected model provider.",
"oneOf": [
{
"properties": {
"kind": {
"enum": [
"configServer"
],
"type": "string"
}
},
"required": [
"kind"
],
"title": "ConfigServerGatewayOAuthTarget",
"type": "object"
}
]
},
"GcpProviderId": {
"enum": [
"gcp"
@@ -13614,7 +13614,7 @@
"type": "object"
},
"GatewayOAuthLoginParams": {
"description": "Authorize a configured provider without changing the default or any thread's provider.",
"description": "Authorize a configured service without changing the selected model provider.",
"properties": {
"deviceAuth": {
"description": "Select device authorization when the server advertises support for it.",
@@ -13626,6 +13626,17 @@
"string",
"null"
]
},
"target": {
"anyOf": [
{
"$ref": "#/definitions/v2/GatewayOAuthTarget"
},
{
"type": "null"
}
],
"description": "Available only on `--startup-oauth`. Mutually exclusive with `modelProvider`."
}
},
"type": "object"
@@ -13733,6 +13744,26 @@
],
"type": "string"
},
"GatewayOAuthTarget": {
"description": "An explicit service to authorize instead of the selected model provider.",
"oneOf": [
{
"properties": {
"kind": {
"enum": [
"configServer"
],
"type": "string"
}
},
"required": [
"kind"
],
"title": "ConfigServerGatewayOAuthTarget",
"type": "object"
}
]
},
"GcpProviderId": {
"enum": [
"gcp"
@@ -22636,6 +22667,28 @@
],
"type": "object"
},
"StartupGatewayOAuthChangedNotification": {
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Browser handoff on the dedicated `--startup-oauth` connection.",
"properties": {
"authUrl": {
"type": "string"
},
"status": {
"$ref": "#/definitions/v2/GatewayOAuthStatus"
},
"target": {
"$ref": "#/definitions/v2/GatewayOAuthTarget"
}
},
"required": [
"authUrl",
"status",
"target"
],
"title": "StartupGatewayOAuthChangedNotification",
"type": "object"
},
"StrictReviewRequiredNotification": {
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
@@ -9479,7 +9479,7 @@
"type": "object"
},
"GatewayOAuthLoginParams": {
"description": "Authorize a configured provider without changing the default or any thread's provider.",
"description": "Authorize a configured service without changing the selected model provider.",
"properties": {
"deviceAuth": {
"description": "Select device authorization when the server advertises support for it.",
@@ -9491,6 +9491,17 @@
"string",
"null"
]
},
"target": {
"anyOf": [
{
"$ref": "#/definitions/GatewayOAuthTarget"
},
{
"type": "null"
}
],
"description": "Available only on `--startup-oauth`. Mutually exclusive with `modelProvider`."
}
},
"type": "object"
@@ -9598,6 +9609,26 @@
],
"type": "string"
},
"GatewayOAuthTarget": {
"description": "An explicit service to authorize instead of the selected model provider.",
"oneOf": [
{
"properties": {
"kind": {
"enum": [
"configServer"
],
"type": "string"
}
},
"required": [
"kind"
],
"title": "ConfigServerGatewayOAuthTarget",
"type": "object"
}
]
},
"GcpProviderId": {
"enum": [
"gcp"
@@ -20332,6 +20363,28 @@
],
"type": "object"
},
"StartupGatewayOAuthChangedNotification": {
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Browser handoff on the dedicated `--startup-oauth` connection.",
"properties": {
"authUrl": {
"type": "string"
},
"status": {
"$ref": "#/definitions/GatewayOAuthStatus"
},
"target": {
"$ref": "#/definitions/GatewayOAuthTarget"
}
},
"required": [
"authUrl",
"status",
"target"
],
"title": "StartupGatewayOAuthChangedNotification",
"type": "object"
},
"StrictReviewRequiredNotification": {
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
@@ -10,7 +10,7 @@
],
"definitions": {
"GatewayOAuthLoginParams": {
"description": "Authorize a configured provider without changing the default or any thread's provider.",
"description": "Authorize a configured service without changing the selected model provider.",
"properties": {
"deviceAuth": {
"description": "Select device authorization when the server advertises support for it.",
@@ -22,9 +22,40 @@
"string",
"null"
]
},
"target": {
"anyOf": [
{
"$ref": "#/definitions/GatewayOAuthTarget"
},
{
"type": "null"
}
],
"description": "Available only on `--startup-oauth`. Mutually exclusive with `modelProvider`."
}
},
"type": "object"
},
"GatewayOAuthTarget": {
"description": "An explicit service to authorize instead of the selected model provider.",
"oneOf": [
{
"properties": {
"kind": {
"enum": [
"configServer"
],
"type": "string"
}
},
"required": [
"kind"
],
"title": "ConfigServerGatewayOAuthTarget",
"type": "object"
}
]
}
},
"title": "Nullable_GatewayOAuthLoginParams"
@@ -0,0 +1,53 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"GatewayOAuthStatus": {
"enum": [
"notReady",
"started",
"succeeded",
"failed"
],
"type": "string"
},
"GatewayOAuthTarget": {
"description": "An explicit service to authorize instead of the selected model provider.",
"oneOf": [
{
"properties": {
"kind": {
"enum": [
"configServer"
],
"type": "string"
}
},
"required": [
"kind"
],
"title": "ConfigServerGatewayOAuthTarget",
"type": "object"
}
]
}
},
"description": "Browser handoff on the dedicated `--startup-oauth` connection.",
"properties": {
"authUrl": {
"type": "string"
},
"status": {
"$ref": "#/definitions/GatewayOAuthStatus"
},
"target": {
"$ref": "#/definitions/GatewayOAuthTarget"
}
},
"required": [
"authUrl",
"status",
"target"
],
"title": "StartupGatewayOAuthChangedNotification",
"type": "object"
}
@@ -1,15 +1,20 @@
// 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 { GatewayOAuthTarget } from "./GatewayOAuthTarget";
/**
* Authorize a configured provider without changing the default or any thread's provider.
* Authorize a configured service without changing the selected model provider.
*/
export type GatewayOAuthLoginParams = {
/**
* Defaults to the current provider when omitted.
*/
modelProvider?: string | null,
/**
* Available only on `--startup-oauth`. Mutually exclusive with `modelProvider`.
*/
target?: GatewayOAuthTarget | null,
/**
* Select device authorization when the server advertises support for it.
*/
@@ -0,0 +1,8 @@
// 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.
/**
* An explicit service to authorize instead of the selected model provider.
*/
export type GatewayOAuthTarget = { "kind": "configServer" };
@@ -0,0 +1,10 @@
// 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 { GatewayOAuthStatus } from "./GatewayOAuthStatus";
import type { GatewayOAuthTarget } from "./GatewayOAuthTarget";
/**
* Browser handoff on the dedicated `--startup-oauth` connection.
*/
export type StartupGatewayOAuthChangedNotification = { target: GatewayOAuthTarget, status: GatewayOAuthStatus, authUrl: string, };
@@ -224,6 +224,7 @@ export type { GatewayOAuthPrompt } from "./GatewayOAuthPrompt";
export type { GatewayOAuthReadParams } from "./GatewayOAuthReadParams";
export type { GatewayOAuthReadResponse } from "./GatewayOAuthReadResponse";
export type { GatewayOAuthStatus } from "./GatewayOAuthStatus";
export type { GatewayOAuthTarget } from "./GatewayOAuthTarget";
export type { GcpProviderId } from "./GcpProviderId";
export type { GcpSettingsParams } from "./GcpSettingsParams";
export type { GetAccountParams } from "./GetAccountParams";
@@ -509,6 +510,7 @@ export type { SkillsListParams } from "./SkillsListParams";
export type { SkillsListResponse } from "./SkillsListResponse";
export type { SortDirection } from "./SortDirection";
export type { SpendControlLimitSnapshot } from "./SpendControlLimitSnapshot";
export type { StartupGatewayOAuthChangedNotification } from "./StartupGatewayOAuthChangedNotification";
export type { StrictReviewRequiredNotification } from "./StrictReviewRequiredNotification";
export type { SubAgentActivityKind } from "./SubAgentActivityKind";
export type { SubagentMigration } from "./SubagentMigration";
@@ -132,6 +132,7 @@ pub fn generate_ts_with_options(
ensure_dir(out_dir)?;
ensure_dir(&v2_out_dir)?;
crate::StartupGatewayOAuthChangedNotification::export_all_to(out_dir)?;
ClientRequest::export_all_to(out_dir)?;
export_client_responses(out_dir)?;
ClientNotification::export_all_to(out_dir)?;
@@ -238,6 +239,9 @@ pub fn generate_json_with_experimental(out_dir: &Path, experimental_api: bool) -
out_dir,
"v2::UserVerificationRpcError",
)?);
schemas.push(write_json_schema::<
crate::StartupGatewayOAuthChangedNotification,
>(out_dir, "v2::StartupGatewayOAuthChangedNotification")?);
schemas.push(write_json_schema::<crate::ModelProviderError>(
out_dir,
"v2::ModelProviderError",
@@ -690,7 +690,34 @@ pub struct GatewayOAuthReadParams {
pub type NullableGatewayOAuthReadParams = Option<GatewayOAuthReadParams>;
/// Authorize a configured provider without changing the default or any thread's provider.
/// An explicit service to authorize instead of the selected model provider.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
#[serde(tag = "kind", rename_all = "camelCase")]
#[ts(tag = "kind", rename_all = "camelCase", export_to = "v2/")]
pub enum GatewayOAuthTarget {
ConfigServer,
}
/// Browser handoff on the dedicated `--startup-oauth` connection.
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct StartupGatewayOAuthChangedNotification {
pub target: GatewayOAuthTarget,
pub status: GatewayOAuthStatus,
pub auth_url: String,
}
impl std::fmt::Debug for StartupGatewayOAuthChangedNotification {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("StartupGatewayOAuthChangedNotification")
.field("target", &self.target)
.field("status", &self.status)
.finish_non_exhaustive()
}
}
/// Authorize a configured service without changing the selected model provider.
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
@@ -698,6 +725,9 @@ pub struct GatewayOAuthLoginParams {
/// Defaults to the current provider when omitted.
#[ts(optional = nullable)]
pub model_provider: Option<String>,
/// Available only on `--startup-oauth`. Mutually exclusive with `modelProvider`.
#[ts(optional = nullable)]
pub target: Option<GatewayOAuthTarget>,
/// Select device authorization when the server advertises support for it.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub device_auth: bool,
@@ -81,6 +81,9 @@ pub fn generate_typescript_schema_fixture_subtree_for_tests() -> Result<BTreeMap
let mut files = BTreeMap::new();
let mut seen = HashSet::new();
collect_typescript_fixture_file::<crate::StartupGatewayOAuthChangedNotification>(
&mut files, &mut seen,
)?;
collect_typescript_fixture_file::<ClientRequest>(&mut files, &mut seen)?;
visit_typescript_fixture_dependencies(&mut files, &mut seen, |visitor| {
visit_client_response_types(visitor);
@@ -102,6 +102,11 @@ impl AccountRequestProcessor {
owner: ConnectionId,
connection_gate: &crate::connection_rpc_gate::ConnectionRpcGate,
) -> Result<GatewayOAuthLoginResponse, JSONRPCErrorError> {
if params.target.is_some() {
return Err(invalid_request(
"Explicit gateway OAuth targets are available only during startup",
));
}
let cancel = CancellationToken::new();
let guard = {
let mut active = self
+1
View File
@@ -141,6 +141,7 @@ pub(crate) async fn start_if_needed(
.request_typed(ClientRequest::GatewayOAuthLogin {
request_id: server.next_request_id(),
params: Some(GatewayOAuthLoginParams {
target: None,
device_auth: true,
model_provider: Some(state.provider_id),
}),
+1 -1
View File
@@ -186,7 +186,7 @@ async fn resuming_a_running_thread_signs_in_to_its_saved_gateway() -> color_eyre
);
assert_eq!(
requests[4].body_json()["params"],
json!({"modelProvider":"company","deviceAuth":true})
json!({"modelProvider":"company","target":null,"deviceAuth":true})
);
Ok(())
}
+64 -33
View File
@@ -1940,23 +1940,6 @@ class GatewayOAuthCancelResponse(BaseModel):
)
class GatewayOAuthLoginParams(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
device_auth: Annotated[
bool | None,
Field(
alias="deviceAuth",
description="Select device authorization when the server advertises support for it.",
),
] = None
model_provider: Annotated[
str | None,
Field(alias="modelProvider", description="Defaults to the current provider when omitted."),
] = None
class GatewayOAuthPrompt(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
@@ -1983,6 +1966,22 @@ class GatewayOAuthStatus(Enum):
failed = "failed"
class ConfigServerGatewayOAuthTarget(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
kind: Literal["configServer"]
class GatewayOAuthTarget(RootModel[ConfigServerGatewayOAuthTarget]):
root: Annotated[
ConfigServerGatewayOAuthTarget,
Field(
description="An explicit service to authorize instead of the selected model provider."
),
]
class GcpProviderId(RootModel[Literal["gcp"]]):
root: Literal["gcp"]
@@ -3275,10 +3274,6 @@ class NonSteerableTurnKind(Enum):
compact = "compact"
class NullableGatewayOAuthLoginParams(RootModel[GatewayOAuthLoginParams | None]):
root: Annotated[GatewayOAuthLoginParams | None, Field(title="Nullable_GatewayOAuthLoginParams")]
class NullableGatewayOAuthReadParams(RootModel[GatewayOAuthReadParams | None]):
root: Annotated[GatewayOAuthReadParams | None, Field(title="Nullable_GatewayOAuthReadParams")]
@@ -5398,6 +5393,15 @@ class SpendControlLimitSnapshot(BaseModel):
used: str
class StartupGatewayOAuthChangedNotification(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
auth_url: Annotated[str, Field(alias="authUrl")]
status: GatewayOAuthStatus
target: GatewayOAuthTarget
class StrictReviewRequiredNotification(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
@@ -8275,18 +8279,6 @@ class AccountGatewayOAuthReadRequest(BaseModel):
params: GatewayOAuthReadParams | None = None
class AccountGatewayOAuthLoginRequest(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
id: RequestId
method: Annotated[
Literal["account/gatewayOAuth/login"],
Field(title="Account/gatewayOAuth/loginRequestMethod"),
]
params: GatewayOAuthLoginParams | None = None
class AccountGatewayOAuthCancelRequest(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
@@ -9210,6 +9202,29 @@ class GatewayOAuthChangedNotification(BaseModel):
status: GatewayOAuthStatus
class GatewayOAuthLoginParams(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
device_auth: Annotated[
bool | None,
Field(
alias="deviceAuth",
description="Select device authorization when the server advertises support for it.",
),
] = None
model_provider: Annotated[
str | None,
Field(alias="modelProvider", description="Defaults to the current provider when omitted."),
] = None
target: Annotated[
GatewayOAuthTarget | None,
Field(
description="Available only on `--startup-oauth`. Mutually exclusive with `modelProvider`."
),
] = None
class GatewayOAuthLoginResponse(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
@@ -9864,6 +9879,10 @@ class NewThreadModelDefaults(BaseModel):
service_tier: Annotated[str | None, Field(alias="serviceTier")] = None
class NullableGatewayOAuthLoginParams(RootModel[GatewayOAuthLoginParams | None]):
root: Annotated[GatewayOAuthLoginParams | None, Field(title="Nullable_GatewayOAuthLoginParams")]
class OtlpHttp(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
@@ -12002,6 +12021,18 @@ class ReviewStartRequest(BaseModel):
params: ReviewStartParams
class AccountGatewayOAuthLoginRequest(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
id: RequestId
method: Annotated[
Literal["account/gatewayOAuth/login"],
Field(title="Account/gatewayOAuth/loginRequestMethod"),
]
params: GatewayOAuthLoginParams | None = None
class ModelProviderConfigWriteRequest(BaseModel):
model_config = ConfigDict(
populate_by_name=True,