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
|
## First room
|
||||||
|
|
||||||
1. **Settings → Providers.** Add a provider kind, model, and key. Keys
|
1. **Settings → Providers.** Add a provider kind and key. The key is
|
||||||
are sealed with the server's master key before they touch SQLite.
|
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
|
2. **Settings → Sandboxes.** Add a target. Leave the private key empty
|
||||||
and the server generates an ed25519 pair and shows the public key.
|
and the server generates an ed25519 pair and shows the public key.
|
||||||
Append that line to `~/.ssh/authorized_keys` on the target. Set the
|
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.
|
- **Turn:** one agent run, started by a mention, made of steps.
|
||||||
- **Step:** one model exchange, the `Agent::step` primitive.
|
- **Step:** one model exchange, the `Agent::step` primitive.
|
||||||
- **Sandbox target:** an account's remote machine, reached over ssh.
|
- **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
|
"Room" is the product word. "Session" stays reserved for
|
||||||
`rhema_core::Session`, the model's memory, and for the login session.
|
`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 |
|
| workspace | the sandbox directory the room lives in |
|
||||||
| sandbox_target | the owner's ssh target |
|
| sandbox_target | the owner's ssh target |
|
||||||
| provider_config | whose model key pays |
|
| 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 |
|
| max_turn_steps | runaway guard, default 48 |
|
||||||
| created_at, archived_at | |
|
| created_at, archived_at | |
|
||||||
|
|
||||||
@@ -535,7 +535,9 @@ One SQLite file in WAL mode.
|
|||||||
```
|
```
|
||||||
accounts(id, handle, display_name, email, password_hash, created_at)
|
accounts(id, handle, display_name, email, password_hash, created_at)
|
||||||
auth_sessions(token_hash, account_id, created_at, expires_at, last_seen)
|
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,
|
sandbox_targets(id, account_id, name, host, user, port, key_ciphertext,
|
||||||
workspace_root, host_key, created_at)
|
workspace_root, host_key, created_at)
|
||||||
rooms(id, name, owner_id, workspace, cwd, sandbox_target_id,
|
rooms(id, name, owner_id, workspace, cwd, sandbox_target_id,
|
||||||
@@ -667,7 +669,8 @@ This repository, as committed:
|
|||||||
provider switch.
|
provider switch.
|
||||||
- A model picker over the provider's live catalog, with context,
|
- A model picker over the provider's live catalog, with context,
|
||||||
output, price, and vision from the adapter and models.dev. A custom
|
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
|
- One conversation per room, a `@rhema` mention starts a turn, human
|
||||||
messages are stamped with their author's name, and only the `message`
|
messages are stamped with their author's name, and only the `message`
|
||||||
tool puts agent text in the room.
|
tool puts agent text in the room.
|
||||||
|
|||||||
@@ -227,6 +227,9 @@ pub async fn create(
|
|||||||
.map(|model| model.trim().to_owned())
|
.map(|model| model.trim().to_owned())
|
||||||
.filter(|model| !model.is_empty())
|
.filter(|model| !model.is_empty())
|
||||||
.unwrap_or_else(|| provider_model.clone());
|
.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 now = now_ms();
|
||||||
{
|
{
|
||||||
let conn = state.db.conn();
|
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 struct CreateProvider {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub kind: 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,
|
pub model: String,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub base_url: Option<String>,
|
pub base_url: Option<String>,
|
||||||
@@ -79,10 +82,7 @@ pub async fn create_provider(
|
|||||||
if !KINDS.contains(&body.kind.as_str()) {
|
if !KINDS.contains(&body.kind.as_str()) {
|
||||||
return Err(AppError::bad_request("unknown provider kind"));
|
return Err(AppError::bad_request("unknown provider kind"));
|
||||||
}
|
}
|
||||||
let model = body.model.trim();
|
let model = body.model.trim().to_owned();
|
||||||
if model.is_empty() {
|
|
||||||
return Err(AppError::bad_request("a model id is required"));
|
|
||||||
}
|
|
||||||
let base_url = body
|
let base_url = body
|
||||||
.base_url
|
.base_url
|
||||||
.map(|url| url.trim().to_owned())
|
.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
|
let members = stmt
|
||||||
.query_map(rusqlite::params![room_id], |row| row.get::<_, String>(0))?
|
.query_map(rusqlite::params![room_id], |row| row.get::<_, String>(0))?
|
||||||
.collect::<Result<Vec<_>, _>>()?;
|
.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 {
|
Ok(TurnConfig {
|
||||||
room_id: room_id.to_owned(),
|
room_id: room_id.to_owned(),
|
||||||
room_name: name,
|
room_name: name,
|
||||||
workspace,
|
workspace,
|
||||||
repo_url,
|
repo_url,
|
||||||
model: room_model.unwrap_or_else(|| provider_model.clone()),
|
model,
|
||||||
max_turn_steps: max_steps.max(1) as u32,
|
max_turn_steps: max_steps.max(1) as u32,
|
||||||
absorbed_seq: absorbed,
|
absorbed_seq: absorbed,
|
||||||
seeded: seeded != 0,
|
seeded: seeded != 0,
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ function onSearchEnter() {
|
|||||||
|
|
||||||
<div v-else ref="listEl" class="model-list">
|
<div v-else ref="listEl" class="model-list">
|
||||||
<button
|
<button
|
||||||
|
v-if="provider.model"
|
||||||
type="button"
|
type="button"
|
||||||
class="model-row"
|
class="model-row"
|
||||||
:class="{ 'model-row-active': selected === '' }"
|
:class="{ 'model-row-active': selected === '' }"
|
||||||
|
|||||||
@@ -36,12 +36,19 @@ const pickerOpen = ref(false)
|
|||||||
const selectedProvider = computed(
|
const selectedProvider = computed(
|
||||||
() => providers.value.find((provider) => provider.id === providerId.value) ?? null,
|
() => providers.value.find((provider) => provider.id === providerId.value) ?? null,
|
||||||
)
|
)
|
||||||
|
const effectiveModel = computed(() => model.value.trim() || selectedProvider.value?.model || '')
|
||||||
|
|
||||||
const submitting = ref(false)
|
const submitting = ref(false)
|
||||||
const error = ref('')
|
const error = ref('')
|
||||||
|
|
||||||
const canSubmit = computed(
|
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(() => {
|
const missing = computed(() => {
|
||||||
@@ -94,7 +101,7 @@ async function submit() {
|
|||||||
}
|
}
|
||||||
if (workspace.value.trim()) body.workspace = workspace.value.trim()
|
if (workspace.value.trim()) body.workspace = workspace.value.trim()
|
||||||
if (repoUrl.value.trim()) body.repo_url = repoUrl.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 {
|
try {
|
||||||
const response = await api.post<CreateRoomResponse>('/rooms', body)
|
const response = await api.post<CreateRoomResponse>('/rooms', body)
|
||||||
await rooms.refresh()
|
await rooms.refresh()
|
||||||
@@ -159,7 +166,7 @@ async function submit() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<span class="field-label">Model <span class="field-optional">optional</span></span>
|
<span class="field-label">Model</span>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="model-trigger"
|
class="model-trigger"
|
||||||
@@ -170,12 +177,12 @@ async function submit() {
|
|||||||
@click="pickerOpen = true"
|
@click="pickerOpen = true"
|
||||||
>
|
>
|
||||||
<span class="model-trigger-value">
|
<span class="model-trigger-value">
|
||||||
<span class="model-trigger-name">{{ model || selectedProvider?.model || 'Select a model' }}</span>
|
<span class="model-trigger-name">{{ effectiveModel || 'Select a model' }}</span>
|
||||||
<span v-if="selectedProvider && !model" class="model-trigger-note">Provider default</span>
|
<span v-if="!model && selectedProvider?.model" class="model-trigger-note">Provider default</span>
|
||||||
</span>
|
</span>
|
||||||
<ChevronRight :size="16" aria-hidden="true" />
|
<ChevronRight :size="16" aria-hidden="true" />
|
||||||
</button>
|
</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>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ const pickerOpen = ref(false)
|
|||||||
const selectedProvider = computed(
|
const selectedProvider = computed(
|
||||||
() => providers.value.find((provider) => provider.id === providerId.value) ?? null,
|
() => providers.value.find((provider) => provider.id === providerId.value) ?? null,
|
||||||
)
|
)
|
||||||
|
const effectiveModel = computed(() => model.value.trim() || selectedProvider.value?.model || '')
|
||||||
|
|
||||||
const saving = ref(false)
|
const saving = ref(false)
|
||||||
const error = ref('')
|
const error = ref('')
|
||||||
@@ -37,7 +38,9 @@ const archiving = ref(false)
|
|||||||
const confirmingArchive = ref(false)
|
const confirmingArchive = ref(false)
|
||||||
const archiveError = ref('')
|
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 () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
@@ -138,12 +141,12 @@ async function archive() {
|
|||||||
@click="pickerOpen = true"
|
@click="pickerOpen = true"
|
||||||
>
|
>
|
||||||
<span class="model-trigger-value">
|
<span class="model-trigger-value">
|
||||||
<span class="model-trigger-name">{{ model || selectedProvider?.model || 'Select a model' }}</span>
|
<span class="model-trigger-name">{{ effectiveModel || 'Select a model' }}</span>
|
||||||
<span v-if="selectedProvider && !model" class="model-trigger-note">Provider default</span>
|
<span v-if="!model && selectedProvider?.model" class="model-trigger-note">Provider default</span>
|
||||||
</span>
|
</span>
|
||||||
<ChevronRight :size="16" aria-hidden="true" />
|
<ChevronRight :size="16" aria-hidden="true" />
|
||||||
</button>
|
</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>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ const loadError = ref('')
|
|||||||
|
|
||||||
const providerName = ref('')
|
const providerName = ref('')
|
||||||
const providerKind = ref('anthropic')
|
const providerKind = ref('anthropic')
|
||||||
const providerModel = ref('')
|
|
||||||
const providerBaseUrl = ref('')
|
const providerBaseUrl = ref('')
|
||||||
const providerKey = ref('')
|
const providerKey = ref('')
|
||||||
const providerBusy = ref(false)
|
const providerBusy = ref(false)
|
||||||
@@ -103,14 +102,12 @@ async function addProvider() {
|
|||||||
const body: CreateProviderBody = {
|
const body: CreateProviderBody = {
|
||||||
name: providerName.value.trim(),
|
name: providerName.value.trim(),
|
||||||
kind: providerKind.value,
|
kind: providerKind.value,
|
||||||
model: providerModel.value.trim(),
|
|
||||||
}
|
}
|
||||||
if (providerBaseUrl.value.trim()) body.base_url = providerBaseUrl.value.trim()
|
if (providerBaseUrl.value.trim()) body.base_url = providerBaseUrl.value.trim()
|
||||||
if (!llama.value) body.api_key = providerKey.value
|
if (!llama.value) body.api_key = providerKey.value
|
||||||
try {
|
try {
|
||||||
await api.post<IdResponse>('/provider-configs', body)
|
await api.post<IdResponse>('/provider-configs', body)
|
||||||
providerName.value = ''
|
providerName.value = ''
|
||||||
providerModel.value = ''
|
|
||||||
providerBaseUrl.value = ''
|
providerBaseUrl.value = ''
|
||||||
providerKey.value = ''
|
providerKey.value = ''
|
||||||
await loadLists()
|
await loadLists()
|
||||||
@@ -225,7 +222,7 @@ async function copyKey(target: SandboxTarget) {
|
|||||||
Add provider
|
Add provider
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</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>
|
<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-main">
|
||||||
<div class="settings-row-title">{{ provider.name }}</div>
|
<div class="settings-row-title">{{ provider.name }}</div>
|
||||||
<div class="settings-row-detail">
|
<div class="settings-row-detail">
|
||||||
{{ provider.kind }}, {{ provider.model }}
|
{{ provider.kind }}<template v-if="provider.base_url">, {{ provider.base_url }}</template>
|
||||||
<template v-if="provider.base_url">, {{ provider.base_url }}</template>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="settings-row-actions">
|
<div class="settings-row-actions">
|
||||||
@@ -284,11 +280,6 @@ async function copyKey(target: SandboxTarget) {
|
|||||||
</div>
|
</div>
|
||||||
</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">
|
<div class="field">
|
||||||
<label class="field-label" for="provider-base">
|
<label class="field-label" for="provider-base">
|
||||||
{{ llama ? 'Server URL' : 'Base URL' }}
|
{{ llama ? 'Server URL' : 'Base URL' }}
|
||||||
|
|||||||
+1
-1
@@ -173,7 +173,7 @@ export interface ProviderModelsResponse {
|
|||||||
export interface CreateProviderBody {
|
export interface CreateProviderBody {
|
||||||
name: string
|
name: string
|
||||||
kind: string
|
kind: string
|
||||||
model: string
|
model?: string
|
||||||
base_url?: string | null
|
base_url?: string | null
|
||||||
api_key?: string
|
api_key?: string
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user