From 64d7f359f521bb47504a99c507496a9947326594 Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Thu, 3 Dec 2026 16:10:14 +0100 Subject: [PATCH] feat(api): retire ChatGPT plan sign-in by default A room's provider serves every member, while a ChatGPT plan belongs to one account, so sharing it breaks OpenAI's terms. Together now hides the chatgpt kind, refuses to store a new one, and fails a room that still points at it with a message that names the API-key route. Existing provider rows stay in the database. The room settings dialog keeps the room's current provider visible even when its kind is retired, so the room shows what it is pinned to instead of silently losing it. Creating or updating a room to that provider is refused. `RHEMA_TOGETHER_I_WANT_CHATGPT_BAN=1` lifts the block for a single-user local test. The value has to be exactly `1`; any other value leaves the block in place. --- README.md | 11 ++- specs/rhema-together.md | 16 ++-- src/api/rooms.rs | 32 +++++-- src/api/settings.rs | 101 ++++++++++++++++++++-- src/room/agent.rs | 4 + web/app/components/NewRoomDialog.vue | 3 +- web/app/components/RoomSettingsDialog.vue | 16 +++- web/app/pages/settings.vue | 8 +- 8 files changed, 157 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index b2995b4..ee883ea 100644 --- a/README.md +++ b/README.md @@ -104,10 +104,13 @@ issue certificates. ## First room 1. **Settings → Providers.** Add a provider kind and its key, address, - or sign-in. For GitHub Copilot, ChatGPT, and Mistral Vibe the dialog - runs the provider's sign-in. The credential is sealed with the - server's master key before it touches SQLite. A new provider stores - no model; the room picks one. + or sign-in. For GitHub Copilot and Mistral Vibe the dialog runs the + provider's sign-in. Together does not offer ChatGPT plan sign-in; + use the openai kind with an API key instead. Set + `RHEMA_TOGETHER_I_WANT_CHATGPT_BAN=1` to lift the block for a + single-user local test; a shared room still breaks OpenAI's terms. + The credential is sealed with the server's master key before it + touches SQLite. A new provider stores no model; the room picks one. 2. **Settings → Sandboxes.** Add a target. Leave the private key empty and the server generates an ed25519 pair and shows the public key. Append that line to `~/.ssh/authorized_keys` on the target. Set the diff --git a/specs/rhema-together.md b/specs/rhema-together.md index ff1ab15..83ab823 100644 --- a/specs/rhema-together.md +++ b/specs/rhema-together.md @@ -600,7 +600,7 @@ it. No route, log line, or event carries a stored key. ### Provider sign-in -GitHub Copilot, ChatGPT, and Mistral Vibe do not ask for a key. The +GitHub Copilot and Mistral Vibe do not ask for a key. The server runs the adapter's `InteractiveLogin` and keeps a per-account record of its last update. The browser asks the server to start the flow, polls the record, and renders the instruction, URL, and code. It @@ -612,10 +612,14 @@ their owner can read or cancel them. They live in memory, so a restart drops a sign-in in progress. No provider row exists until the adapter completes. -ChatGPT's callback returns to loopback port 1455, or 1457 when 1455 is -taken. The machine that runs the browser must forward that port to the -server before opening the URL. Copilot's device code and Mistral Vibe's -console sign-in need no inbound port. +Together does not offer ChatGPT plan sign-in by default. A ChatGPT +subscription is personal, and a room's provider serves every member, +so a shared room uses an API-key kind such as `openai`. Existing +`chatgpt` provider rows stay in the database but fail with a clear +message, and neither a new room nor a room settings change can point +at that kind. Setting `RHEMA_TOGETHER_I_WANT_CHATGPT_BAN=1` lifts the +block for a single-user local test; it does not make a shared room +compliant. A sign-in URL can carry a short-lived device or PKCE token. The server does not log it, and it is not the stored provider key. @@ -775,7 +779,7 @@ This repository, as committed: - A model picker over the provider's live catalog, with context, output, price, and vision from the adapter and models.dev. A custom id is always accepted. The add-provider dialog asks for a kind and - key, or runs a sign-in for GitHub Copilot, ChatGPT, and Mistral Vibe. + key, or runs a sign-in for GitHub Copilot and Mistral Vibe. An OpenAI provider also takes a base URL and an explicit chat completions or responses API, so one kind reaches OpenAI itself and any compatible server. The room chooses the model. diff --git a/src/api/rooms.rs b/src/api/rooms.rs index a075b2c..29d025d 100644 --- a/src/api/rooms.rs +++ b/src/api/rooms.rs @@ -8,6 +8,7 @@ use rhema_core::request::ThinkingEffort; use serde::Deserialize; use serde_json::{Value, json}; +use crate::api::settings::retired_kind; use crate::auth::{self, AuthUser, clean_display_name}; use crate::error::{AppError, AppResult}; use crate::models::{Member, Room, RoomSummary, User}; @@ -179,13 +180,19 @@ pub async fn create( "room name must be 1 to 60 characters", )); } - let (provider_model, provider_owner) = state + let (provider_model, provider_owner, provider_kind) = state .db .conn() .query_row( - "SELECT model, account_id FROM provider_configs WHERE id = ?1", + "SELECT model, account_id, kind FROM provider_configs WHERE id = ?1", rusqlite::params![body.provider_config_id], - |row| Ok((row.get::<_, String>(0)?, row.get::<_, String>(1)?)), + |row| { + Ok(( + row.get::<_, String>(0)?, + row.get::<_, String>(1)?, + row.get::<_, String>(2)?, + )) + }, ) .map_err(|_| AppError::bad_request("provider configuration not found"))?; if provider_owner != user.user.id { @@ -193,6 +200,9 @@ pub async fn create( "that provider belongs to another account", )); } + if let Some(message) = retired_kind(&provider_kind) { + return Err(AppError::bad_request(message)); + } let (workspace_root, target_owner) = state .db .conn() @@ -326,19 +336,27 @@ pub async fn update( )?; } if let Some(provider_id) = body.provider_config_id.as_deref() { - let owner: Option = state + let provider: Option<(String, String)> = state .db .conn() .query_row( - "SELECT account_id FROM provider_configs WHERE id = ?1", + "SELECT account_id, kind FROM provider_configs WHERE id = ?1", rusqlite::params![provider_id], - |row| row.get(0), + |row| Ok((row.get(0)?, row.get(1)?)), ) .ok(); - if owner.as_deref() != Some(user.user.id.as_str()) { + let Some((owner, kind)) = provider else { return Err(AppError::forbidden( "that provider belongs to another account", )); + }; + if owner != user.user.id { + return Err(AppError::forbidden( + "that provider belongs to another account", + )); + } + if let Some(message) = retired_kind(&kind) { + return Err(AppError::bad_request(message)); } state.db.conn().execute( "UPDATE rooms SET provider_config_id = ?1 WHERE id = ?2", diff --git a/src/api/settings.rs b/src/api/settings.rs index 977f7c0..13f24b3 100644 --- a/src/api/settings.rs +++ b/src/api/settings.rs @@ -28,15 +28,76 @@ const KINDS: &[&str] = &[ "mistral", "mistral-vibe", "copilot", - "chatgpt", "opencode", "llama-cpp", ]; -/// Kinds whose credential comes from a browser sign-in instead of a -/// pasted key. The adapter owns the protocol; the server owns the -/// record the browser polls and stores the token it produces. -pub const FLOW_KINDS: &[&str] = &["copilot", "chatgpt", "mistral-vibe"]; +/// Whether the operator lifted the ChatGPT block. Off by default: +/// Together serves one plan to every room member, which OpenAI's terms +/// do not allow for a shared room. A single-user local test can set +/// `RHEMA_TOGETHER_I_WANT_CHATGPT_BAN=1`; the name keeps the ban, so +/// the default reads as banned and `1` as lifted. +fn chatgpt_enabled() -> bool { + std::env::var("RHEMA_TOGETHER_I_WANT_CHATGPT_BAN") + .ok() + .as_deref() + .is_some_and(enabled_value) +} + +fn enabled_value(value: &str) -> bool { + value == "1" +} + +/// The provider kinds the add dialog offers. ChatGPT joins the list +/// only when the operator lifted its block. +fn kinds() -> Vec<&'static str> { + let mut kinds = KINDS.to_vec(); + if chatgpt_enabled() { + kinds.push("chatgpt"); + } + kinds +} + +/// The kinds whose credential comes from a browser sign-in. The +/// adapter owns the protocol; the server owns the record the browser +/// polls and stores the token it produces. +pub const FLOW_KINDS: &[&str] = &["copilot", "mistral-vibe"]; + +/// The flow kinds the add dialog offers, with ChatGPT only when its +/// block is lifted. +fn flow_kinds() -> Vec<&'static str> { + let mut kinds = FLOW_KINDS.to_vec(); + if chatgpt_enabled() { + kinds.push("chatgpt"); + } + kinds +} + +/// Whether `kind` may be stored. `KINDS` is the base list; ChatGPT is +/// accepted only with the operator's opt-in. +fn kind_allowed(kind: &str) -> bool { + kind_allowed_with(kind, chatgpt_enabled()) +} + +fn kind_allowed_with(kind: &str, chatgpt: bool) -> bool { + KINDS.contains(&kind) || (kind == "chatgpt" && chatgpt) +} + +/// Kinds Together has retired. Existing rows stay so a room that +/// points at one fails with this message instead of losing its +/// configuration. +pub(crate) fn retired_kind(kind: &str) -> Option<&'static str> { + retired_kind_with(kind, chatgpt_enabled()) +} + +fn retired_kind_with(kind: &str, chatgpt: bool) -> Option<&'static str> { + match kind { + "chatgpt" if !chatgpt => Some( + "ChatGPT plan sign-in is not available in Together. Add an API-key provider and point the room at it, or set RHEMA_TOGETHER_I_WANT_CHATGPT_BAN=1 for a single-user local test.", + ), + _ => None, + } +} /// The caller's provider configurations. pub async fn list_providers(user: AuthUser, State(state): State) -> AppResult> { @@ -58,8 +119,8 @@ pub async fn list_providers(user: AuthUser, State(state): State) -> AppR let configs = rows.collect::, _>>()?; Ok(Json(json!({ "providers": configs, - "kinds": KINDS, - "flow_kinds": FLOW_KINDS, + "kinds": kinds(), + "flow_kinds": flow_kinds(), }))) } @@ -94,7 +155,7 @@ pub async fn create_provider( if name.is_empty() || name.chars().count() > 60 { return Err(AppError::bad_request("name must be 1 to 60 characters")); } - if !KINDS.contains(&body.kind.as_str()) { + if !kind_allowed(&body.kind) { return Err(AppError::bad_request("unknown provider kind")); } let model = body.model.trim().to_owned(); @@ -193,7 +254,7 @@ fn login_flow(kind: &str) -> Option> { "copilot" => Some(Box::new(rhema_provider_copilot::CopilotLogin::new())), // The ChatGPT callback lands on the server's loopback port; a // server cannot open the user's browser for them. - "chatgpt" => Some(Box::new( + "chatgpt" if chatgpt_enabled() => Some(Box::new( rhema_provider_chatgpt::ChatGptLogin::new().with_open_browser(false), )), "mistral-vibe" => Some(Box::new(rhema_provider_mistral::MistralVibeLogin::new())), @@ -311,6 +372,9 @@ pub async fn list_provider_models( rusqlite::Error::QueryReturnedNoRows => AppError::not_found("provider not found"), other => other.into(), })?; + if let Some(message) = retired_kind(&kind) { + return Err(AppError::bad_request(message)); + } let key = state.secrets.open_str(&ciphertext)?; let llama_url = (kind == "llama-cpp") .then_some(base_url.as_deref()) @@ -622,6 +686,25 @@ mod tests { } } + #[test] + fn chatgpt_is_retired_until_the_operator_opts_in() { + assert!(retired_kind_with("chatgpt", false).is_some()); + assert!(retired_kind_with("chatgpt", true).is_none()); + assert!(retired_kind_with("openai", false).is_none()); + assert!(!KINDS.contains(&"chatgpt")); + assert!(!FLOW_KINDS.contains(&"chatgpt")); + assert!(!kind_allowed_with("chatgpt", false)); + assert!(kind_allowed_with("chatgpt", true)); + } + + #[test] + fn only_one_lifts_the_block() { + assert!(enabled_value("1")); + assert!(!enabled_value("0")); + assert!(!enabled_value("true")); + assert!(!enabled_value("")); + } + #[test] fn a_keyed_kind_has_no_login_flow() { assert!(login_flow("anthropic").is_none()); diff --git a/src/room/agent.rs b/src/room/agent.rs index 91a2f6a..ac31800 100644 --- a/src/room/agent.rs +++ b/src/room/agent.rs @@ -13,6 +13,7 @@ use rhema_host_agent::{HostAgent, HostAgentConfig, Steering}; use rhema_sandbox::WorkspaceSeed; use rhema_sandbox::{Sandbox, ShellSandbox}; +use crate::api::settings::retired_kind; use crate::error::{AppError, AppResult}; use crate::state::Shared; @@ -116,6 +117,9 @@ pub fn load_turn_config(state: &Shared, room_id: &str) -> AppResult )) }, )?; + if let Some(message) = retired_kind(&kind) { + return Err(AppError::bad_request(message)); + } let target = conn.query_row( "SELECT id, host, port, user_name, private_key_ciphertext, host_fingerprint FROM sandbox_targets WHERE id = ?1", diff --git a/web/app/components/NewRoomDialog.vue b/web/app/components/NewRoomDialog.vue index 3b5ef85..10238e4 100644 --- a/web/app/components/NewRoomDialog.vue +++ b/web/app/components/NewRoomDialog.vue @@ -67,7 +67,8 @@ onMounted(async () => { api.get('/provider-configs'), api.get('/sandbox-targets'), ]) - providers.value = providerList.providers + const known = new Set(providerList.kinds) + providers.value = providerList.providers.filter((provider) => known.has(provider.kind)) targets.value = targetList.targets providerId.value = providers.value[0]?.id ?? '' targetId.value = targets.value[0]?.id ?? '' diff --git a/web/app/components/RoomSettingsDialog.vue b/web/app/components/RoomSettingsDialog.vue index e250ea0..5bfcfac 100644 --- a/web/app/components/RoomSettingsDialog.vue +++ b/web/app/components/RoomSettingsDialog.vue @@ -19,6 +19,7 @@ const emit = defineEmits<{ close: []; updated: [room: Room]; archived: [] }>() const api = useApi() const providers = ref([]) +const providerKinds = ref([]) const loadingProviders = ref(true) const providersError = ref('') @@ -47,7 +48,13 @@ const canSave = computed( onMounted(async () => { try { const list = await api.get('/provider-configs') - providers.value = list.providers + // Keep the room's current provider even when the server no longer + // offers its kind, so the select shows what the room is pinned to. + const known = new Set(list.kinds) + providerKinds.value = list.kinds + providers.value = list.providers.filter( + (provider) => known.has(provider.kind) || provider.id === providerId.value, + ) } catch (err) { providersError.value = apiErrorMessage(err) } finally { @@ -74,7 +81,9 @@ async function save() { thinking_effort: thinkingEffort.value, max_turn_steps: Math.min(500, Math.max(1, Math.round(Number(maxSteps.value) || 1))), } - if (providerId.value) body.provider_config_id = providerId.value + if (providerId.value && providerId.value !== props.room.provider_config_id) { + body.provider_config_id = providerId.value + } body.model = model.value.trim() try { const response = await api.patch(`/rooms/${props.room.id}`, body) @@ -130,6 +139,9 @@ async function archive() { No providers yet. Add one in settings. + + This provider is no longer available. Pick another before the room can run a turn. +
diff --git a/web/app/pages/settings.vue b/web/app/pages/settings.vue index 200ed28..877c3e2 100644 --- a/web/app/pages/settings.vue +++ b/web/app/pages/settings.vue @@ -37,8 +37,8 @@ const KIND_LABELS: Record = { } const providers = ref([]) -const kinds = ref(['anthropic', 'openai', 'openrouter', 'google', 'deepseek', 'zai', 'mistral', 'mistral-vibe', 'copilot', 'chatgpt', 'opencode', 'llama-cpp']) -const flowKinds = ref(['copilot', 'chatgpt', 'mistral-vibe']) +const kinds = ref(['anthropic', 'openai', 'openrouter', 'google', 'deepseek', 'zai', 'mistral', 'mistral-vibe', 'copilot', 'opencode', 'llama-cpp']) +const flowKinds = ref(['copilot', 'mistral-vibe']) const targets = ref([]) const loading = ref(true) const loadError = ref('') @@ -88,8 +88,6 @@ const flowInstruction = computed(() => { return 'Enter the code on GitHub to authorize Rhema.' case 'mistral-vibe': return 'Sign in with your Mistral account to authorize Rhema for your Vibe plan.' - case 'chatgpt': - return sentence(instruction.text) default: return sentence(instruction.text) } @@ -450,7 +448,7 @@ async function copyKey(target: SandboxTarget) {
{{ provider.name }}
- {{ kindLabel(provider.kind) }} + {{ kindLabel(provider.kind) }}