forked from vhaudiquet/rhema-together
feat: pick the room model from a catalog dialog
The room model was a free-text field. It now opens a dialog that lists the provider's live catalog through the same adapter a turn uses, with context, output, price, and vision from models.dev. Rows filter by text, vision, or free price, and a custom id remains available when the provider lists nothing. The dialog is nested over room settings, so BaseDialog now gives Escape and the focus trap to the top dialog only. Clearing the model stores NULL, which returns the room to the provider's default.
This commit is contained in:
1 parent
2d36790fe1
commit
2216f37422
13 files changed
+720
-16
No files matched your search
@@ -113,7 +113,9 @@ issue certificates.
|
|||||||
3. **New room.** Pick the target and provider, give the workspace
|
3. **New room.** Pick the target and provider, give the workspace
|
||||||
directory (for example `/home/me/rooms/demo`), and optionally a git
|
directory (for example `/home/me/rooms/demo`), and optionally a git
|
||||||
URL. The workspace is created on the first mention and seeded from
|
URL. The workspace is created on the first mention and seeded from
|
||||||
the repository or a README.
|
the repository or a README. The Model field opens the provider's
|
||||||
|
model list with context, output, price, and vision. Pick a row, or
|
||||||
|
type an id the list does not carry.
|
||||||
4. **Invite.** The room's invite dialog creates a single-use link such
|
4. **Invite.** The room's invite dialog creates a single-use link such
|
||||||
as `https://together.example.com/join/<token>`. A friend opens it,
|
as `https://together.example.com/join/<token>`. A friend opens it,
|
||||||
picks a display name, and lands in the room as a guest.
|
picks a display name, and lands in the room as a guest.
|
||||||
|
|||||||
@@ -665,6 +665,9 @@ This repository, as committed:
|
|||||||
- Rooms with members, a per-room provider config, a sandbox target, a
|
- Rooms with members, a per-room provider config, a sandbox target, a
|
||||||
workspace, an optional repository URL, and an owner-only model and
|
workspace, an optional repository URL, and an owner-only model and
|
||||||
provider switch.
|
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.
|
||||||
- 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.
|
||||||
|
|||||||
@@ -41,6 +41,10 @@ pub fn router(state: Shared) -> Router {
|
|||||||
get(settings::list_providers).post(settings::create_provider),
|
get(settings::list_providers).post(settings::create_provider),
|
||||||
)
|
)
|
||||||
.route("/provider-configs/{id}", delete(settings::delete_provider))
|
.route("/provider-configs/{id}", delete(settings::delete_provider))
|
||||||
|
.route(
|
||||||
|
"/provider-configs/{id}/models",
|
||||||
|
get(settings::list_provider_models),
|
||||||
|
)
|
||||||
.route(
|
.route(
|
||||||
"/sandbox-targets",
|
"/sandbox-targets",
|
||||||
get(settings::list_targets).post(settings::create_target),
|
get(settings::list_targets).post(settings::create_target),
|
||||||
|
|||||||
+1
-2
@@ -341,13 +341,12 @@ pub async fn update(
|
|||||||
}
|
}
|
||||||
if let Some(model) = body.model.as_deref() {
|
if let Some(model) = body.model.as_deref() {
|
||||||
let model = model.trim();
|
let model = model.trim();
|
||||||
if !model.is_empty() {
|
let model = (!model.is_empty()).then_some(model);
|
||||||
state.db.conn().execute(
|
state.db.conn().execute(
|
||||||
"UPDATE rooms SET model = ?1 WHERE id = ?2",
|
"UPDATE rooms SET model = ?1 WHERE id = ?2",
|
||||||
rusqlite::params![model, id],
|
rusqlite::params![model, id],
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if let Some(steps) = body.max_turn_steps {
|
if let Some(steps) = body.max_turn_steps {
|
||||||
state.db.conn().execute(
|
state.db.conn().execute(
|
||||||
"UPDATE rooms SET max_turn_steps = ?1 WHERE id = ?2",
|
"UPDATE rooms SET max_turn_steps = ?1 WHERE id = ?2",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use axum::Json;
|
use axum::Json;
|
||||||
use axum::extract::{Path, State};
|
use axum::extract::{Path, State};
|
||||||
|
use axum::http::StatusCode;
|
||||||
use rhema_sandbox::Sandbox;
|
use rhema_sandbox::Sandbox;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::{Value, json};
|
use serde_json::{Value, json};
|
||||||
@@ -112,6 +113,82 @@ pub async fn create_provider(
|
|||||||
Ok(Json(json!({ "id": id })))
|
Ok(Json(json!({ "id": id })))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The provider's live model catalog. The registry builds the same
|
||||||
|
/// adapter a turn uses and asks it for the rows a coding agent can
|
||||||
|
/// drive; the model-facts decorator fills price, context, and vision
|
||||||
|
/// from models.dev where the provider leaves them blank.
|
||||||
|
pub async fn list_provider_models(
|
||||||
|
user: AuthUser,
|
||||||
|
State(state): State<Shared>,
|
||||||
|
Path(id): Path<String>,
|
||||||
|
) -> AppResult<Json<Value>> {
|
||||||
|
let (kind, model, base_url, ciphertext) = state
|
||||||
|
.db
|
||||||
|
.conn()
|
||||||
|
.query_row(
|
||||||
|
"SELECT kind, model, base_url, api_key_ciphertext FROM provider_configs
|
||||||
|
WHERE id = ?1 AND account_id = ?2",
|
||||||
|
rusqlite::params![id, user.user.id],
|
||||||
|
|row| {
|
||||||
|
Ok((
|
||||||
|
row.get::<_, String>(0)?,
|
||||||
|
row.get::<_, String>(1)?,
|
||||||
|
row.get::<_, Option<String>>(2)?,
|
||||||
|
row.get::<_, String>(3)?,
|
||||||
|
))
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.map_err(|err| match err {
|
||||||
|
rusqlite::Error::QueryReturnedNoRows => AppError::not_found("provider not found"),
|
||||||
|
other => other.into(),
|
||||||
|
})?;
|
||||||
|
let key = state.secrets.open_str(&ciphertext)?;
|
||||||
|
let llama_url = (kind == "llama-cpp")
|
||||||
|
.then_some(base_url.as_deref())
|
||||||
|
.flatten();
|
||||||
|
let built =
|
||||||
|
rhema_provider_registry::build(&kind, Some(&key), llama_url, base_url.as_deref(), None)
|
||||||
|
.map_err(|err| AppError::bad_request(format!("provider: {err}")))?;
|
||||||
|
let models = tokio::time::timeout(Duration::from_secs(30), built.listing.list_models())
|
||||||
|
.await
|
||||||
|
.map_err(|_| {
|
||||||
|
AppError::new(
|
||||||
|
StatusCode::GATEWAY_TIMEOUT,
|
||||||
|
"the provider did not answer in time",
|
||||||
|
)
|
||||||
|
})?
|
||||||
|
.map_err(|err| {
|
||||||
|
tracing::warn!(provider = %id, error = %err, "provider catalog");
|
||||||
|
AppError::new(StatusCode::BAD_GATEWAY, catalog_error(&err))
|
||||||
|
})?;
|
||||||
|
Ok(Json(json!({
|
||||||
|
"provider": { "id": id, "kind": kind, "model": model },
|
||||||
|
"models": models,
|
||||||
|
})))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A short reason for a failed catalog fetch. The provider's own body
|
||||||
|
/// can be an HTML error page and is not worth showing; the full error
|
||||||
|
/// stays in the log.
|
||||||
|
fn catalog_error(err: &rhema_core::ProviderError) -> String {
|
||||||
|
use rhema_core::ProviderError;
|
||||||
|
match err {
|
||||||
|
ProviderError::Api {
|
||||||
|
status: Some(status),
|
||||||
|
..
|
||||||
|
} => format!("the provider answered with HTTP {status}"),
|
||||||
|
ProviderError::Api { status: None, .. } => {
|
||||||
|
"the provider returned an unreadable catalog".to_owned()
|
||||||
|
}
|
||||||
|
ProviderError::RateLimited { .. } => {
|
||||||
|
"the provider rate limited the catalog request".to_owned()
|
||||||
|
}
|
||||||
|
ProviderError::Network(_) => "could not reach the provider".to_owned(),
|
||||||
|
ProviderError::Timeout => "the provider did not answer in time".to_owned(),
|
||||||
|
other => other.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Removes a provider configuration. Rooms that used it are left with
|
/// Removes a provider configuration. Rooms that used it are left with
|
||||||
/// no provider until the owner picks another.
|
/// no provider until the owner picks another.
|
||||||
pub async fn delete_provider(
|
pub async fn delete_provider(
|
||||||
|
|||||||
@@ -309,6 +309,66 @@ button {
|
|||||||
color: var(--faint);
|
color: var(--faint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.model-trigger {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: var(--sp-3);
|
||||||
|
width: 100%;
|
||||||
|
min-height: 36px;
|
||||||
|
padding: var(--sp-2) var(--sp-3);
|
||||||
|
background: var(--surface);
|
||||||
|
border: 1px solid var(--border-strong);
|
||||||
|
border-radius: var(--r-control);
|
||||||
|
color: var(--text);
|
||||||
|
font-size: var(--fs-ui);
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-trigger:hover:not(:disabled) {
|
||||||
|
background: var(--surface-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-trigger:focus-visible {
|
||||||
|
border-color: var(--accent);
|
||||||
|
outline: 2px solid var(--accent);
|
||||||
|
outline-offset: -1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-trigger:disabled {
|
||||||
|
background: var(--surface-2);
|
||||||
|
color: var(--faint);
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-trigger > svg {
|
||||||
|
flex: none;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-trigger:disabled > svg {
|
||||||
|
color: var(--faint);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-trigger-value {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
gap: var(--sp-2);
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-trigger-name {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-trigger-note {
|
||||||
|
flex: none;
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: var(--fs-small);
|
||||||
|
}
|
||||||
|
|
||||||
.btn {
|
.btn {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -536,6 +596,173 @@ button {
|
|||||||
margin-top: var(--sp-6);
|
margin-top: var(--sp-6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.model-picker {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: var(--sp-3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-search {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-search-icon {
|
||||||
|
position: absolute;
|
||||||
|
left: var(--sp-3);
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
color: var(--faint);
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-search-input {
|
||||||
|
padding-left: var(--sp-8);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-filter-bar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--sp-4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-check {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--sp-2);
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: var(--fs-meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-check input {
|
||||||
|
accent-color: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-count {
|
||||||
|
margin-left: auto;
|
||||||
|
color: var(--faint);
|
||||||
|
font-size: var(--fs-small);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-state {
|
||||||
|
padding: var(--sp-4) 0;
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: var(--fs-ui);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-list {
|
||||||
|
max-height: min(52vh, 520px);
|
||||||
|
overflow-y: auto;
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-row {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
padding: var(--sp-3) var(--sp-2);
|
||||||
|
border: 0;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
background: transparent;
|
||||||
|
color: var(--text);
|
||||||
|
text-align: left;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-row:last-child {
|
||||||
|
border-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-row:hover {
|
||||||
|
background: var(--surface-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-row:focus-visible {
|
||||||
|
outline: 2px solid var(--accent);
|
||||||
|
outline-offset: -2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-row-active,
|
||||||
|
.model-row-active:hover {
|
||||||
|
background: var(--accent-soft);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-row-body {
|
||||||
|
display: flex;
|
||||||
|
flex: 1;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: var(--sp-1);
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-row-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--sp-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-row-title {
|
||||||
|
font-size: var(--fs-ui);
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-row-check {
|
||||||
|
flex: none;
|
||||||
|
margin-left: auto;
|
||||||
|
color: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-row-id {
|
||||||
|
color: var(--muted);
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: var(--fs-small);
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-row-desc {
|
||||||
|
display: -webkit-box;
|
||||||
|
overflow: hidden;
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: var(--fs-meta);
|
||||||
|
line-height: var(--lh-body);
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-row-facts {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: var(--sp-1) var(--sp-3);
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: var(--fs-small);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-fact {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-fact-accent {
|
||||||
|
color: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-fact-muted {
|
||||||
|
color: var(--faint);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-error {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: var(--sp-3);
|
||||||
|
padding: var(--sp-4) var(--sp-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-empty {
|
||||||
|
padding: var(--sp-6) var(--sp-2);
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: var(--fs-ui);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
.code-block {
|
.code-block {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: var(--sp-2);
|
padding: var(--sp-2);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { nextTick, onBeforeUnmount, onMounted, ref, useId } from 'vue'
|
import { nextTick, onBeforeUnmount, onMounted, ref, useId } from 'vue'
|
||||||
import { X } from 'lucide-vue-next'
|
import { X } from 'lucide-vue-next'
|
||||||
|
import { isTopDialog, pushDialog, removeDialog } from '~/utils/dialogStack'
|
||||||
|
|
||||||
const props = withDefaults(defineProps<{ title: string; description?: string; wide?: boolean }>(), {
|
const props = withDefaults(defineProps<{ title: string; description?: string; wide?: boolean }>(), {
|
||||||
description: '',
|
description: '',
|
||||||
@@ -13,7 +14,12 @@ const titleId = useId()
|
|||||||
const descId = useId()
|
const descId = useId()
|
||||||
const panel = ref<HTMLElement | null>(null)
|
const panel = ref<HTMLElement | null>(null)
|
||||||
let previousFocus: HTMLElement | null = null
|
let previousFocus: HTMLElement | null = null
|
||||||
let previousOverflow = ''
|
|
||||||
|
// A dialog can open another one (the model picker over room settings).
|
||||||
|
// Only the top of the stack answers Escape and Tab, so closing the
|
||||||
|
// inner dialog leaves the outer one open. The stack lives in its own
|
||||||
|
// module because every `<script setup>` binding is per instance.
|
||||||
|
const dialogId = Symbol('dialog')
|
||||||
|
|
||||||
function focusable(): HTMLElement[] {
|
function focusable(): HTMLElement[] {
|
||||||
if (!panel.value) return []
|
if (!panel.value) return []
|
||||||
@@ -31,6 +37,7 @@ function focusable(): HTMLElement[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onKeydown(event: KeyboardEvent) {
|
function onKeydown(event: KeyboardEvent) {
|
||||||
|
if (!isTopDialog(dialogId)) return
|
||||||
if (event.key === 'Escape') {
|
if (event.key === 'Escape') {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
emit('close')
|
emit('close')
|
||||||
@@ -58,13 +65,13 @@ function onKeydown(event: KeyboardEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onBackdrop(event: MouseEvent) {
|
function onBackdrop(event: MouseEvent) {
|
||||||
|
if (!isTopDialog(dialogId)) return
|
||||||
if (event.target === event.currentTarget) emit('close')
|
if (event.target === event.currentTarget) emit('close')
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
pushDialog(dialogId)
|
||||||
previousFocus = document.activeElement as HTMLElement | null
|
previousFocus = document.activeElement as HTMLElement | null
|
||||||
previousOverflow = document.body.style.overflow
|
|
||||||
document.body.style.overflow = 'hidden'
|
|
||||||
document.addEventListener('keydown', onKeydown)
|
document.addEventListener('keydown', onKeydown)
|
||||||
await nextTick()
|
await nextTick()
|
||||||
const preferred = panel.value?.querySelector<HTMLElement>('[autofocus]')
|
const preferred = panel.value?.querySelector<HTMLElement>('[autofocus]')
|
||||||
@@ -73,8 +80,8 @@ onMounted(async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
|
removeDialog(dialogId)
|
||||||
document.removeEventListener('keydown', onKeydown)
|
document.removeEventListener('keydown', onKeydown)
|
||||||
document.body.style.overflow = previousOverflow
|
|
||||||
previousFocus?.focus?.()
|
previousFocus?.focus?.()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -0,0 +1,235 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, nextTick, onMounted, ref } from 'vue'
|
||||||
|
import { Check, Search } from 'lucide-vue-next'
|
||||||
|
import type { ModelCard, ModelPricing, ProviderConfig, ProviderModelsResponse } from '~/types'
|
||||||
|
import { apiErrorMessage } from '~/utils/errors'
|
||||||
|
import { formatModelPrice, formatTokens } from '~/utils/format'
|
||||||
|
import BaseDialog from '~/components/BaseDialog.vue'
|
||||||
|
|
||||||
|
const props = defineProps<{ provider: ProviderConfig; selected: string }>()
|
||||||
|
const emit = defineEmits<{ close: []; select: [model: string] }>()
|
||||||
|
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
const models = ref<ModelCard[]>([])
|
||||||
|
const listEl = ref<HTMLElement | null>(null)
|
||||||
|
const loading = ref(true)
|
||||||
|
const error = ref('')
|
||||||
|
const filter = ref('')
|
||||||
|
const visionOnly = ref(false)
|
||||||
|
const freeOnly = ref(false)
|
||||||
|
|
||||||
|
const query = computed(() => filter.value.trim())
|
||||||
|
const queryLower = computed(() => query.value.toLowerCase())
|
||||||
|
const currentMissing = computed(
|
||||||
|
() =>
|
||||||
|
props.selected.length > 0 &&
|
||||||
|
props.selected !== props.provider.model &&
|
||||||
|
!models.value.some((model) => model.id.toLowerCase() === props.selected.toLowerCase()),
|
||||||
|
)
|
||||||
|
const showCustom = computed(
|
||||||
|
() =>
|
||||||
|
query.value.length > 0 &&
|
||||||
|
!models.value.some((model) => model.id.toLowerCase() === queryLower.value),
|
||||||
|
)
|
||||||
|
const filtered = computed(() => {
|
||||||
|
const q = queryLower.value
|
||||||
|
const list = models.value.filter((model) => {
|
||||||
|
if (visionOnly.value && model.supports_vision !== true) return false
|
||||||
|
if (freeOnly.value) {
|
||||||
|
const price = model.pricing
|
||||||
|
if (!price || price.input_per_mtok !== 0 || price.output_per_mtok !== 0) return false
|
||||||
|
}
|
||||||
|
if (!q) return true
|
||||||
|
return [model.id, model.display_name, model.description, model.family ?? '']
|
||||||
|
.some((value) => value.toLowerCase().includes(q))
|
||||||
|
})
|
||||||
|
return list.sort(
|
||||||
|
(a, b) => a.display_name.localeCompare(b.display_name) || a.id.localeCompare(b.id),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
const countLabel = computed(
|
||||||
|
() => `${filtered.value.length} ${filtered.value.length === 1 ? 'model' : 'models'}`,
|
||||||
|
)
|
||||||
|
|
||||||
|
onMounted(load)
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
loading.value = true
|
||||||
|
error.value = ''
|
||||||
|
try {
|
||||||
|
const response = await api.get<ProviderModelsResponse>(
|
||||||
|
`/provider-configs/${props.provider.id}/models`,
|
||||||
|
)
|
||||||
|
models.value = response.models
|
||||||
|
} catch (err) {
|
||||||
|
error.value = apiErrorMessage(err)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
await nextTick()
|
||||||
|
listEl.value?.querySelector<HTMLElement>('.model-row-active')?.scrollIntoView({ block: 'nearest' })
|
||||||
|
}
|
||||||
|
|
||||||
|
function priceLabel(pricing: ModelPricing): string {
|
||||||
|
if (pricing.input_per_mtok === 0 && pricing.output_per_mtok === 0) return 'Free'
|
||||||
|
return `${formatModelPrice(pricing.input_per_mtok)} in / ${formatModelPrice(pricing.output_per_mtok)} out`
|
||||||
|
}
|
||||||
|
|
||||||
|
function choose(id: string) {
|
||||||
|
emit('select', id)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSearchEnter() {
|
||||||
|
const only = filtered.value[0]
|
||||||
|
if (filtered.value.length === 1 && only) {
|
||||||
|
choose(only.id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (filtered.value.length === 0 && showCustom.value) choose(query.value)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<BaseDialog
|
||||||
|
title="Select model"
|
||||||
|
:description="`${provider.name} · ${provider.kind}. Prices are USD per 1M tokens.`"
|
||||||
|
wide
|
||||||
|
@close="emit('close')"
|
||||||
|
>
|
||||||
|
<div class="model-picker">
|
||||||
|
<div class="model-search">
|
||||||
|
<Search :size="16" class="model-search-icon" aria-hidden="true" />
|
||||||
|
<input
|
||||||
|
v-model="filter"
|
||||||
|
class="input model-search-input"
|
||||||
|
type="search"
|
||||||
|
placeholder="Filter by name, id, or family"
|
||||||
|
aria-label="Filter models"
|
||||||
|
autofocus
|
||||||
|
@keydown.enter.prevent="onSearchEnter"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="model-filter-bar">
|
||||||
|
<label class="model-check">
|
||||||
|
<input v-model="visionOnly" type="checkbox">
|
||||||
|
Vision
|
||||||
|
</label>
|
||||||
|
<label class="model-check">
|
||||||
|
<input v-model="freeOnly" type="checkbox">
|
||||||
|
Free
|
||||||
|
</label>
|
||||||
|
<span v-if="!loading && !error" class="model-count">{{ countLabel }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p v-if="loading" class="model-state">Loading models.</p>
|
||||||
|
|
||||||
|
<div v-else ref="listEl" class="model-list">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="model-row"
|
||||||
|
:class="{ 'model-row-active': selected === '' }"
|
||||||
|
@click="choose('')"
|
||||||
|
>
|
||||||
|
<span class="model-row-body">
|
||||||
|
<span class="model-row-head">
|
||||||
|
<span class="model-row-title">Provider default</span>
|
||||||
|
<Check
|
||||||
|
v-if="selected === ''"
|
||||||
|
:size="16"
|
||||||
|
class="model-row-check"
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
<span v-if="selected === ''" class="sr-only">Current model</span>
|
||||||
|
</span>
|
||||||
|
<span class="model-row-id">{{ provider.model }}</span>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
v-if="currentMissing"
|
||||||
|
type="button"
|
||||||
|
class="model-row model-row-active"
|
||||||
|
@click="choose(selected)"
|
||||||
|
>
|
||||||
|
<span class="model-row-body">
|
||||||
|
<span class="model-row-head">
|
||||||
|
<span class="model-row-title">Current model</span>
|
||||||
|
<Check :size="16" class="model-row-check" aria-hidden="true" />
|
||||||
|
</span>
|
||||||
|
<span class="model-row-id">{{ selected }}</span>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<p v-if="error" class="model-error">
|
||||||
|
<span class="form-error">{{ error }}</span>
|
||||||
|
<button type="button" class="btn btn-sm" @click="load">Retry</button>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
|
<button
|
||||||
|
v-for="model in filtered"
|
||||||
|
:key="model.id"
|
||||||
|
type="button"
|
||||||
|
class="model-row"
|
||||||
|
:class="{ 'model-row-active': model.id === selected }"
|
||||||
|
@click="choose(model.id)"
|
||||||
|
>
|
||||||
|
<span class="model-row-body">
|
||||||
|
<span class="model-row-head">
|
||||||
|
<span class="model-row-title">{{ model.display_name || model.id }}</span>
|
||||||
|
<Check
|
||||||
|
v-if="model.id === selected"
|
||||||
|
:size="16"
|
||||||
|
class="model-row-check"
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
<span v-if="model.id === selected" class="sr-only">Current model</span>
|
||||||
|
</span>
|
||||||
|
<span class="model-row-id">{{ model.id }}</span>
|
||||||
|
<span v-if="model.description" class="model-row-desc">{{ model.description }}</span>
|
||||||
|
<span class="model-row-facts">
|
||||||
|
<span v-if="model.supports_vision === true" class="model-fact model-fact-accent">
|
||||||
|
Vision
|
||||||
|
</span>
|
||||||
|
<span v-if="model.input_token_limit" class="model-fact">
|
||||||
|
{{ formatTokens(model.input_token_limit) }} context
|
||||||
|
</span>
|
||||||
|
<span v-if="model.output_token_limit" class="model-fact">
|
||||||
|
{{ formatTokens(model.output_token_limit) }} output
|
||||||
|
</span>
|
||||||
|
<span v-if="model.pricing" class="model-fact">
|
||||||
|
{{ priceLabel(model.pricing) }}
|
||||||
|
</span>
|
||||||
|
<span v-else class="model-fact model-fact-muted">Price unknown</span>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<p v-if="filtered.length === 0 && !showCustom" class="model-empty">
|
||||||
|
{{ models.length === 0 ? 'No models listed.' : 'No models match.' }}
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<button
|
||||||
|
v-if="showCustom"
|
||||||
|
type="button"
|
||||||
|
class="model-row"
|
||||||
|
@click="choose(query)"
|
||||||
|
>
|
||||||
|
<span class="model-row-body">
|
||||||
|
<span class="model-row-head">
|
||||||
|
<span class="model-row-title">Use custom model</span>
|
||||||
|
</span>
|
||||||
|
<code class="model-row-id">{{ query }}</code>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="dialog-actions">
|
||||||
|
<button type="button" class="btn btn-quiet" @click="emit('close')">Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</BaseDialog>
|
||||||
|
</template>
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, ref } from 'vue'
|
import { computed, onMounted, ref } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
|
import { ChevronRight } from 'lucide-vue-next'
|
||||||
import type {
|
import type {
|
||||||
CreateRoomBody,
|
CreateRoomBody,
|
||||||
CreateRoomResponse,
|
CreateRoomResponse,
|
||||||
@@ -11,6 +12,7 @@ import type {
|
|||||||
} from '~/types'
|
} from '~/types'
|
||||||
import { apiErrorMessage } from '~/utils/errors'
|
import { apiErrorMessage } from '~/utils/errors'
|
||||||
import BaseDialog from '~/components/BaseDialog.vue'
|
import BaseDialog from '~/components/BaseDialog.vue'
|
||||||
|
import ModelPickerDialog from '~/components/ModelPickerDialog.vue'
|
||||||
|
|
||||||
const emit = defineEmits<{ close: [] }>()
|
const emit = defineEmits<{ close: [] }>()
|
||||||
|
|
||||||
@@ -29,6 +31,11 @@ const targetId = ref('')
|
|||||||
const workspace = ref('')
|
const workspace = ref('')
|
||||||
const repoUrl = ref('')
|
const repoUrl = ref('')
|
||||||
const model = ref('')
|
const model = ref('')
|
||||||
|
const pickerOpen = ref(false)
|
||||||
|
|
||||||
|
const selectedProvider = computed(
|
||||||
|
() => providers.value.find((provider) => provider.id === providerId.value) ?? null,
|
||||||
|
)
|
||||||
|
|
||||||
const submitting = ref(false)
|
const submitting = ref(false)
|
||||||
const error = ref('')
|
const error = ref('')
|
||||||
@@ -67,8 +74,13 @@ onMounted(async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
function onProviderChange() {
|
function onProviderChange() {
|
||||||
const current = providers.value.find((provider) => provider.id === providerId.value)
|
pickerOpen.value = false
|
||||||
if (current && !model.value.trim()) model.value = current.model
|
model.value = selectedProvider.value?.model ?? ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function onModelSelected(next: string) {
|
||||||
|
model.value = next
|
||||||
|
pickerOpen.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
@@ -147,9 +159,23 @@ async function submit() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="field-label" for="new-room-model">Model <span class="field-optional">optional</span></label>
|
<span class="field-label">Model <span class="field-optional">optional</span></span>
|
||||||
<input id="new-room-model" v-model="model" class="input" type="text" autocomplete="off">
|
<button
|
||||||
<span class="hint">Leave this as the provider model unless the room needs another one.</span>
|
type="button"
|
||||||
|
class="model-trigger"
|
||||||
|
:disabled="!selectedProvider || loading"
|
||||||
|
aria-label="Select model"
|
||||||
|
aria-haspopup="dialog"
|
||||||
|
title="Select model"
|
||||||
|
@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>
|
||||||
|
<ChevronRight :size="16" aria-hidden="true" />
|
||||||
|
</button>
|
||||||
|
<span class="hint">The room uses the provider's model unless you pick another.</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
@@ -186,5 +212,13 @@ async function submit() {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<ModelPickerDialog
|
||||||
|
v-if="pickerOpen && selectedProvider"
|
||||||
|
:provider="selectedProvider"
|
||||||
|
:selected="model"
|
||||||
|
@close="pickerOpen = false"
|
||||||
|
@select="onModelSelected"
|
||||||
|
/>
|
||||||
</BaseDialog>
|
</BaseDialog>
|
||||||
</template>
|
</template>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, ref } from 'vue'
|
import { computed, onMounted, ref } from 'vue'
|
||||||
|
import { ChevronRight } from 'lucide-vue-next'
|
||||||
import type {
|
import type {
|
||||||
ProviderConfig,
|
ProviderConfig,
|
||||||
ProviderListResponse,
|
ProviderListResponse,
|
||||||
@@ -9,6 +10,7 @@ import type {
|
|||||||
} from '~/types'
|
} from '~/types'
|
||||||
import { apiErrorMessage } from '~/utils/errors'
|
import { apiErrorMessage } from '~/utils/errors'
|
||||||
import BaseDialog from '~/components/BaseDialog.vue'
|
import BaseDialog from '~/components/BaseDialog.vue'
|
||||||
|
import ModelPickerDialog from '~/components/ModelPickerDialog.vue'
|
||||||
|
|
||||||
const props = defineProps<{ room: Room }>()
|
const props = defineProps<{ room: Room }>()
|
||||||
const emit = defineEmits<{ close: []; updated: [room: Room]; archived: [] }>()
|
const emit = defineEmits<{ close: []; updated: [room: Room]; archived: [] }>()
|
||||||
@@ -23,6 +25,11 @@ const name = ref(props.room.name)
|
|||||||
const providerId = ref(props.room.provider_config_id ?? '')
|
const providerId = ref(props.room.provider_config_id ?? '')
|
||||||
const model = ref(props.room.model ?? '')
|
const model = ref(props.room.model ?? '')
|
||||||
const maxSteps = ref<number | string>(props.room.max_turn_steps)
|
const maxSteps = ref<number | string>(props.room.max_turn_steps)
|
||||||
|
const pickerOpen = ref(false)
|
||||||
|
|
||||||
|
const selectedProvider = computed(
|
||||||
|
() => providers.value.find((provider) => provider.id === providerId.value) ?? null,
|
||||||
|
)
|
||||||
|
|
||||||
const saving = ref(false)
|
const saving = ref(false)
|
||||||
const error = ref('')
|
const error = ref('')
|
||||||
@@ -43,6 +50,16 @@ onMounted(async () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function onProviderChange() {
|
||||||
|
pickerOpen.value = false
|
||||||
|
model.value = selectedProvider.value?.model ?? ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function onModelSelected(next: string) {
|
||||||
|
model.value = next
|
||||||
|
pickerOpen.value = false
|
||||||
|
}
|
||||||
|
|
||||||
async function save() {
|
async function save() {
|
||||||
if (!canSave.value) return
|
if (!canSave.value) return
|
||||||
saving.value = true
|
saving.value = true
|
||||||
@@ -52,7 +69,7 @@ async function save() {
|
|||||||
max_turn_steps: Math.min(500, Math.max(1, Math.round(Number(maxSteps.value) || 1))),
|
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) body.provider_config_id = providerId.value
|
||||||
if (model.value.trim()) body.model = model.value.trim()
|
body.model = model.value.trim()
|
||||||
try {
|
try {
|
||||||
const response = await api.patch<UpdateRoomResponse>(`/rooms/${props.room.id}`, body)
|
const response = await api.patch<UpdateRoomResponse>(`/rooms/${props.room.id}`, body)
|
||||||
emit('updated', response.room)
|
emit('updated', response.room)
|
||||||
@@ -90,7 +107,13 @@ async function archive() {
|
|||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="field-label" for="room-settings-provider">Provider</label>
|
<label class="field-label" for="room-settings-provider">Provider</label>
|
||||||
<select id="room-settings-provider" v-model="providerId" class="select" :disabled="loadingProviders">
|
<select
|
||||||
|
id="room-settings-provider"
|
||||||
|
v-model="providerId"
|
||||||
|
class="select"
|
||||||
|
:disabled="loadingProviders"
|
||||||
|
@change="onProviderChange"
|
||||||
|
>
|
||||||
<option v-if="!room.provider_config_id" value="" disabled>No provider selected</option>
|
<option v-if="!room.provider_config_id" value="" disabled>No provider selected</option>
|
||||||
<option v-for="provider in providers" :key="provider.id" :value="provider.id">
|
<option v-for="provider in providers" :key="provider.id" :value="provider.id">
|
||||||
{{ provider.name }} ({{ provider.kind }})
|
{{ provider.name }} ({{ provider.kind }})
|
||||||
@@ -104,8 +127,23 @@ async function archive() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="field-label" for="room-settings-model">Model</label>
|
<span class="field-label">Model</span>
|
||||||
<input id="room-settings-model" v-model="model" class="input" type="text" spellcheck="false">
|
<button
|
||||||
|
type="button"
|
||||||
|
class="model-trigger"
|
||||||
|
:disabled="!selectedProvider || loadingProviders"
|
||||||
|
aria-label="Select model"
|
||||||
|
aria-haspopup="dialog"
|
||||||
|
title="Select model"
|
||||||
|
@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>
|
||||||
|
<ChevronRight :size="16" aria-hidden="true" />
|
||||||
|
</button>
|
||||||
|
<span class="hint">The room uses the provider's model unless you pick another.</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
@@ -123,6 +161,14 @@ async function archive() {
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<ModelPickerDialog
|
||||||
|
v-if="pickerOpen && selectedProvider"
|
||||||
|
:provider="selectedProvider"
|
||||||
|
:selected="model"
|
||||||
|
@close="pickerOpen = false"
|
||||||
|
@select="onModelSelected"
|
||||||
|
/>
|
||||||
|
|
||||||
<div class="section archive-section">
|
<div class="section archive-section">
|
||||||
<h3 class="panel-title">Archive</h3>
|
<h3 class="panel-title">Archive</h3>
|
||||||
<p class="hint">
|
<p class="hint">
|
||||||
|
|||||||
@@ -146,6 +146,30 @@ export interface ProviderListResponse {
|
|||||||
kinds: string[]
|
kinds: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ModelPricing {
|
||||||
|
input_per_mtok: number
|
||||||
|
output_per_mtok: number
|
||||||
|
cached_input_per_mtok: number | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ModelCard {
|
||||||
|
id: string
|
||||||
|
display_name: string
|
||||||
|
description: string
|
||||||
|
input_token_limit: number | null
|
||||||
|
output_token_limit: number | null
|
||||||
|
supports_vision?: boolean | null
|
||||||
|
generation_methods: string[]
|
||||||
|
pricing?: ModelPricing | null
|
||||||
|
family?: string | null
|
||||||
|
release_date?: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProviderModelsResponse {
|
||||||
|
provider: { id: string; kind: string; model: string }
|
||||||
|
models: ModelCard[]
|
||||||
|
}
|
||||||
|
|
||||||
export interface CreateProviderBody {
|
export interface CreateProviderBody {
|
||||||
name: string
|
name: string
|
||||||
kind: string
|
kind: string
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
const stack: symbol[] = []
|
||||||
|
let savedOverflow = ''
|
||||||
|
|
||||||
|
export function pushDialog(id: symbol) {
|
||||||
|
if (stack.length === 0) {
|
||||||
|
savedOverflow = document.body.style.overflow
|
||||||
|
document.body.style.overflow = 'hidden'
|
||||||
|
}
|
||||||
|
stack.push(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeDialog(id: symbol) {
|
||||||
|
const index = stack.indexOf(id)
|
||||||
|
if (index === -1) return
|
||||||
|
stack.splice(index, 1)
|
||||||
|
if (stack.length === 0) document.body.style.overflow = savedOverflow
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isTopDialog(id: symbol) {
|
||||||
|
return stack[stack.length - 1] === id
|
||||||
|
}
|
||||||
@@ -52,3 +52,28 @@ export function formatCost(cost: number | null | undefined): string {
|
|||||||
export function plural(count: number, one: string, many: string): string {
|
export function plural(count: number, one: string, many: string): string {
|
||||||
return count === 1 ? one : many
|
return count === 1 ? one : many
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatTokens(tokens: number | null | undefined): string {
|
||||||
|
if (tokens === null || tokens === undefined || tokens <= 0) return ''
|
||||||
|
if (tokens >= 1_000_000) {
|
||||||
|
const value = tokens / 1_000_000
|
||||||
|
return `${Number.isInteger(value) ? value : value.toFixed(1)}M`
|
||||||
|
}
|
||||||
|
if (tokens >= 1_000) {
|
||||||
|
const value = tokens / 1_000
|
||||||
|
return `${Number.isInteger(value) ? value : value.toFixed(0)}k`
|
||||||
|
}
|
||||||
|
return String(tokens)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatModelPrice(value: number | null | undefined): string {
|
||||||
|
if (value === null || value === undefined) return ''
|
||||||
|
if (value === 0) return 'Free'
|
||||||
|
const digits = value < 0.01 ? 4 : 2
|
||||||
|
return new Intl.NumberFormat('en', {
|
||||||
|
style: 'currency',
|
||||||
|
currency: 'USD',
|
||||||
|
minimumFractionDigits: 2,
|
||||||
|
maximumFractionDigits: digits,
|
||||||
|
}).format(value)
|
||||||
|
}
|
||||||
Reference in new issue
Block a user