feat: add providers without a default model
The add-provider form asked for a model even though the room owns that choice. It now asks for a name, kind, base URL, and key. New providers store no default, and New room requires a model before it can submit. Existing providers keep their model as an optional default. The model picker hides the Provider default row when there is none, and a room with no usable model gets a clear error instead of an empty model reaching the provider.
This commit is contained in:
1 parent
2216f37422
commit
369075a842
10 files changed
+48
-33
No files matched your search
@@ -102,8 +102,9 @@ issue certificates.
|
||||
|
||||
## First room
|
||||
|
||||
1. **Settings → Providers.** Add a provider kind, model, and key. Keys
|
||||
are sealed with the server's master key before they touch SQLite.
|
||||
1. **Settings → Providers.** Add a provider kind and key. The key 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
|
||||
|
||||
@@ -38,7 +38,7 @@ later, it can move into a crate the way `rhema-cloud-agent` did.
|
||||
- **Turn:** one agent run, started by a mention, made of steps.
|
||||
- **Step:** one model exchange, the `Agent::step` primitive.
|
||||
- **Sandbox target:** an account's remote machine, reached over ssh.
|
||||
- **Provider config:** an account's model backend, model id, and key.
|
||||
- **Provider config:** an account's model backend and key.
|
||||
|
||||
"Room" is the product word. "Session" stays reserved for
|
||||
`rhema_core::Session`, the model's memory, and for the login session.
|
||||
@@ -56,7 +56,7 @@ A room holds:
|
||||
| workspace | the sandbox directory the room lives in |
|
||||
| sandbox_target | the owner's ssh target |
|
||||
| provider_config | whose model key pays |
|
||||
| model | model id, may change per room |
|
||||
| model | model id chosen for this room |
|
||||
| max_turn_steps | runaway guard, default 48 |
|
||||
| created_at, archived_at | |
|
||||
|
||||
@@ -535,7 +535,9 @@ One SQLite file in WAL mode.
|
||||
```
|
||||
accounts(id, handle, display_name, email, password_hash, created_at)
|
||||
auth_sessions(token_hash, account_id, created_at, expires_at, last_seen)
|
||||
provider_configs(id, account_id, kind, model, base_url, key_ciphertext)
|
||||
provider_configs(id, account_id, name, kind, model, base_url, key_ciphertext)
|
||||
-- model is an optional default kept for existing rows; rooms carry
|
||||
-- the model that turns use
|
||||
sandbox_targets(id, account_id, name, host, user, port, key_ciphertext,
|
||||
workspace_root, host_key, created_at)
|
||||
rooms(id, name, owner_id, workspace, cwd, sandbox_target_id,
|
||||
@@ -667,7 +669,8 @@ This repository, as committed:
|
||||
provider switch.
|
||||
- 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.
|
||||
id is always accepted. Adding a provider asks for its kind and key;
|
||||
the room chooses the model.
|
||||
- One conversation per room, a `@rhema` mention starts a turn, human
|
||||
messages are stamped with their author's name, and only the `message`
|
||||
tool puts agent text in the room.
|
||||
|
||||
@@ -227,6 +227,9 @@ pub async fn create(
|
||||
.map(|model| model.trim().to_owned())
|
||||
.filter(|model| !model.is_empty())
|
||||
.unwrap_or_else(|| provider_model.clone());
|
||||
if model.trim().is_empty() {
|
||||
return Err(AppError::bad_request("pick a model for the room"));
|
||||
}
|
||||
let now = now_ms();
|
||||
{
|
||||
let conn = state.db.conn();
|
||||
|
||||
+4
-4
@@ -55,6 +55,9 @@ pub async fn list_providers(user: AuthUser, State(state): State<Shared>) -> AppR
|
||||
pub struct CreateProvider {
|
||||
pub name: String,
|
||||
pub kind: String,
|
||||
/// An optional default for older clients. The room picks the model
|
||||
/// it uses, so the add-provider form leaves this empty.
|
||||
#[serde(default)]
|
||||
pub model: String,
|
||||
#[serde(default)]
|
||||
pub base_url: Option<String>,
|
||||
@@ -79,10 +82,7 @@ pub async fn create_provider(
|
||||
if !KINDS.contains(&body.kind.as_str()) {
|
||||
return Err(AppError::bad_request("unknown provider kind"));
|
||||
}
|
||||
let model = body.model.trim();
|
||||
if model.is_empty() {
|
||||
return Err(AppError::bad_request("a model id is required"));
|
||||
}
|
||||
let model = body.model.trim().to_owned();
|
||||
let base_url = body
|
||||
.base_url
|
||||
.map(|url| url.trim().to_owned())
|
||||
|
||||
+7
-1
@@ -129,12 +129,18 @@ pub fn load_turn_config(state: &Shared, room_id: &str) -> AppResult<TurnConfig>
|
||||
let members = stmt
|
||||
.query_map(rusqlite::params![room_id], |row| row.get::<_, String>(0))?
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
let model = room_model
|
||||
.filter(|model| !model.trim().is_empty())
|
||||
.unwrap_or(provider_model);
|
||||
if model.trim().is_empty() {
|
||||
return Err(AppError::bad_request("room has no model selected"));
|
||||
}
|
||||
Ok(TurnConfig {
|
||||
room_id: room_id.to_owned(),
|
||||
room_name: name,
|
||||
workspace,
|
||||
repo_url,
|
||||
model: room_model.unwrap_or_else(|| provider_model.clone()),
|
||||
model,
|
||||
max_turn_steps: max_steps.max(1) as u32,
|
||||
absorbed_seq: absorbed,
|
||||
seeded: seeded != 0,
|
||||
|
||||
@@ -127,6 +127,7 @@ function onSearchEnter() {
|
||||
|
||||
<div v-else ref="listEl" class="model-list">
|
||||
<button
|
||||
v-if="provider.model"
|
||||
type="button"
|
||||
class="model-row"
|
||||
:class="{ 'model-row-active': selected === '' }"
|
||||
|
||||
@@ -36,12 +36,19 @@ const pickerOpen = ref(false)
|
||||
const selectedProvider = computed(
|
||||
() => providers.value.find((provider) => provider.id === providerId.value) ?? null,
|
||||
)
|
||||
const effectiveModel = computed(() => model.value.trim() || selectedProvider.value?.model || '')
|
||||
|
||||
const submitting = ref(false)
|
||||
const error = ref('')
|
||||
|
||||
const canSubmit = computed(
|
||||
() => !loading.value && !submitting.value && !!name.value.trim() && !!providerId.value && !!targetId.value,
|
||||
() =>
|
||||
!loading.value &&
|
||||
!submitting.value &&
|
||||
!!name.value.trim() &&
|
||||
!!providerId.value &&
|
||||
!!targetId.value &&
|
||||
!!effectiveModel.value,
|
||||
)
|
||||
|
||||
const missing = computed(() => {
|
||||
@@ -94,7 +101,7 @@ async function submit() {
|
||||
}
|
||||
if (workspace.value.trim()) body.workspace = workspace.value.trim()
|
||||
if (repoUrl.value.trim()) body.repo_url = repoUrl.value.trim()
|
||||
if (model.value.trim()) body.model = model.value.trim()
|
||||
body.model = effectiveModel.value
|
||||
try {
|
||||
const response = await api.post<CreateRoomResponse>('/rooms', body)
|
||||
await rooms.refresh()
|
||||
@@ -159,7 +166,7 @@ async function submit() {
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<span class="field-label">Model <span class="field-optional">optional</span></span>
|
||||
<span class="field-label">Model</span>
|
||||
<button
|
||||
type="button"
|
||||
class="model-trigger"
|
||||
@@ -170,12 +177,12 @@ async function submit() {
|
||||
@click="pickerOpen = true"
|
||||
>
|
||||
<span class="model-trigger-value">
|
||||
<span class="model-trigger-name">{{ model || selectedProvider?.model || 'Select a model' }}</span>
|
||||
<span v-if="selectedProvider && !model" class="model-trigger-note">Provider default</span>
|
||||
<span class="model-trigger-name">{{ effectiveModel || 'Select a model' }}</span>
|
||||
<span v-if="!model && selectedProvider?.model" class="model-trigger-note">Provider default</span>
|
||||
</span>
|
||||
<ChevronRight :size="16" aria-hidden="true" />
|
||||
</button>
|
||||
<span class="hint">The room uses the provider's model unless you pick another.</span>
|
||||
<span class="hint">{{ effectiveModel ? 'The room uses this model for every turn.' : 'Pick a model for the room.' }}</span>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
|
||||
@@ -30,6 +30,7 @@ const pickerOpen = ref(false)
|
||||
const selectedProvider = computed(
|
||||
() => providers.value.find((provider) => provider.id === providerId.value) ?? null,
|
||||
)
|
||||
const effectiveModel = computed(() => model.value.trim() || selectedProvider.value?.model || '')
|
||||
|
||||
const saving = ref(false)
|
||||
const error = ref('')
|
||||
@@ -37,7 +38,9 @@ const archiving = ref(false)
|
||||
const confirmingArchive = ref(false)
|
||||
const archiveError = ref('')
|
||||
|
||||
const canSave = computed(() => !saving.value && name.value.trim().length > 0)
|
||||
const canSave = computed(
|
||||
() => !saving.value && name.value.trim().length > 0 && !!effectiveModel.value,
|
||||
)
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
@@ -138,12 +141,12 @@ async function archive() {
|
||||
@click="pickerOpen = true"
|
||||
>
|
||||
<span class="model-trigger-value">
|
||||
<span class="model-trigger-name">{{ model || selectedProvider?.model || 'Select a model' }}</span>
|
||||
<span v-if="selectedProvider && !model" class="model-trigger-note">Provider default</span>
|
||||
<span class="model-trigger-name">{{ effectiveModel || 'Select a model' }}</span>
|
||||
<span v-if="!model && selectedProvider?.model" class="model-trigger-note">Provider default</span>
|
||||
</span>
|
||||
<ChevronRight :size="16" aria-hidden="true" />
|
||||
</button>
|
||||
<span class="hint">The room uses the provider's model unless you pick another.</span>
|
||||
<span class="hint">{{ effectiveModel ? 'The room uses this model for every turn.' : 'Pick a model before saving the room.' }}</span>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
|
||||
@@ -27,7 +27,6 @@ const loadError = ref('')
|
||||
|
||||
const providerName = ref('')
|
||||
const providerKind = ref('anthropic')
|
||||
const providerModel = ref('')
|
||||
const providerBaseUrl = ref('')
|
||||
const providerKey = ref('')
|
||||
const providerBusy = ref(false)
|
||||
@@ -103,14 +102,12 @@ async function addProvider() {
|
||||
const body: CreateProviderBody = {
|
||||
name: providerName.value.trim(),
|
||||
kind: providerKind.value,
|
||||
model: providerModel.value.trim(),
|
||||
}
|
||||
if (providerBaseUrl.value.trim()) body.base_url = providerBaseUrl.value.trim()
|
||||
if (!llama.value) body.api_key = providerKey.value
|
||||
try {
|
||||
await api.post<IdResponse>('/provider-configs', body)
|
||||
providerName.value = ''
|
||||
providerModel.value = ''
|
||||
providerBaseUrl.value = ''
|
||||
providerKey.value = ''
|
||||
await loadLists()
|
||||
@@ -225,7 +222,7 @@ async function copyKey(target: SandboxTarget) {
|
||||
Add provider
|
||||
</button>
|
||||
</div>
|
||||
<p class="hint">A provider holds the model backend and key. Rooms spend from the provider their owner picks.</p>
|
||||
<p class="hint">A provider holds a backend and key. 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>
|
||||
|
||||
@@ -234,8 +231,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 }}, {{ provider.model }}
|
||||
<template v-if="provider.base_url">, {{ provider.base_url }}</template>
|
||||
{{ provider.kind }}<template v-if="provider.base_url">, {{ provider.base_url }}</template>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settings-row-actions">
|
||||
@@ -284,11 +280,6 @@ async function copyKey(target: SandboxTarget) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="field-label" for="provider-model">Model</label>
|
||||
<input id="provider-model" v-model="providerModel" class="input" type="text" spellcheck="false" required>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="field-label" for="provider-base">
|
||||
{{ llama ? 'Server URL' : 'Base URL' }}
|
||||
|
||||
+1
-1
@@ -173,7 +173,7 @@ export interface ProviderModelsResponse {
|
||||
export interface CreateProviderBody {
|
||||
name: string
|
||||
kind: string
|
||||
model: string
|
||||
model?: string
|
||||
base_url?: string | null
|
||||
api_key?: string
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user