room: add a per-room thinking effort
ci / checks (push) Successful in 52s
ci / test (push) Successful in 1m9s
ci / chart (push) Successful in 6s
ci / web (push) Successful in 19s
ci / docker (push) Successful in 2m0s
ci / publish-edge-image (push) Successful in 12s
ci / publish-edge-chart (push) Successful in 4s
ci / checks (push) Successful in 52s
ci / test (push) Successful in 1m9s
ci / chart (push) Successful in 6s
ci / web (push) Successful in 19s
ci / docker (push) Successful in 2m0s
ci / publish-edge-image (push) Successful in 12s
ci / publish-edge-chart (push) Successful in 4s
Every turn sent ThinkingEffort::Default, so a room could not ask for more or less reasoning. The owner now picks default, low, medium, or high in room settings. An existing database gains the column with a default of 'default', which sends no effort parameter and leaves the provider's choice alone.
This commit is contained in:
1 parent
0a3c7b7b45
commit
1289f5f0c2
7 files changed
+118
-6
No files matched your search
@@ -57,6 +57,7 @@ A room holds:
|
||||
| sandbox_target | the owner's ssh target |
|
||||
| provider_config | whose model key pays |
|
||||
| model | model id chosen for this room |
|
||||
| thinking_effort | reasoning level the turn sends: default, low, medium, high |
|
||||
| max_turn_steps | runaway guard, default 48 |
|
||||
| created_at, archived_at | |
|
||||
|
||||
@@ -623,8 +624,8 @@ provider_configs(id, account_id, name, kind, model, base_url, key_ciphertext)
|
||||
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,
|
||||
provider_config_id, model, max_turn_steps, absorbed_seq,
|
||||
created_at, archived_at)
|
||||
provider_config_id, model, thinking_effort, max_turn_steps,
|
||||
absorbed_seq, created_at, archived_at)
|
||||
members(room_id, id, account_id, display_name, role, color, guest_token_hash,
|
||||
joined_at)
|
||||
invites(token_hash, room_id, role, created_by, expires_at, max_uses, uses)
|
||||
|
||||
+16
-2
@@ -4,6 +4,7 @@ use axum::Json;
|
||||
use axum::extract::{Path, State};
|
||||
use axum::http::HeaderMap;
|
||||
use axum_extra::extract::CookieJar;
|
||||
use rhema_core::request::ThinkingEffort;
|
||||
use serde::Deserialize;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
@@ -59,10 +60,11 @@ fn load_room(state: &Shared, id: &str) -> AppResult<Room> {
|
||||
let vision = crate::util::room_model_vision(&conn, id);
|
||||
conn.query_row(
|
||||
"SELECT id, name, owner_id, provider_config_id, sandbox_target_id, workspace,
|
||||
repo_url, model, max_turn_steps, created_at, archived_at
|
||||
repo_url, model, thinking_effort, max_turn_steps, created_at, archived_at
|
||||
FROM rooms WHERE id = ?1",
|
||||
rusqlite::params![id],
|
||||
|row| {
|
||||
let effort: String = row.get("thinking_effort")?;
|
||||
Ok(Room {
|
||||
id: row.get("id")?,
|
||||
name: row.get("name")?,
|
||||
@@ -72,6 +74,7 @@ fn load_room(state: &Shared, id: &str) -> AppResult<Room> {
|
||||
workspace: row.get("workspace")?,
|
||||
repo_url: row.get("repo_url")?,
|
||||
model: row.get("model")?,
|
||||
thinking_effort: ThinkingEffort::parse(&effort).unwrap_or_default(),
|
||||
max_turn_steps: row.get("max_turn_steps")?,
|
||||
model_vision: vision,
|
||||
created_at: row.get("created_at")?,
|
||||
@@ -298,9 +301,11 @@ pub struct UpdateRoom {
|
||||
pub model: Option<String>,
|
||||
#[serde(default)]
|
||||
pub max_turn_steps: Option<u32>,
|
||||
#[serde(default)]
|
||||
pub thinking_effort: Option<String>,
|
||||
}
|
||||
|
||||
/// Owner edits: name, provider, model, step budget.
|
||||
/// Owner edits: name, provider, model, step budget, thinking effort.
|
||||
pub async fn update(
|
||||
user: AuthUser,
|
||||
State(state): State<Shared>,
|
||||
@@ -354,6 +359,15 @@ pub async fn update(
|
||||
rusqlite::params![steps.clamp(1, 500) as i64, id],
|
||||
)?;
|
||||
}
|
||||
if let Some(effort) = body.thinking_effort.as_deref() {
|
||||
let effort = ThinkingEffort::parse(effort).ok_or_else(|| {
|
||||
AppError::bad_request("thinking effort must be default, low, medium, or high")
|
||||
})?;
|
||||
state.db.conn().execute(
|
||||
"UPDATE rooms SET thinking_effort = ?1 WHERE id = ?2",
|
||||
rusqlite::params![effort.as_str(), id],
|
||||
)?;
|
||||
}
|
||||
Ok(Json(json!({ "room": load_room(&state, &id)? })))
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,14 @@ impl Db {
|
||||
conn.pragma_update(None, "foreign_keys", "ON")?;
|
||||
conn.busy_timeout(std::time::Duration::from_secs(5))?;
|
||||
conn.execute_batch(SCHEMA)?;
|
||||
// Columns added after the first release have no CREATE TABLE
|
||||
// path on an existing file. Add them here, once.
|
||||
ensure_column(
|
||||
&conn,
|
||||
"rooms",
|
||||
"thinking_effort",
|
||||
"TEXT NOT NULL DEFAULT 'default'",
|
||||
)?;
|
||||
Ok(Self {
|
||||
conn: Arc::new(Mutex::new(conn)),
|
||||
})
|
||||
@@ -47,6 +55,28 @@ impl Db {
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds `column` to `table` when the file predates it. The declaration
|
||||
/// carries its own default, so existing rows read as the old behavior.
|
||||
fn ensure_column(
|
||||
conn: &Connection,
|
||||
table: &str,
|
||||
column: &str,
|
||||
declaration: &str,
|
||||
) -> rusqlite::Result<()> {
|
||||
let present: i64 = conn.query_row(
|
||||
"SELECT COUNT(*) FROM pragma_table_info(?1) WHERE name = ?2",
|
||||
rusqlite::params![table, column],
|
||||
|row| row.get(0),
|
||||
)?;
|
||||
if present == 0 {
|
||||
conn.execute(
|
||||
&format!("ALTER TABLE {table} ADD COLUMN {column} {declaration}"),
|
||||
[],
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) const SCHEMA: &str = r#"
|
||||
CREATE TABLE IF NOT EXISTS meta (
|
||||
key TEXT PRIMARY KEY,
|
||||
@@ -113,6 +143,7 @@ CREATE TABLE IF NOT EXISTS rooms (
|
||||
repo_url TEXT,
|
||||
model TEXT,
|
||||
max_turn_steps INTEGER NOT NULL DEFAULT 48,
|
||||
thinking_effort TEXT NOT NULL DEFAULT 'default',
|
||||
session_json TEXT,
|
||||
absorbed_seq INTEGER NOT NULL DEFAULT 0,
|
||||
seeded INTEGER NOT NULL DEFAULT 0,
|
||||
@@ -185,3 +216,40 @@ CREATE INDEX IF NOT EXISTS events_room_seq ON events(room_id, seq);
|
||||
CREATE INDEX IF NOT EXISTS auth_sessions_account ON auth_sessions(account_id);
|
||||
CREATE INDEX IF NOT EXISTS attachments_room ON attachments(room_id);
|
||||
"#;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::ensure_column;
|
||||
|
||||
#[test]
|
||||
fn a_late_column_is_added_once_with_its_default() {
|
||||
let conn = rusqlite::Connection::open_in_memory().unwrap();
|
||||
conn.execute_batch(
|
||||
"CREATE TABLE rooms (id TEXT PRIMARY KEY) STRICT;
|
||||
INSERT INTO rooms (id) VALUES ('old');",
|
||||
)
|
||||
.unwrap();
|
||||
ensure_column(
|
||||
&conn,
|
||||
"rooms",
|
||||
"thinking_effort",
|
||||
"TEXT NOT NULL DEFAULT 'default'",
|
||||
)
|
||||
.unwrap();
|
||||
ensure_column(
|
||||
&conn,
|
||||
"rooms",
|
||||
"thinking_effort",
|
||||
"TEXT NOT NULL DEFAULT 'default'",
|
||||
)
|
||||
.unwrap();
|
||||
let effort: String = conn
|
||||
.query_row(
|
||||
"SELECT thinking_effort FROM rooms WHERE id = 'old'",
|
||||
[],
|
||||
|row| row.get(0),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(effort, "default");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Rows and wire types shared by the API and the room.
|
||||
|
||||
use rhema_core::request::ThinkingEffort;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// One chat line. The sequence number orders it in the room log.
|
||||
@@ -52,6 +53,8 @@ pub struct Room {
|
||||
pub workspace: String,
|
||||
pub repo_url: Option<String>,
|
||||
pub model: Option<String>,
|
||||
/// How much reasoning the room's model does; the turn sends it.
|
||||
pub thinking_effort: ThinkingEffort,
|
||||
pub max_turn_steps: i64,
|
||||
/// Whether the room's effective model is known to accept images.
|
||||
/// `None` is unknown, not no: facts arrive with a provider listing.
|
||||
|
||||
+8
-2
@@ -29,6 +29,8 @@ pub struct TurnConfig {
|
||||
/// The model's stored vision fact; `None` is unknown, not no.
|
||||
pub supports_vision: Option<bool>,
|
||||
pub max_turn_steps: u32,
|
||||
/// How much reasoning the model does; sent on every step.
|
||||
pub thinking: ThinkingEffort,
|
||||
/// The cursor the turn starts from. The boundary pass moves it to
|
||||
/// the last line it appended, so the turn's steering source reads on
|
||||
/// from there and never over what is already in the history.
|
||||
@@ -64,7 +66,7 @@ pub fn load_turn_config(state: &Shared, room_id: &str) -> AppResult<TurnConfig>
|
||||
let row = conn
|
||||
.query_row(
|
||||
"SELECT name, provider_config_id, sandbox_target_id, workspace, repo_url, model,
|
||||
max_turn_steps, absorbed_seq, seeded
|
||||
max_turn_steps, absorbed_seq, seeded, thinking_effort
|
||||
FROM rooms WHERE id = ?1 AND archived_at IS NULL",
|
||||
rusqlite::params![room_id],
|
||||
|row| {
|
||||
@@ -78,6 +80,7 @@ pub fn load_turn_config(state: &Shared, room_id: &str) -> AppResult<TurnConfig>
|
||||
row.get::<_, i64>(6)?,
|
||||
row.get::<_, i64>(7)?,
|
||||
row.get::<_, i64>(8)?,
|
||||
row.get::<_, String>(9)?,
|
||||
))
|
||||
},
|
||||
)
|
||||
@@ -92,6 +95,7 @@ pub fn load_turn_config(state: &Shared, room_id: &str) -> AppResult<TurnConfig>
|
||||
max_steps,
|
||||
absorbed,
|
||||
seeded,
|
||||
effort,
|
||||
) = row;
|
||||
let provider_id =
|
||||
provider_id.ok_or_else(|| AppError::bad_request("room has no provider configured"))?;
|
||||
@@ -141,6 +145,7 @@ pub fn load_turn_config(state: &Shared, room_id: &str) -> AppResult<TurnConfig>
|
||||
return Err(AppError::bad_request("room has no model selected"));
|
||||
}
|
||||
let supports_vision = crate::util::model_supports_vision(&conn, &kind, &model);
|
||||
let thinking = ThinkingEffort::parse(&effort).unwrap_or_default();
|
||||
Ok(TurnConfig {
|
||||
room_id: room_id.to_owned(),
|
||||
room_name: name,
|
||||
@@ -149,6 +154,7 @@ pub fn load_turn_config(state: &Shared, room_id: &str) -> AppResult<TurnConfig>
|
||||
model,
|
||||
supports_vision,
|
||||
max_turn_steps: max_steps.max(1) as u32,
|
||||
thinking,
|
||||
absorbed_seq: absorbed,
|
||||
seeded: seeded != 0,
|
||||
owner_name,
|
||||
@@ -356,7 +362,7 @@ pub fn build_agent(
|
||||
subagent_providers: None,
|
||||
session_id: Some(config.room_id.clone()),
|
||||
max_turn_steps,
|
||||
thinking: ThinkingEffort::Default,
|
||||
thinking: config.thinking,
|
||||
tools: Some(shell),
|
||||
extra_resolver: Some(extra_tools),
|
||||
shell_env: Default::default(),
|
||||
|
||||
@@ -5,6 +5,7 @@ import type {
|
||||
ProviderConfig,
|
||||
ProviderListResponse,
|
||||
Room,
|
||||
ThinkingEffort,
|
||||
UpdateRoomBody,
|
||||
UpdateRoomResponse,
|
||||
} from '~/types'
|
||||
@@ -24,6 +25,7 @@ const providersError = ref('')
|
||||
const name = ref(props.room.name)
|
||||
const providerId = ref(props.room.provider_config_id ?? '')
|
||||
const model = ref(props.room.model ?? '')
|
||||
const thinkingEffort = ref<ThinkingEffort>(props.room.thinking_effort)
|
||||
const maxSteps = ref<number | string>(props.room.max_turn_steps)
|
||||
const pickerOpen = ref(false)
|
||||
|
||||
@@ -69,6 +71,7 @@ async function save() {
|
||||
error.value = ''
|
||||
const body: UpdateRoomBody = {
|
||||
name: name.value.trim(),
|
||||
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
|
||||
@@ -149,6 +152,19 @@ async function archive() {
|
||||
<span class="hint">{{ effectiveModel ? 'The room uses this model for every turn.' : 'Pick a model before saving the room.' }}</span>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="field-label" for="room-settings-thinking">Thinking effort</label>
|
||||
<select id="room-settings-thinking" v-model="thinkingEffort" class="select">
|
||||
<option value="default">Provider default</option>
|
||||
<option value="low">Low</option>
|
||||
<option value="medium">Medium</option>
|
||||
<option value="high">High</option>
|
||||
</select>
|
||||
<span class="hint">
|
||||
How much reasoning the model does on each turn. Provider default sends no effort parameter.
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="field-label" for="room-settings-steps">Max turn steps</label>
|
||||
<input id="room-settings-steps" v-model.number="maxSteps" class="input" type="number" min="1" max="500" required>
|
||||
|
||||
@@ -62,6 +62,8 @@ export interface RoomListResponse {
|
||||
rooms: RoomSummary[]
|
||||
}
|
||||
|
||||
export type ThinkingEffort = 'default' | 'low' | 'medium' | 'high'
|
||||
|
||||
export interface Room {
|
||||
id: string
|
||||
name: string
|
||||
@@ -71,6 +73,7 @@ export interface Room {
|
||||
workspace: string
|
||||
repo_url: string | null
|
||||
model: string | null
|
||||
thinking_effort: ThinkingEffort
|
||||
model_vision: boolean | null
|
||||
max_turn_steps: number
|
||||
created_at: number
|
||||
@@ -123,6 +126,7 @@ export interface UpdateRoomBody {
|
||||
provider_config_id?: string
|
||||
model?: string
|
||||
max_turn_steps?: number
|
||||
thinking_effort?: ThinkingEffort
|
||||
}
|
||||
|
||||
export interface UpdateRoomResponse {
|
||||
|
||||
Reference in new issue
Block a user