feat: sign in to Copilot, ChatGPT, and Mistral Vibe

Three provider kinds have a browser sign-in, but the add-provider
dialog only accepted a pasted key. A per-account login record now runs
the adapter's InteractiveLogin on the server, reports the instruction,
URL, and code to the dialog, and stores the credential before the
browser sees completion. The credential never reaches the client.

The dialog gets a sign-in stage for flow kinds, with a link, a
copyable code, and retry after failure. Closing the dialog cancels the
flow. ChatGPT's callback lands on the server's loopback port, and the
instruction names the port to forward.
This commit is contained in:
vhaudiquet committed 2026-11-28 18:06:21 +01:00
1 parent 369075a842
commit f5087220da
12 files changed
+927 -23

No files matched your search

+38
View File
@@ -464,6 +464,44 @@ button {
line-height: var(--lh-body);
}
.signin {
display: flex;
flex-direction: column;
gap: var(--sp-4);
}
.signin .dialog-actions {
margin-top: 0;
}
.signin-actions {
display: flex;
flex-wrap: wrap;
gap: var(--sp-2);
}
.signin-link:hover {
text-decoration: none;
}
.signin-code {
display: flex;
flex-direction: column;
gap: var(--sp-1);
}
.signin-code-value {
align-self: flex-start;
padding: var(--sp-2) var(--sp-3);
border: 1px solid var(--border);
border-radius: var(--r-control);
background: var(--surface-2);
font-family: var(--font-mono);
font-size: var(--fs-code);
letter-spacing: 0.08em;
white-space: pre;
}
.form-note {
color: var(--muted);
font-size: var(--fs-meta);
+272 -12
View File
@@ -1,15 +1,17 @@
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { Check, Copy, Plus, Trash2 } from 'lucide-vue-next'
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
import { Check, Copy, ExternalLink, Plus, Trash2 } from 'lucide-vue-next'
import type {
CreateSandboxBody,
CreateSandboxResponse,
CreateProviderBody,
IdResponse,
LoginFlowStatus,
ProviderConfig,
ProviderListResponse,
SandboxListResponse,
SandboxTarget,
StartLoginResponse,
TestSandboxResponse,
} from '~/types'
import { apiErrorMessage } from '~/utils/errors'
@@ -19,8 +21,24 @@ useHead({ title: 'Settings · Rhema Together' })
const api = useApi()
const KIND_LABELS: Record<string, string> = {
anthropic: 'Anthropic',
openai: 'OpenAI',
openrouter: 'OpenRouter',
google: 'Google Gemini',
deepseek: 'DeepSeek',
zai: 'Z.ai',
mistral: 'Mistral API',
'mistral-vibe': 'Mistral Vibe',
copilot: 'GitHub Copilot',
chatgpt: 'ChatGPT',
opencode: 'OpenCode',
'llama-cpp': 'llama.cpp',
}
const providers = ref<ProviderConfig[]>([])
const kinds = ref<string[]>(['anthropic', 'openai', 'openrouter', 'google', 'deepseek', 'zai', 'mistral', 'mistral-vibe', 'opencode', 'llama-cpp'])
const kinds = ref<string[]>(['anthropic', 'openai', 'openrouter', 'google', 'deepseek', 'zai', 'mistral', 'mistral-vibe', 'copilot', 'chatgpt', 'opencode', 'llama-cpp'])
const flowKinds = ref<string[]>(['copilot', 'chatgpt', 'mistral-vibe'])
const targets = ref<SandboxTarget[]>([])
const loading = ref(true)
const loadError = ref('')
@@ -32,6 +50,48 @@ const providerKey = ref('')
const providerBusy = ref(false)
const providerError = ref('')
const llama = computed(() => providerKind.value === 'llama-cpp')
const flowKind = computed(() => flowKinds.value.includes(providerKind.value))
const kindName = computed(() => KIND_LABELS[providerKind.value] ?? providerKind.value)
const loginId = ref<string | null>(null)
const loginStatus = ref<LoginFlowStatus | null>(null)
const loginPollFailures = ref(0)
const copiedLoginCode = ref(false)
let loginTimer: ReturnType<typeof setTimeout> | null = null
let loginCopyTimer: ReturnType<typeof setTimeout> | null = null
let loginGeneration = 0
const providerDialogTitle = computed(() =>
loginId.value ? `Sign in to ${providerName.value.trim() || kindName.value}` : 'Add provider',
)
const providerDialogDescription = computed(() => {
if (loginId.value) {
if (loginStatus.value?.status === 'failed') return 'The sign-in did not finish. Try again or go back.'
return 'Finish the sign-in in your browser. This dialog updates on its own.'
}
if (flowKind.value) return 'Sign in with the provider. The credential stays sealed on the server.'
if (llama.value) return 'The server address is stored for this account.'
return 'The key stays sealed on the server and is never shown again.'
})
const loginUrl = computed(() => {
const url = loginStatus.value?.instruction?.url
return url && /^https?:\/\//i.test(url) ? url : null
})
const loginCode = computed(() => loginStatus.value?.instruction?.code ?? null)
const flowInstruction = computed(() => {
const instruction = loginStatus.value?.instruction
if (!instruction) return ''
switch (providerKind.value) {
case 'copilot':
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)
}
})
const sandboxName = ref('')
const sandboxHost = ref('')
@@ -63,6 +123,7 @@ async function loadLists() {
])
providers.value = providerList.providers
if (providerList.kinds.length > 0) kinds.value = providerList.kinds
if (providerList.flow_kinds.length > 0) flowKinds.value = providerList.flow_kinds
targets.value = targetList.targets
} catch (err) {
loadError.value = apiErrorMessage(err)
@@ -73,17 +134,171 @@ async function loadLists() {
onMounted(loadLists)
onBeforeUnmount(() => {
loginGeneration += 1
stopLoginPolling()
if (loginCopyTimer !== null) clearTimeout(loginCopyTimer)
const id = loginId.value
if (id) void api.del(`/provider-configs/login/${id}`).catch(() => {})
})
function openProviderDialog() {
providerError.value = ''
loginStatus.value = null
loginId.value = null
loginPollFailures.value = 0
copiedLoginCode.value = false
providerDialog.value = true
}
function closeProviderDialog() {
cancelLogin()
providerDialog.value = false
providerKey.value = ''
providerError.value = ''
}
function kindLabel(kind: string) {
return KIND_LABELS[kind] ?? kind
}
function sentence(text: string) {
return text ? text.charAt(0).toUpperCase() + text.slice(1) : text
}
function stopLoginPolling() {
if (loginTimer !== null) {
clearTimeout(loginTimer)
loginTimer = null
}
}
function cancelLogin() {
loginGeneration += 1
providerBusy.value = false
stopLoginPolling()
const id = loginId.value
loginId.value = null
loginStatus.value = null
loginPollFailures.value = 0
copiedLoginCode.value = false
if (loginCopyTimer !== null) {
clearTimeout(loginCopyTimer)
loginCopyTimer = null
}
if (id) void api.del(`/provider-configs/login/${id}`).catch(() => {})
}
function scheduleLoginPoll() {
stopLoginPolling()
loginTimer = window.setTimeout(() => {
void pollLogin()
}, 2000)
}
async function pollLogin() {
const id = loginId.value
if (!id) return
const generation = loginGeneration
try {
const status = await api.get<LoginFlowStatus>(`/provider-configs/login/${id}`)
if (loginId.value !== id || generation !== loginGeneration) return
loginPollFailures.value = 0
loginStatus.value = status
if (status.status === 'completed') {
stopLoginPolling()
loginId.value = null
loginStatus.value = null
providerName.value = ''
providerBaseUrl.value = ''
providerKey.value = ''
providerError.value = ''
if (id) void api.del(`/provider-configs/login/${id}`).catch(() => {})
providerDialog.value = false
await loadLists()
} else if (status.status === 'failed') {
stopLoginPolling()
} else {
scheduleLoginPoll()
}
} catch (err) {
if (loginId.value !== id || generation !== loginGeneration) return
loginPollFailures.value += 1
if (loginPollFailures.value >= 3) {
stopLoginPolling()
loginStatus.value = { status: 'failed', message: apiErrorMessage(err) }
} else {
scheduleLoginPoll()
}
}
}
async function startProviderLogin() {
if (providerBusy.value) return
const generation = ++loginGeneration
providerBusy.value = true
providerError.value = ''
stopLoginPolling()
const previous = loginId.value
loginId.value = null
loginStatus.value = null
loginPollFailures.value = 0
copiedLoginCode.value = false
if (previous) {
try {
await api.del(`/provider-configs/login/${previous}`)
} catch {
// The sweep drops an old record anyway; the new flow still starts.
}
}
if (generation !== loginGeneration) return
try {
const started = await api.post<StartLoginResponse>('/provider-configs/login', {
name: providerName.value.trim(),
kind: providerKind.value,
})
if (generation !== loginGeneration) {
void api.del(`/provider-configs/login/${started.id}`).catch(() => {})
return
}
loginId.value = started.id
loginStatus.value = { status: 'starting' }
scheduleLoginPoll()
} catch (err) {
if (generation === loginGeneration) providerError.value = apiErrorMessage(err)
} finally {
if (generation === loginGeneration) providerBusy.value = false
}
}
function backToProviderForm() {
cancelLogin()
providerError.value = ''
}
async function copyLoginCode() {
if (!loginCode.value) return
try {
await navigator.clipboard.writeText(loginCode.value)
providerError.value = ''
copiedLoginCode.value = true
if (loginCopyTimer !== null) clearTimeout(loginCopyTimer)
loginCopyTimer = window.setTimeout(() => {
copiedLoginCode.value = false
}, 1800)
} catch {
providerError.value = 'The clipboard is not available. Select the code and copy it by hand.'
}
}
async function submitProvider() {
if (flowKind.value) {
await startProviderLogin()
return
}
await addProvider()
}
function openSandboxDialog() {
sandboxError.value = ''
sandboxDialog.value = true
@@ -222,7 +437,7 @@ async function copyKey(target: SandboxTarget) {
Add provider
</button>
</div>
<p class="hint">A provider holds a backend and key. Each room picks a model from its provider.</p>
<p class="hint">A provider holds a backend and how to reach it. Each room picks a model from its provider.</p>
<div v-if="!loading && providers.length === 0" class="empty">No providers yet. Use Add provider to connect one.</div>
@@ -231,7 +446,7 @@ async function copyKey(target: SandboxTarget) {
<div class="settings-row-main">
<div class="settings-row-title">{{ provider.name }}</div>
<div class="settings-row-detail">
{{ provider.kind }}<template v-if="provider.base_url">, {{ provider.base_url }}</template>
{{ kindLabel(provider.kind) }}<template v-if="provider.base_url">, {{ provider.base_url }}</template>
</div>
</div>
<div class="settings-row-actions">
@@ -262,11 +477,11 @@ async function copyKey(target: SandboxTarget) {
<BaseDialog
v-if="providerDialog"
title="Add provider"
description="The key stays sealed on the server and is never shown again."
:title="providerDialogTitle"
:description="providerDialogDescription"
@close="closeProviderDialog"
>
<form class="form" @submit.prevent="addProvider">
<form v-if="!loginId" class="form" @submit.prevent="submitProvider">
<div class="form-grid">
<div class="field">
<label class="field-label" for="provider-name">Name</label>
@@ -275,12 +490,12 @@ async function copyKey(target: SandboxTarget) {
<div class="field">
<label class="field-label" for="provider-kind">Kind</label>
<select id="provider-kind" v-model="providerKind" class="select">
<option v-for="kind in kinds" :key="kind" :value="kind">{{ kind }}</option>
<option v-for="kind in kinds" :key="kind" :value="kind">{{ kindLabel(kind) }}</option>
</select>
</div>
</div>
<div class="field">
<div v-if="!flowKind" class="field">
<label class="field-label" for="provider-base">
{{ llama ? 'Server URL' : 'Base URL' }}
<span v-if="!llama" class="field-optional">optional</span>
@@ -297,7 +512,7 @@ async function copyKey(target: SandboxTarget) {
<span v-if="llama" class="hint">The address of the llama.cpp server.</span>
</div>
<div v-if="!llama" class="field">
<div v-if="!flowKind && !llama" class="field">
<label class="field-label" for="provider-key">API key</label>
<input
id="provider-key"
@@ -316,10 +531,55 @@ async function copyKey(target: SandboxTarget) {
<div class="dialog-actions">
<button type="button" class="btn" :disabled="providerBusy" @click="closeProviderDialog">Cancel</button>
<button type="submit" class="btn btn-primary" :disabled="providerBusy">
{{ providerBusy ? 'Adding' : 'Add provider' }}
{{ providerBusy ? (flowKind ? 'Starting' : 'Adding') : flowKind ? 'Sign in' : 'Add provider' }}
</button>
</div>
</form>
<div v-else class="signin" aria-live="polite">
<p v-if="!loginStatus || loginStatus.status === 'starting'" class="form-note">Starting sign-in.</p>
<template v-else>
<template v-if="loginStatus.status === 'instruct' || loginStatus.status === 'waiting'">
<p v-if="flowInstruction" class="form-note">{{ flowInstruction }}</p>
<div v-if="loginUrl || loginCode" class="signin-actions">
<a
v-if="loginUrl"
class="btn btn-primary signin-link"
:href="loginUrl"
target="_blank"
rel="noopener noreferrer"
>
Open sign-in page
<ExternalLink :size="14" aria-hidden="true" />
</a>
<button v-if="loginCode" type="button" class="btn" @click="copyLoginCode">
<component :is="copiedLoginCode ? Check : Copy" :size="14" aria-hidden="true" />
{{ copiedLoginCode ? 'Copied' : 'Copy code' }}
</button>
</div>
<div v-if="loginCode" class="signin-code">
<span class="field-label">Code</span>
<code class="signin-code-value">{{ loginCode }}</code>
</div>
<p v-if="loginStatus.message" class="form-note">{{ sentence(loginStatus.message) }}</p>
<p v-else class="form-note">Waiting for you to finish in the browser.</p>
</template>
<p v-else-if="loginStatus.status === 'failed'" class="form-error" role="alert">
{{ sentence(loginStatus.message ?? 'The sign-in failed.') }}
</p>
<p v-if="providerError" class="form-error" role="alert">{{ providerError }}</p>
</template>
<div class="dialog-actions">
<template v-if="loginStatus?.status === 'failed'">
<button type="button" class="btn" @click="backToProviderForm">Back</button>
<button type="button" class="btn btn-primary" :disabled="providerBusy" @click="startProviderLogin">
Try again
</button>
</template>
<button v-else type="button" class="btn" @click="closeProviderDialog">Cancel</button>
</div>
</div>
</BaseDialog>
</section>
+20
View File
@@ -144,6 +144,26 @@ export interface ProviderConfig {
export interface ProviderListResponse {
providers: ProviderConfig[]
kinds: string[]
flow_kinds: string[]
}
export interface LoginInstruction {
text: string
url: string | null
code: string | null
}
export type LoginFlowPhase = 'starting' | 'instruct' | 'waiting' | 'completed' | 'failed'
export interface LoginFlowStatus {
status: LoginFlowPhase
instruction?: LoginInstruction
message?: string
provider_id?: string
}
export interface StartLoginResponse {
id: string
}
export interface ModelPricing {