refactor!: integrate quick pane simplification
Merge the validated feature branch after the Ctrl+N session shortcut landed on main. BREAKING CHANGE: The Noctalia relay no longer accepts --agent, and the Tauri host no longer exposes the legacy load_agent command.
This commit is contained in:
+1
-2
@@ -2,9 +2,8 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Tauri + React + Typescript</title>
|
||||
<title>Pi Status UI</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
Generated
-10
@@ -11,7 +11,6 @@
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2",
|
||||
"@tauri-apps/plugin-dialog": "^2.7.2",
|
||||
"@tauri-apps/plugin-opener": "^2",
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0",
|
||||
"react-markdown": "^10.1.0",
|
||||
@@ -1605,15 +1604,6 @@
|
||||
"@tauri-apps/api": "^2.11.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-opener": {
|
||||
"version": "2.5.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-opener/-/plugin-opener-2.5.4.tgz",
|
||||
"integrity": "sha512-1HnPkb+AmgO29HBazm4uPLKB+r7zzcTBW1d0fyYp1uP+jwtpoiNDGKMMzz58SFp49nOIrxdE3aUJtT57lfO9CQ==",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.11.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@testing-library/dom": {
|
||||
"version": "10.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-10.4.1.tgz",
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2",
|
||||
"@tauri-apps/plugin-dialog": "^2.7.2",
|
||||
"@tauri-apps/plugin-opener": "^2",
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0",
|
||||
"react-markdown": "^10.1.0",
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
<svg width="206" height="231" viewBox="0 0 206 231" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M143.143 84C143.143 96.1503 133.293 106 121.143 106C108.992 106 99.1426 96.1503 99.1426 84C99.1426 71.8497 108.992 62 121.143 62C133.293 62 143.143 71.8497 143.143 84Z" fill="#FFC131"/>
|
||||
<ellipse cx="84.1426" cy="147" rx="22" ry="22" transform="rotate(180 84.1426 147)" fill="#24C8DB"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M166.738 154.548C157.86 160.286 148.023 164.269 137.757 166.341C139.858 160.282 141 153.774 141 147C141 144.543 140.85 142.121 140.558 139.743C144.975 138.204 149.215 136.139 153.183 133.575C162.73 127.404 170.292 118.608 174.961 108.244C179.63 97.8797 181.207 86.3876 179.502 75.1487C177.798 63.9098 172.884 53.4021 165.352 44.8883C157.82 36.3744 147.99 30.2165 137.042 27.1546C126.095 24.0926 114.496 24.2568 103.64 27.6274C92.7839 30.998 83.1319 37.4317 75.8437 46.1553C74.9102 47.2727 74.0206 48.4216 73.176 49.5993C61.9292 50.8488 51.0363 54.0318 40.9629 58.9556C44.2417 48.4586 49.5653 38.6591 56.679 30.1442C67.0505 17.7298 80.7861 8.57426 96.2354 3.77762C111.685 -1.01901 128.19 -1.25267 143.769 3.10474C159.348 7.46215 173.337 16.2252 184.056 28.3411C194.775 40.457 201.767 55.4101 204.193 71.404C206.619 87.3978 204.374 103.752 197.73 118.501C191.086 133.25 180.324 145.767 166.738 154.548ZM41.9631 74.275L62.5557 76.8042C63.0459 72.813 63.9401 68.9018 65.2138 65.1274C57.0465 67.0016 49.2088 70.087 41.9631 74.275Z" fill="#FFC131"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M38.4045 76.4519C47.3493 70.6709 57.2677 66.6712 67.6171 64.6132C65.2774 70.9669 64 77.8343 64 85.0001C64 87.1434 64.1143 89.26 64.3371 91.3442C60.0093 92.8732 55.8533 94.9092 51.9599 97.4256C42.4128 103.596 34.8505 112.392 30.1816 122.756C25.5126 133.12 23.9357 144.612 25.6403 155.851C27.3449 167.09 32.2584 177.598 39.7906 186.112C47.3227 194.626 57.153 200.784 68.1003 203.846C79.0476 206.907 90.6462 206.743 101.502 203.373C112.359 200.002 122.011 193.568 129.299 184.845C130.237 183.722 131.131 182.567 131.979 181.383C143.235 180.114 154.132 176.91 164.205 171.962C160.929 182.49 155.596 192.319 148.464 200.856C138.092 213.27 124.357 222.426 108.907 227.222C93.458 232.019 76.9524 232.253 61.3736 227.895C45.7948 223.538 31.8055 214.775 21.0867 202.659C10.3679 190.543 3.37557 175.59 0.949823 159.596C-1.47592 143.602 0.768139 127.248 7.41237 112.499C14.0566 97.7497 24.8183 85.2327 38.4045 76.4519ZM163.062 156.711L163.062 156.711C162.954 156.773 162.846 156.835 162.738 156.897C162.846 156.835 162.954 156.773 163.062 156.711Z" fill="#24C8DB"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 2.5 KiB |
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||
|
Before Width: | Height: | Size: 1.5 KiB |
+5
-152
@@ -1,7 +1,6 @@
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
use serde_json::{json, Value};
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use tauri::{AppHandle, Emitter};
|
||||
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
|
||||
@@ -346,72 +345,11 @@ pub async fn new_session(socket_path: &str, agent_id: &str) -> Result<Value, Str
|
||||
request(socket_path, "new_session", Some(agent_id), None).await
|
||||
}
|
||||
|
||||
fn fallback_transcript(state: &Value) -> Value {
|
||||
let Some(path) = state.pointer("/data/sessionFile").and_then(Value::as_str) else {
|
||||
return json!({ "data": { "messages": [] } });
|
||||
};
|
||||
let path = Path::new(path);
|
||||
if !path.is_absolute()
|
||||
|| path.extension().and_then(|extension| extension.to_str()) != Some("jsonl")
|
||||
{
|
||||
return json!({ "data": { "messages": [] } });
|
||||
}
|
||||
let messages = std::fs::read_to_string(path)
|
||||
.ok()
|
||||
.map(|content| {
|
||||
content
|
||||
.lines()
|
||||
.filter_map(|line| serde_json::from_str::<Value>(line).ok())
|
||||
.filter(|entry| entry.get("type").and_then(Value::as_str) == Some("message"))
|
||||
.filter_map(|entry| entry.get("message").cloned())
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
json!({ "data": { "messages": messages } })
|
||||
}
|
||||
|
||||
fn compact_commands(value: Value) -> Value {
|
||||
let commands = value
|
||||
.pointer("/data/commands")
|
||||
.and_then(Value::as_array)
|
||||
.map(|commands| {
|
||||
commands
|
||||
.iter()
|
||||
.map(|command| {
|
||||
let mut compact = serde_json::Map::new();
|
||||
for field in ["name", "description"] {
|
||||
if let Some(value) = command.get(field) {
|
||||
compact.insert(field.to_owned(), value.clone());
|
||||
}
|
||||
}
|
||||
Value::Object(compact)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
json!({ "data": { "commands": commands } })
|
||||
}
|
||||
|
||||
pub async fn load_agent(socket_path: &str, agent_id: &str) -> Result<Value, String> {
|
||||
// Older bridge daemons can still serve the conversation while they await a restart.
|
||||
let stats = request(socket_path, "get_session_stats", Some(agent_id), None)
|
||||
.await
|
||||
.unwrap_or_else(|_| json!({ "data": {} }));
|
||||
let (state, commands, models) = tokio::try_join!(
|
||||
request(socket_path, "get_state", Some(agent_id), None),
|
||||
request(socket_path, "get_commands", Some(agent_id), None),
|
||||
request(socket_path, "get_available_models", Some(agent_id), None),
|
||||
)?;
|
||||
Ok(json!({
|
||||
"state": state,
|
||||
"stats": stats,
|
||||
"transcript": fallback_transcript(&state),
|
||||
"commands": compact_commands(commands),
|
||||
"models": models
|
||||
}))
|
||||
}
|
||||
|
||||
pub async fn submit_prompt(socket_path: &str, agent_id: &str, message: &str) -> Result<Value, String> {
|
||||
pub async fn submit_prompt(
|
||||
socket_path: &str,
|
||||
agent_id: &str,
|
||||
message: &str,
|
||||
) -> Result<Value, String> {
|
||||
request(
|
||||
socket_path,
|
||||
"submit_prompt",
|
||||
@@ -896,91 +834,6 @@ mod tests {
|
||||
std::fs::remove_file(path).expect("socket cleanup");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reads_messages_from_the_saved_session_file_when_transcript_rpc_is_unavailable() {
|
||||
let path = format!(
|
||||
"{}/pi-status-ui-history-{}.jsonl",
|
||||
env::temp_dir().display(),
|
||||
std::process::id()
|
||||
);
|
||||
std::fs::write(
|
||||
&path,
|
||||
concat!(
|
||||
"{\"type\":\"session\",\"id\":\"session-1\"}\n",
|
||||
"{\"type\":\"message\",\"message\":{\"role\":\"user\",\"content\":\"Hello\"}}\n",
|
||||
"{\"type\":\"message\",\"message\":{\"role\":\"assistant\",\"content\":\"Hi\"}}\n"
|
||||
),
|
||||
)
|
||||
.expect("session fixture");
|
||||
let transcript = fallback_transcript(&json!({
|
||||
"data": { "sessionFile": path }
|
||||
}));
|
||||
assert_eq!(
|
||||
transcript["data"]["messages"],
|
||||
json!([
|
||||
{ "role": "user", "content": "Hello" },
|
||||
{ "role": "assistant", "content": "Hi" }
|
||||
])
|
||||
);
|
||||
std::fs::remove_file(path).expect("session cleanup");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn loads_state_history_commands_and_models_as_one_snapshot() {
|
||||
let path = format!(
|
||||
"{}/pi-status-ui-load-{}.sock",
|
||||
env::temp_dir().display(),
|
||||
std::process::id()
|
||||
);
|
||||
let _ = std::fs::remove_file(&path);
|
||||
let listener = UnixListener::bind(&path).expect("listener");
|
||||
let server = tokio::spawn(async move {
|
||||
for _ in 0..4 {
|
||||
let (stream, _) = listener.accept().await.expect("connection");
|
||||
tokio::spawn(async move {
|
||||
let mut line = String::new();
|
||||
let mut reader = BufReader::new(stream);
|
||||
reader.read_line(&mut line).await.expect("request");
|
||||
let request: Value = serde_json::from_str(&line).expect("JSON request");
|
||||
assert_eq!(request["agentId"], "agent-1");
|
||||
let result = match request["op"].as_str() {
|
||||
Some("get_state") => json!({ "data": { "isStreaming": false } }),
|
||||
Some("get_session_stats") => json!({
|
||||
"data": { "contextUsage": { "tokens": 32000, "contextWindow": 200000 } }
|
||||
}),
|
||||
Some("get_commands") => json!({ "data": { "commands": [{
|
||||
"name": "resume",
|
||||
"description": "Resume a saved session",
|
||||
"sourceInfo": { "path": "/very/large/extension/metadata" }
|
||||
}] } }),
|
||||
Some("get_available_models") => json!({ "data": { "models": [] } }),
|
||||
other => panic!("unexpected operation: {other:?}"),
|
||||
};
|
||||
let mut response = serde_json::to_vec(&json!({
|
||||
"id": "tauri-ui", "ok": true, "result": result
|
||||
}))
|
||||
.expect("response JSON");
|
||||
response.push(b'\n');
|
||||
reader
|
||||
.get_mut()
|
||||
.write_all(&response)
|
||||
.await
|
||||
.expect("response");
|
||||
});
|
||||
}
|
||||
});
|
||||
let snapshot = load_agent(&path, "agent-1").await.expect("snapshot");
|
||||
assert_eq!(snapshot["state"]["data"]["isStreaming"], false);
|
||||
assert_eq!(snapshot["stats"]["data"]["contextUsage"]["tokens"], 32000);
|
||||
assert_eq!(snapshot["transcript"]["data"]["messages"], json!([]));
|
||||
assert_eq!(
|
||||
snapshot["commands"]["data"]["commands"],
|
||||
json!([{ "name": "resume", "description": "Resume a saved session" }])
|
||||
);
|
||||
server.await.expect("server succeeds");
|
||||
std::fs::remove_file(path).expect("socket cleanup");
|
||||
}
|
||||
|
||||
fn runtime(id: &str) -> Value {
|
||||
json!({
|
||||
"runtimeId": id,
|
||||
|
||||
+84
-190
@@ -14,33 +14,6 @@ use tauri::{
|
||||
};
|
||||
|
||||
struct LegacySubscription(Mutex<Option<JoinHandle<()>>>);
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
struct ManagedWindowVisibility {
|
||||
main: bool,
|
||||
quick_pane: bool,
|
||||
}
|
||||
|
||||
impl ManagedWindowVisibility {
|
||||
fn main_shown(&mut self) {
|
||||
self.main = true;
|
||||
self.quick_pane = false;
|
||||
}
|
||||
|
||||
fn quick_pane_shown(&mut self) {
|
||||
self.main = false;
|
||||
self.quick_pane = true;
|
||||
}
|
||||
|
||||
fn hidden(&mut self, label: &str) {
|
||||
if label == "main" {
|
||||
self.main = false;
|
||||
} else if label == "quick-pane" {
|
||||
self.quick_pane = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// One mutex serializes cross-window transitions, avoiding nested visibility-lock ordering.
|
||||
struct WindowVisibility(Mutex<ManagedWindowVisibility>);
|
||||
struct PendingPromotedRuntime(Mutex<Option<String>>);
|
||||
struct WorkspaceSubscription {
|
||||
generation: Arc<bridge::SubscriptionGeneration>,
|
||||
@@ -131,22 +104,10 @@ fn apply_main_window_action(app: &AppHandle, args: &[String]) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
let Some(state) = app.try_state::<WindowVisibility>() else {
|
||||
eprintln!("Window visibility state is unavailable");
|
||||
return;
|
||||
};
|
||||
let mut visibility = state
|
||||
.0
|
||||
.lock()
|
||||
.unwrap_or_else(|poisoned| poisoned.into_inner());
|
||||
if created {
|
||||
visibility.main = false;
|
||||
}
|
||||
match window_action(args, visibility.main) {
|
||||
let visible = !created && window.is_visible().unwrap_or(false);
|
||||
match window_action(args, visible) {
|
||||
WindowAction::Hide => {
|
||||
if window.hide().is_ok() {
|
||||
visibility.hidden("main");
|
||||
}
|
||||
let _ = window.hide();
|
||||
}
|
||||
WindowAction::ShowAndFocus => {
|
||||
if let Some(quick_pane) = app.get_webview_window("quick-pane") {
|
||||
@@ -155,9 +116,7 @@ fn apply_main_window_action(app: &AppHandle, args: &[String]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
visibility.hidden("quick-pane");
|
||||
if window.show().is_ok() {
|
||||
visibility.main_shown();
|
||||
let _ = window.unminimize();
|
||||
let _ = window.set_focus();
|
||||
}
|
||||
@@ -185,37 +144,24 @@ fn get_or_create_quick_pane(app: &AppHandle) -> Result<(WebviewWindow, bool), St
|
||||
|
||||
fn show_main_for_promoted_runtime(app: &AppHandle, runtime_id: String) -> Result<(), String> {
|
||||
// A recreated Main starts hidden, so Quick is never visible with it.
|
||||
let (window, created) = get_or_create_main_with_visibility(app, false)?;
|
||||
let state = app
|
||||
.try_state::<WindowVisibility>()
|
||||
.ok_or_else(|| "Window visibility state is unavailable".to_owned())?;
|
||||
let (window, _) = get_or_create_main_with_visibility(app, false)?;
|
||||
let pending = app
|
||||
.try_state::<PendingPromotedRuntime>()
|
||||
.ok_or_else(|| "Promoted runtime state is unavailable".to_owned())?;
|
||||
let mut visibility = state
|
||||
.0
|
||||
.lock()
|
||||
.map_err(|_| "Could not update window visibility".to_owned())?;
|
||||
let mut pending = pending
|
||||
.0
|
||||
.lock()
|
||||
.map_err(|_| "Could not queue promoted runtime".to_owned())?;
|
||||
if created {
|
||||
visibility.main = false;
|
||||
}
|
||||
if let Some(quick_pane) = app.get_webview_window("quick-pane") {
|
||||
quick_pane
|
||||
.hide()
|
||||
.map_err(|error| format!("Could not hide Quick Pane before promotion: {error}"))?;
|
||||
}
|
||||
visibility.hidden("quick-pane");
|
||||
// Retain this on show failure; a later Main startup can consume it.
|
||||
*pending = Some(runtime_id);
|
||||
visibility.main = false;
|
||||
window
|
||||
.show()
|
||||
.map_err(|error| format!("Could not show Main after hiding Quick Pane: {error}"))?;
|
||||
visibility.main_shown();
|
||||
let _ = window.unminimize();
|
||||
let _ = window.set_focus();
|
||||
Ok(())
|
||||
@@ -229,22 +175,10 @@ fn toggle_quick_pane(app: &AppHandle) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
let Some(state) = app.try_state::<WindowVisibility>() else {
|
||||
eprintln!("Window visibility state is unavailable");
|
||||
return;
|
||||
};
|
||||
let mut visibility = state
|
||||
.0
|
||||
.lock()
|
||||
.unwrap_or_else(|poisoned| poisoned.into_inner());
|
||||
if created {
|
||||
visibility.quick_pane = false;
|
||||
}
|
||||
match quick_pane_action(visibility.quick_pane) {
|
||||
let visible = !created && window.is_visible().unwrap_or(false);
|
||||
match quick_pane_action(visible) {
|
||||
WindowAction::Hide => {
|
||||
if window.hide().is_ok() {
|
||||
visibility.hidden("quick-pane");
|
||||
}
|
||||
let _ = window.hide();
|
||||
}
|
||||
WindowAction::ShowAndFocus => {
|
||||
if let Some(main) = app.get_webview_window("main") {
|
||||
@@ -253,9 +187,7 @@ fn toggle_quick_pane(app: &AppHandle) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
visibility.hidden("main");
|
||||
if window.show().is_ok() {
|
||||
visibility.quick_pane_shown();
|
||||
let _ = window.unminimize();
|
||||
let _ = window.set_focus();
|
||||
let _ = app.emit("quick-pane-shown", ());
|
||||
@@ -288,30 +220,52 @@ fn requested_new_worktree(app: &AppHandle, args: &[String]) -> Option<String> {
|
||||
}
|
||||
|
||||
fn launch_new_session(app: AppHandle, args: &[String]) {
|
||||
let Some(worktree_path) = requested_new_worktree(&app, args) else { return };
|
||||
let Some(worktree_path) = requested_new_worktree(&app, args) else {
|
||||
return;
|
||||
};
|
||||
tauri::async_runtime::spawn(async move {
|
||||
// Give a newly-created webview time to register its frontend listeners.
|
||||
tokio::time::sleep(Duration::from_millis(350)).await;
|
||||
let _ = app.emit("workspace-new-session", json!({
|
||||
"phase": "starting",
|
||||
"detail": "Starting a new Pi session…"
|
||||
}));
|
||||
let _ = app.emit(
|
||||
"workspace-new-session",
|
||||
json!({
|
||||
"phase": "starting",
|
||||
"detail": "Starting a new Pi session…"
|
||||
}),
|
||||
);
|
||||
match socket_path().map(|socket| (socket, worktree_path)) {
|
||||
Ok((socket, worktree_path)) => match bridge::create_session_runtime(&socket, &worktree_path).await {
|
||||
Ok(result) => { let _ = app.emit("workspace-new-session", json!({
|
||||
"phase": "ready",
|
||||
"runtimeId": result.runtime.runtime_id,
|
||||
"detail": "New session ready"
|
||||
})); }
|
||||
Err(error) => { let _ = app.emit("workspace-new-session", json!({
|
||||
"phase": "error",
|
||||
"detail": format!("Could not start session: {error}")
|
||||
})); }
|
||||
},
|
||||
Err(error) => { let _ = app.emit("workspace-new-session", json!({
|
||||
"phase": "error",
|
||||
"detail": error
|
||||
})); }
|
||||
Ok((socket, worktree_path)) => {
|
||||
match bridge::create_session_runtime(&socket, &worktree_path).await {
|
||||
Ok(result) => {
|
||||
let _ = app.emit(
|
||||
"workspace-new-session",
|
||||
json!({
|
||||
"phase": "ready",
|
||||
"runtimeId": result.runtime.runtime_id,
|
||||
"detail": "New session ready"
|
||||
}),
|
||||
);
|
||||
}
|
||||
Err(error) => {
|
||||
let _ = app.emit(
|
||||
"workspace-new-session",
|
||||
json!({
|
||||
"phase": "error",
|
||||
"detail": format!("Could not start session: {error}")
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
let _ = app.emit(
|
||||
"workspace-new-session",
|
||||
json!({
|
||||
"phase": "error",
|
||||
"detail": error
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -344,7 +298,9 @@ fn resize_quick_pane(app: AppHandle, height: f64) -> Result<(), String> {
|
||||
let quick_pane = app
|
||||
.get_webview_window("quick-pane")
|
||||
.ok_or_else(|| "Quick Pane window is unavailable".to_owned())?;
|
||||
let scale_factor = quick_pane.scale_factor().map_err(|error| error.to_string())?;
|
||||
let scale_factor = quick_pane
|
||||
.scale_factor()
|
||||
.map_err(|error| error.to_string())?;
|
||||
let current_size = quick_pane.inner_size().map_err(|error| error.to_string())?;
|
||||
quick_pane
|
||||
.set_size(LogicalSize::new(
|
||||
@@ -355,20 +311,11 @@ fn resize_quick_pane(app: AppHandle, height: f64) -> Result<(), String> {
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn dismiss_quick_pane(
|
||||
app: AppHandle,
|
||||
visibility: State<'_, WindowVisibility>,
|
||||
) -> Result<(), String> {
|
||||
let quick_pane = app
|
||||
.get_webview_window("quick-pane")
|
||||
.ok_or_else(|| "Quick Pane window is unavailable".to_owned())?;
|
||||
let mut visibility = visibility
|
||||
.0
|
||||
.lock()
|
||||
.map_err(|_| "Could not update window visibility".to_owned())?;
|
||||
quick_pane.hide().map_err(|error| error.to_string())?;
|
||||
visibility.hidden("quick-pane");
|
||||
Ok(())
|
||||
fn dismiss_quick_pane(app: AppHandle) -> Result<(), String> {
|
||||
app.get_webview_window("quick-pane")
|
||||
.ok_or_else(|| "Quick Pane window is unavailable".to_owned())?
|
||||
.hide()
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -388,7 +335,10 @@ async fn promote_quick_runtime(
|
||||
) -> Result<bridge::RuntimeResult, String> {
|
||||
let result = bridge::promote_quick_runtime(&socket_path()?, &runtime_id).await?;
|
||||
show_main_for_promoted_runtime(&app, result.runtime.runtime_id.clone())?;
|
||||
let _ = app.emit("workspace-promoted-runtime", json!({ "runtimeId": result.runtime.runtime_id }));
|
||||
let _ = app.emit(
|
||||
"workspace-promoted-runtime",
|
||||
json!({ "runtimeId": result.runtime.runtime_id }),
|
||||
);
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
@@ -490,11 +440,6 @@ async fn forget_directory(worktree_path: String) -> Result<Value, String> {
|
||||
bridge::forget_directory(&socket_path()?, &worktree_path).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn load_agent(agent_id: String) -> Result<Value, String> {
|
||||
bridge::load_agent(&socket_path()?, &agent_id).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn list_sessions(agent_id: String) -> Result<Value, String> {
|
||||
bridge::list_sessions(&socket_path()?, &agent_id).await
|
||||
@@ -557,7 +502,8 @@ async fn pi_rpc_command(agent_id: String, command: String, input: Value) -> Resu
|
||||
"pi_rpc_command",
|
||||
Some(&agent_id),
|
||||
Some(serde_json::json!({ "command": command, "input": input })),
|
||||
).await
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -665,10 +611,6 @@ pub fn run() {
|
||||
let builder = tauri::Builder::default()
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.manage(LegacySubscription(Mutex::new(None)))
|
||||
.manage(WindowVisibility(Mutex::new(ManagedWindowVisibility {
|
||||
main: true,
|
||||
quick_pane: false,
|
||||
})))
|
||||
.manage(PendingPromotedRuntime(Mutex::new(None)))
|
||||
.manage(WorkspaceSubscription {
|
||||
generation: Arc::new(bridge::SubscriptionGeneration::default()),
|
||||
@@ -686,17 +628,7 @@ pub fn run() {
|
||||
if should_hide_close_request(window.label()) {
|
||||
if let WindowEvent::CloseRequested { api, .. } = event {
|
||||
api.prevent_close();
|
||||
if let Some(state) = window.app_handle().try_state::<WindowVisibility>() {
|
||||
let mut visibility = state
|
||||
.0
|
||||
.lock()
|
||||
.unwrap_or_else(|poisoned| poisoned.into_inner());
|
||||
if window.hide().is_ok() {
|
||||
visibility.hidden(window.label());
|
||||
}
|
||||
} else {
|
||||
let _ = window.hide();
|
||||
}
|
||||
let _ = window.hide();
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -732,7 +664,6 @@ pub fn run() {
|
||||
list_directories,
|
||||
select_worktree,
|
||||
forget_directory,
|
||||
load_agent,
|
||||
list_sessions,
|
||||
switch_session,
|
||||
new_session,
|
||||
@@ -776,10 +707,26 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn new_session_uses_an_explicit_absolute_worktree() {
|
||||
let args = vec!["pi-status-ui".into(), "--new".into(), "--worktree".into(), "/workspace".into()];
|
||||
assert_eq!(requested_new_worktree_argument(&args), Some("/workspace".into()));
|
||||
let relative = vec!["pi-status-ui".into(), "--new".into(), "--worktree".into(), "workspace".into()];
|
||||
assert_eq!(requested_new_worktree_argument(&relative).filter(|path| Path::new(path).is_absolute()), None);
|
||||
let args = vec![
|
||||
"pi-status-ui".into(),
|
||||
"--new".into(),
|
||||
"--worktree".into(),
|
||||
"/workspace".into(),
|
||||
];
|
||||
assert_eq!(
|
||||
requested_new_worktree_argument(&args),
|
||||
Some("/workspace".into())
|
||||
);
|
||||
let relative = vec![
|
||||
"pi-status-ui".into(),
|
||||
"--new".into(),
|
||||
"--worktree".into(),
|
||||
"workspace".into(),
|
||||
];
|
||||
assert_eq!(
|
||||
requested_new_worktree_argument(&relative).filter(|path| Path::new(path).is_absolute()),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -797,42 +744,6 @@ mod tests {
|
||||
assert!(!should_hide_close_request("other"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn showing_main_clears_quick_pane_visibility() {
|
||||
let mut visibility = ManagedWindowVisibility {
|
||||
main: false,
|
||||
quick_pane: true,
|
||||
};
|
||||
|
||||
visibility.main_shown();
|
||||
|
||||
assert_eq!(
|
||||
visibility,
|
||||
ManagedWindowVisibility {
|
||||
main: true,
|
||||
quick_pane: false,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn showing_quick_pane_clears_main_visibility() {
|
||||
let mut visibility = ManagedWindowVisibility {
|
||||
main: true,
|
||||
quick_pane: false,
|
||||
};
|
||||
|
||||
visibility.quick_pane_shown();
|
||||
|
||||
assert_eq!(
|
||||
visibility,
|
||||
ManagedWindowVisibility {
|
||||
main: false,
|
||||
quick_pane: true,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn promoted_runtime_pending_id_clears_only_after_matching_acknowledgement() {
|
||||
let pending = PendingPromotedRuntime(Mutex::new(Some("runtime-a".to_owned())));
|
||||
@@ -843,23 +754,6 @@ mod tests {
|
||||
assert_eq!(value.as_deref(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dismissed_quick_pane_reopens_with_one_toggle() {
|
||||
let mut visibility = ManagedWindowVisibility {
|
||||
main: false,
|
||||
quick_pane: true,
|
||||
};
|
||||
|
||||
visibility.hidden("quick-pane");
|
||||
assert_eq!(
|
||||
quick_pane_action(visibility.quick_pane),
|
||||
WindowAction::ShowAndFocus
|
||||
);
|
||||
visibility.quick_pane_shown();
|
||||
assert!(visibility.quick_pane);
|
||||
assert!(!visibility.main);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn main_recreation_uses_the_complete_configured_window() {
|
||||
let context: tauri::Context<tauri::Wry> = tauri::generate_context!();
|
||||
|
||||
+8
-9
@@ -1007,17 +1007,14 @@ select:focus-visible {
|
||||
flex: 0 0 auto;
|
||||
transform: scale(1.35);
|
||||
}
|
||||
.modal-backdrop,
|
||||
.extension-backdrop {
|
||||
position: absolute;
|
||||
z-index: 10;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
dialog.session-picker::backdrop,
|
||||
dialog.extension::backdrop {
|
||||
background: rgba(0, 0, 0, 0.62);
|
||||
}
|
||||
dialog.session-picker:not([open]),
|
||||
dialog.extension:not([open]) {
|
||||
display: none;
|
||||
}
|
||||
.session-picker,
|
||||
.extension {
|
||||
width: min(680px, 90vw);
|
||||
@@ -1025,10 +1022,12 @@ select:focus-visible {
|
||||
overflow: auto;
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
margin: auto;
|
||||
padding: 15px;
|
||||
border: 1px solid #b76f26;
|
||||
border-radius: 10px;
|
||||
background: #2d2e31;
|
||||
color: #f1f3f4;
|
||||
}
|
||||
.session-picker {
|
||||
overflow: hidden;
|
||||
|
||||
+3
-4
@@ -213,10 +213,9 @@ describe("App command progress and errors", () => {
|
||||
await user.click(
|
||||
screen.getByRole("option", { name: /Claude.*anthropic\/claude\/sonnet/i }),
|
||||
);
|
||||
await user.click(
|
||||
screen.getByRole("button", { name: "Default thinking Medium" }),
|
||||
);
|
||||
await user.click(screen.getByRole("option", { name: "High" }));
|
||||
fireEvent.change(screen.getByRole("combobox", { name: "Default thinking" }), {
|
||||
target: { value: "high" },
|
||||
});
|
||||
await user.click(
|
||||
screen.getByRole("button", { name: "Save Quick Pane settings" }),
|
||||
);
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||
|
Before Width: | Height: | Size: 4.0 KiB |
@@ -1,16 +1,18 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import type { RpcCommand, RpcField } from "../commands/rpc";
|
||||
|
||||
const controls = (container: HTMLElement | null) =>
|
||||
Array.from(
|
||||
container?.querySelectorAll<HTMLElement>("button, input, select, textarea") ??
|
||||
[],
|
||||
).filter((node) => !node.hasAttribute("disabled"));
|
||||
type RpcInputValue =
|
||||
| string
|
||||
| boolean
|
||||
| null
|
||||
| RpcInputValue[]
|
||||
| { [key: string]: RpcInputValue }
|
||||
| undefined;
|
||||
|
||||
function valueFor(field: RpcField, value: string | boolean): unknown {
|
||||
function valueFor(field: RpcField, value: string | boolean): RpcInputValue {
|
||||
if (field.kind === "boolean") return value === true;
|
||||
if (field.kind === "json")
|
||||
return value ? JSON.parse(value as string) : undefined;
|
||||
return value ? (JSON.parse(value as string) as RpcInputValue) : undefined;
|
||||
return value || undefined;
|
||||
}
|
||||
|
||||
@@ -27,19 +29,17 @@ export function CommandFormDialog({
|
||||
pending?: boolean;
|
||||
commandError?: string;
|
||||
}) {
|
||||
const ref = useRef<HTMLElement>(null);
|
||||
const opener = useRef<HTMLElement | null>(null);
|
||||
const ref = useRef<HTMLDialogElement>(null);
|
||||
const [values, setValues] = useState<Record<string, string | boolean>>({});
|
||||
const [validationError, setValidationError] = useState<string>();
|
||||
useEffect(() => {
|
||||
if (!command) return;
|
||||
opener.current = document.activeElement as HTMLElement | null;
|
||||
setValues({});
|
||||
setValidationError(undefined);
|
||||
const frame = requestAnimationFrame(() => controls(ref.current)[0]?.focus());
|
||||
const dialog = ref.current;
|
||||
dialog?.showModal();
|
||||
return () => {
|
||||
cancelAnimationFrame(frame);
|
||||
opener.current?.focus();
|
||||
if (dialog?.open) dialog.close();
|
||||
};
|
||||
}, [command]);
|
||||
if (!command) return null;
|
||||
@@ -63,109 +63,90 @@ export function CommandFormDialog({
|
||||
}
|
||||
};
|
||||
return (
|
||||
<div className="extension-backdrop">
|
||||
<section
|
||||
ref={ref}
|
||||
className="extension"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="command-form-title"
|
||||
aria-busy={pending}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
onCancel();
|
||||
}
|
||||
if (event.key === "Tab") {
|
||||
const items = controls(ref.current),
|
||||
first = items[0],
|
||||
last = items[items.length - 1];
|
||||
if (!first || !last) return;
|
||||
if (event.shiftKey && document.activeElement === first) {
|
||||
event.preventDefault();
|
||||
last.focus();
|
||||
} else if (!event.shiftKey && document.activeElement === last) {
|
||||
event.preventDefault();
|
||||
first.focus();
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<p className="extension-eyebrow">Pi RPC command</p>
|
||||
<h2 id="command-form-title">/{command.command}</h2>
|
||||
<p>{command.description}</p>
|
||||
{fields.map((field) => (
|
||||
<label key={field.name}>
|
||||
{field.label}
|
||||
{field.kind === "boolean" ? (
|
||||
<input
|
||||
aria-label={field.label}
|
||||
type="checkbox"
|
||||
checked={values[field.name] === true}
|
||||
disabled={pending}
|
||||
onChange={(event) =>
|
||||
setValues({
|
||||
...values,
|
||||
[field.name]: event.currentTarget.checked,
|
||||
})
|
||||
}
|
||||
/>
|
||||
) : field.kind === "enum" ? (
|
||||
<select
|
||||
aria-label={field.label}
|
||||
value={(values[field.name] as string) ?? ""}
|
||||
disabled={pending}
|
||||
onChange={(event) =>
|
||||
setValues({
|
||||
...values,
|
||||
[field.name]: event.currentTarget.value,
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">Select…</option>
|
||||
{field.options?.map((option) => (
|
||||
<option key={option}>{option}</option>
|
||||
))}
|
||||
</select>
|
||||
) : field.kind === "json" ? (
|
||||
<textarea
|
||||
aria-label={field.label}
|
||||
value={(values[field.name] as string) ?? ""}
|
||||
disabled={pending}
|
||||
onChange={(event) =>
|
||||
setValues({
|
||||
...values,
|
||||
[field.name]: event.currentTarget.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<input
|
||||
aria-label={field.label}
|
||||
value={(values[field.name] as string) ?? ""}
|
||||
disabled={pending}
|
||||
onChange={(event) =>
|
||||
setValues({
|
||||
...values,
|
||||
[field.name]: event.currentTarget.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</label>
|
||||
))}
|
||||
{(validationError || commandError) && (
|
||||
<p role="alert">{validationError || commandError}</p>
|
||||
)}
|
||||
<div className="extension-options">
|
||||
<button disabled={pending} onClick={submit}>
|
||||
{pending ? "Running…" : "Run command"}
|
||||
</button>
|
||||
<button className="quiet" disabled={pending} onClick={onCancel}>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<dialog
|
||||
ref={ref}
|
||||
className="extension"
|
||||
aria-labelledby="command-form-title"
|
||||
aria-busy={pending}
|
||||
onCancel={(event) => {
|
||||
event.preventDefault();
|
||||
onCancel();
|
||||
}}
|
||||
>
|
||||
<p className="extension-eyebrow">Pi RPC command</p>
|
||||
<h2 id="command-form-title">/{command.command}</h2>
|
||||
<p>{command.description}</p>
|
||||
{fields.map((field) => (
|
||||
<label key={field.name}>
|
||||
{field.label}
|
||||
{field.kind === "boolean" ? (
|
||||
<input
|
||||
aria-label={field.label}
|
||||
type="checkbox"
|
||||
checked={values[field.name] === true}
|
||||
disabled={pending}
|
||||
onChange={(event) =>
|
||||
setValues({
|
||||
...values,
|
||||
[field.name]: event.currentTarget.checked,
|
||||
})
|
||||
}
|
||||
/>
|
||||
) : field.kind === "enum" ? (
|
||||
<select
|
||||
aria-label={field.label}
|
||||
value={(values[field.name] as string) ?? ""}
|
||||
disabled={pending}
|
||||
onChange={(event) =>
|
||||
setValues({
|
||||
...values,
|
||||
[field.name]: event.currentTarget.value,
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">Select…</option>
|
||||
{field.options?.map((option) => (
|
||||
<option key={option}>{option}</option>
|
||||
))}
|
||||
</select>
|
||||
) : field.kind === "json" ? (
|
||||
<textarea
|
||||
aria-label={field.label}
|
||||
value={(values[field.name] as string) ?? ""}
|
||||
disabled={pending}
|
||||
onChange={(event) =>
|
||||
setValues({
|
||||
...values,
|
||||
[field.name]: event.currentTarget.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<input
|
||||
aria-label={field.label}
|
||||
value={(values[field.name] as string) ?? ""}
|
||||
disabled={pending}
|
||||
onChange={(event) =>
|
||||
setValues({
|
||||
...values,
|
||||
[field.name]: event.currentTarget.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</label>
|
||||
))}
|
||||
{(validationError || commandError) && (
|
||||
<p role="alert">{validationError || commandError}</p>
|
||||
)}
|
||||
<div className="extension-options">
|
||||
<button disabled={pending} onClick={submit}>
|
||||
{pending ? "Running…" : "Run command"}
|
||||
</button>
|
||||
<button className="quiet" disabled={pending} onClick={onCancel}>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</dialog>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,20 +2,26 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
const fs = await import(["node", "fs"].join(":"));
|
||||
const modelCss = fs.readFileSync("src/components/ModelSelector.css", "utf8");
|
||||
const thinkingCss = fs.readFileSync("src/components/ThinkingSelector.css", "utf8");
|
||||
const quickPaneCss = fs.readFileSync("src/quick-pane/quick-pane.css", "utf8");
|
||||
|
||||
describe("dropdown CSS", () => {
|
||||
it("keeps regular model menu capped with scrolling results", () => {
|
||||
expect(modelCss).toMatch(/\.model-menu\s*\{[\s\S]*max-height:\s*min\(420px, calc\(100vh - 80px\)\)/);
|
||||
expect(modelCss).toMatch(
|
||||
/\.model-menu\s*\{[\s\S]*max-height:\s*min\(420px, calc\(100vh - 80px\)\)/,
|
||||
);
|
||||
expect(modelCss).toMatch(/\.model-results\s*\{[\s\S]*overflow-y:\s*auto/);
|
||||
expect(modelCss).toMatch(/\.model-option\[aria-selected="true"\]/);
|
||||
});
|
||||
|
||||
it("caps compact menus to Quick Pane container below titlebar and toolbar", () => {
|
||||
expect(quickPaneCss).toMatch(/\.quick-pane\s*\{[\s\S]*container-type:\s*size/);
|
||||
expect(quickPaneCss).toMatch(/\.quick-pane \.model-menu\s*\{[\s\S]*max-height:\s*min\(350px, calc\(100cqh - 74px\)\)/);
|
||||
expect(quickPaneCss).toMatch(/\.quick-pane \.model-menu\s*\{[\s\S]*width:\s*min\(400px, calc\(100cqw - 24px\)\)/);
|
||||
expect(thinkingCss).toMatch(/\.thinking-selector-down \.thinking-menu\s*\{[\s\S]*top:\s*calc\(100% \+ 6px\)/);
|
||||
expect(quickPaneCss).toMatch(
|
||||
/\.quick-pane\s*\{[\s\S]*container-type:\s*size/,
|
||||
);
|
||||
expect(quickPaneCss).toMatch(
|
||||
/\.quick-pane \.model-menu\s*\{[\s\S]*max-height:\s*min\(350px, calc\(100cqh - 74px\)\)/,
|
||||
);
|
||||
expect(quickPaneCss).toMatch(
|
||||
/\.quick-pane \.model-menu\s*\{[\s\S]*width:\s*min\(400px, calc\(100cqw - 24px\)\)/,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,137 +1,99 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import type { Extension } from "../workspace/types";
|
||||
|
||||
function controls(container: HTMLElement | null) {
|
||||
return [
|
||||
...(container?.querySelectorAll<HTMLElement>(
|
||||
'button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [href], [tabindex]:not([tabindex="-1"])',
|
||||
) ?? []),
|
||||
];
|
||||
}
|
||||
|
||||
export function ExtensionDialog({
|
||||
extension,
|
||||
onRespond,
|
||||
extension,
|
||||
onRespond,
|
||||
}: {
|
||||
extension?: Extension;
|
||||
onRespond: (response: Record<string, unknown>) => void;
|
||||
extension?: Extension;
|
||||
onRespond: (response: Record<string, unknown>) => void;
|
||||
}) {
|
||||
const ref = useRef<HTMLElement>(null);
|
||||
const opener = useRef<HTMLElement | null>(null);
|
||||
const respond = useRef(onRespond);
|
||||
const [value, setValue] = useState("");
|
||||
respond.current = onRespond;
|
||||
const ref = useRef<HTMLDialogElement>(null);
|
||||
const [value, setValue] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
if (!extension) return;
|
||||
opener.current = document.activeElement as HTMLElement | null;
|
||||
setValue(
|
||||
extension.prefill ?? extension.initialValue ?? extension.text ?? "",
|
||||
);
|
||||
const frame = requestAnimationFrame(() =>
|
||||
controls(ref.current)[0]?.focus(),
|
||||
);
|
||||
const keydown = (event: KeyboardEvent) => {
|
||||
if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
respond.current({ cancelled: true });
|
||||
return;
|
||||
}
|
||||
if (event.key !== "Tab") return;
|
||||
const focusable = controls(ref.current);
|
||||
const first = focusable[0];
|
||||
const last = focusable[focusable.length - 1];
|
||||
if (!first || !last) return;
|
||||
if (event.shiftKey && document.activeElement === first) {
|
||||
event.preventDefault();
|
||||
last.focus();
|
||||
} else if (!event.shiftKey && document.activeElement === last) {
|
||||
event.preventDefault();
|
||||
first.focus();
|
||||
}
|
||||
};
|
||||
window.addEventListener("keydown", keydown);
|
||||
return () => {
|
||||
cancelAnimationFrame(frame);
|
||||
window.removeEventListener("keydown", keydown);
|
||||
opener.current?.focus();
|
||||
};
|
||||
}, [extension]);
|
||||
useEffect(() => {
|
||||
if (!extension) return;
|
||||
setValue(
|
||||
extension.prefill ?? extension.initialValue ?? extension.text ?? "",
|
||||
);
|
||||
const dialog = ref.current;
|
||||
dialog?.showModal();
|
||||
return () => {
|
||||
if (dialog?.open) dialog.close();
|
||||
};
|
||||
}, [extension]);
|
||||
|
||||
if (!extension) return null;
|
||||
return (
|
||||
<div className="extension-backdrop">
|
||||
<section
|
||||
ref={ref}
|
||||
className="extension"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="extension-title"
|
||||
>
|
||||
<p className="extension-eyebrow">Pi agent request</p>
|
||||
<h2 id="extension-title">Review request</h2>
|
||||
<div className="extension-request">
|
||||
<p className="extension-request-label">Requested action</p>
|
||||
<p className="extension-request-action">
|
||||
{extension.title ?? "Pi needs input"}
|
||||
</p>
|
||||
{extension.message && (
|
||||
<>
|
||||
<p className="extension-request-label">Request details</p>
|
||||
<p className="extension-request-details">{extension.message}</p>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{extension.method === "select" && (
|
||||
<div className="extension-options">
|
||||
{extension.options?.map((option) => (
|
||||
<button key={option} onClick={() => onRespond({ value: option })}>
|
||||
{option}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{extension.method === "confirm" && (
|
||||
<div className="extension-options">
|
||||
<button onClick={() => onRespond({ confirmed: true })}>
|
||||
Allow request
|
||||
</button>
|
||||
<button
|
||||
className="quiet"
|
||||
onClick={() => onRespond({ confirmed: false })}
|
||||
>
|
||||
Decline request
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{extension.method === "input" && (
|
||||
<>
|
||||
<input
|
||||
aria-label="Extension value"
|
||||
value={value}
|
||||
placeholder={extension.placeholder}
|
||||
onChange={(event) => setValue(event.currentTarget.value)}
|
||||
/>
|
||||
<button onClick={() => onRespond({ value })}>Submit</button>
|
||||
</>
|
||||
)}
|
||||
{extension.method === "editor" && (
|
||||
<>
|
||||
<textarea
|
||||
aria-label="Extension value"
|
||||
value={value}
|
||||
onChange={(event) => setValue(event.currentTarget.value)}
|
||||
/>
|
||||
<button onClick={() => onRespond({ value })}>Submit</button>
|
||||
</>
|
||||
)}
|
||||
<button
|
||||
className="quiet"
|
||||
onClick={() => onRespond({ cancelled: true })}
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
if (!extension) return null;
|
||||
return (
|
||||
<dialog
|
||||
ref={ref}
|
||||
className="extension"
|
||||
aria-labelledby="extension-title"
|
||||
onCancel={(event) => {
|
||||
event.preventDefault();
|
||||
onRespond({ cancelled: true });
|
||||
}}
|
||||
>
|
||||
<p className="extension-eyebrow">Pi agent request</p>
|
||||
<h2 id="extension-title">Review request</h2>
|
||||
<div className="extension-request">
|
||||
<p className="extension-request-label">Requested action</p>
|
||||
<p className="extension-request-action">
|
||||
{extension.title ?? "Pi needs input"}
|
||||
</p>
|
||||
{extension.message && (
|
||||
<>
|
||||
<p className="extension-request-label">Request details</p>
|
||||
<p className="extension-request-details">{extension.message}</p>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{extension.method === "select" && (
|
||||
<div className="extension-options">
|
||||
{extension.options?.map((option) => (
|
||||
<button key={option} onClick={() => onRespond({ value: option })}>
|
||||
{option}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{extension.method === "confirm" && (
|
||||
<div className="extension-options">
|
||||
<button onClick={() => onRespond({ confirmed: true })}>
|
||||
Allow request
|
||||
</button>
|
||||
<button
|
||||
className="quiet"
|
||||
onClick={() => onRespond({ confirmed: false })}
|
||||
>
|
||||
Decline request
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{extension.method === "input" && (
|
||||
<>
|
||||
<input
|
||||
aria-label="Extension value"
|
||||
value={value}
|
||||
placeholder={extension.placeholder}
|
||||
onChange={(event) => setValue(event.currentTarget.value)}
|
||||
/>
|
||||
<button onClick={() => onRespond({ value })}>Submit</button>
|
||||
</>
|
||||
)}
|
||||
{extension.method === "editor" && (
|
||||
<>
|
||||
<textarea
|
||||
aria-label="Extension value"
|
||||
value={value}
|
||||
onChange={(event) => setValue(event.currentTarget.value)}
|
||||
/>
|
||||
<button onClick={() => onRespond({ value })}>Submit</button>
|
||||
</>
|
||||
)}
|
||||
<button className="quiet" onClick={() => onRespond({ cancelled: true })}>
|
||||
Cancel
|
||||
</button>
|
||||
</dialog>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import { type RefObject, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import type { DirectorySession } from "../workspace/types";
|
||||
|
||||
const focusableSelector =
|
||||
'button:not(:disabled), input:not(:disabled), [href], [tabindex]:not([tabindex="-1"])';
|
||||
|
||||
function sessionTitle(session: DirectorySession) {
|
||||
return session.name ?? session.firstMessage ?? "Untitled session";
|
||||
}
|
||||
@@ -26,9 +23,7 @@ function SessionRow({
|
||||
onOpen: (session: DirectorySession) => void;
|
||||
}) {
|
||||
const showPreview = Boolean(
|
||||
session.name &&
|
||||
session.firstMessage &&
|
||||
session.firstMessage !== session.name,
|
||||
session.name && session.firstMessage && session.firstMessage !== session.name,
|
||||
);
|
||||
return (
|
||||
<li>
|
||||
@@ -71,47 +66,6 @@ function SessionResults({
|
||||
);
|
||||
}
|
||||
|
||||
function useDialogFocus(
|
||||
dialogRef: RefObject<HTMLElement | null>,
|
||||
searchRef: RefObject<HTMLInputElement | null>,
|
||||
onClose: () => void,
|
||||
) {
|
||||
const openerRef = useRef<HTMLElement | null>(
|
||||
document.activeElement as HTMLElement | null,
|
||||
);
|
||||
useEffect(() => {
|
||||
const dialog = dialogRef.current;
|
||||
const controls = () => [
|
||||
...(dialog?.querySelectorAll<HTMLElement>(focusableSelector) ?? []),
|
||||
];
|
||||
searchRef.current?.focus();
|
||||
const keydown = (event: KeyboardEvent) => {
|
||||
if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
onClose();
|
||||
return;
|
||||
}
|
||||
if (event.key !== "Tab") return;
|
||||
const focusable = controls();
|
||||
const first = focusable[0];
|
||||
const last = focusable[focusable.length - 1];
|
||||
if (!first || !last) return;
|
||||
if (event.shiftKey && document.activeElement === first) {
|
||||
event.preventDefault();
|
||||
last.focus();
|
||||
} else if (!event.shiftKey && document.activeElement === last) {
|
||||
event.preventDefault();
|
||||
first.focus();
|
||||
}
|
||||
};
|
||||
window.addEventListener("keydown", keydown);
|
||||
return () => {
|
||||
window.removeEventListener("keydown", keydown);
|
||||
openerRef.current?.focus();
|
||||
};
|
||||
}, [dialogRef, onClose, searchRef]);
|
||||
}
|
||||
|
||||
export function SessionPicker({
|
||||
sessions,
|
||||
onOpen,
|
||||
@@ -122,55 +76,56 @@ export function SessionPicker({
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const [query, setQuery] = useState("");
|
||||
const dialogRef = useRef<HTMLElement>(null);
|
||||
const searchRef = useRef<HTMLInputElement>(null);
|
||||
const dialogRef = useRef<HTMLDialogElement>(null);
|
||||
const normalizedQuery = query.trim().toLocaleLowerCase();
|
||||
const filteredSessions = useMemo(
|
||||
() => sessions.filter((session) => matchesQuery(session, normalizedQuery)),
|
||||
[normalizedQuery, sessions],
|
||||
);
|
||||
useDialogFocus(dialogRef, searchRef, onClose);
|
||||
useEffect(() => {
|
||||
const dialog = dialogRef.current;
|
||||
dialog?.showModal();
|
||||
return () => {
|
||||
if (dialog?.open) dialog.close();
|
||||
};
|
||||
}, []);
|
||||
const resultLabel = `${filteredSessions.length} saved session${filteredSessions.length === 1 ? "" : "s"}`;
|
||||
return (
|
||||
<div className="modal-backdrop">
|
||||
<section
|
||||
ref={dialogRef}
|
||||
className="session-picker"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="session-picker-title"
|
||||
>
|
||||
<div className="picker-heading">
|
||||
<h2 id="session-picker-title">Saved sessions</h2>
|
||||
<button onClick={onClose}>Close</button>
|
||||
</div>
|
||||
<div className="session-search">
|
||||
<label className="sr-only" htmlFor="session-search">
|
||||
Search saved sessions
|
||||
</label>
|
||||
<input
|
||||
ref={searchRef}
|
||||
id="session-search"
|
||||
type="search"
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
placeholder="Search by name, message, or ID"
|
||||
aria-controls="session-results"
|
||||
/>
|
||||
</div>
|
||||
<p className="session-result-count" role="status" aria-live="polite">
|
||||
{sessions.length ? resultLabel : "No saved sessions"}
|
||||
</p>
|
||||
{sessions.length === 0 ? (
|
||||
<p className="muted">No saved sessions for this directory.</p>
|
||||
) : (
|
||||
<SessionResults
|
||||
sessions={filteredSessions}
|
||||
query={query}
|
||||
onOpen={onOpen}
|
||||
/>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
<dialog
|
||||
ref={dialogRef}
|
||||
className="session-picker"
|
||||
aria-labelledby="session-picker-title"
|
||||
onCancel={(event) => {
|
||||
event.preventDefault();
|
||||
onClose();
|
||||
}}
|
||||
>
|
||||
<div className="picker-heading">
|
||||
<h2 id="session-picker-title">Saved sessions</h2>
|
||||
<button onClick={onClose}>Close</button>
|
||||
</div>
|
||||
<div className="session-search">
|
||||
<label className="sr-only" htmlFor="session-search">
|
||||
Search saved sessions
|
||||
</label>
|
||||
<input
|
||||
autoFocus
|
||||
id="session-search"
|
||||
type="search"
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
placeholder="Search by name, message, or ID"
|
||||
aria-controls="session-results"
|
||||
/>
|
||||
</div>
|
||||
<p className="session-result-count" role="status" aria-live="polite">
|
||||
{sessions.length ? resultLabel : "No saved sessions"}
|
||||
</p>
|
||||
{sessions.length === 0 ? (
|
||||
<p className="muted">No saved sessions for this directory.</p>
|
||||
) : (
|
||||
<SessionResults sessions={filteredSessions} query={query} onOpen={onOpen} />
|
||||
)}
|
||||
</dialog>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,19 +11,8 @@
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.thinking-menu {
|
||||
grid-template-rows: minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.thinking-selector-down .thinking-menu {
|
||||
top: calc(100% + 6px);
|
||||
bottom: auto;
|
||||
}
|
||||
|
||||
.thinking-options {
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.thinking-option {
|
||||
font-size: inherit;
|
||||
.thinking-trigger {
|
||||
appearance: auto;
|
||||
padding-right: 6px;
|
||||
background-image: none;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
import {
|
||||
fireEvent,
|
||||
render,
|
||||
screen,
|
||||
waitFor,
|
||||
within,
|
||||
} from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { ThinkingSelector } from "./ThinkingSelector";
|
||||
|
||||
@@ -19,6 +12,7 @@ const model = {
|
||||
xhigh: "xhigh",
|
||||
},
|
||||
};
|
||||
|
||||
const fullModel = {
|
||||
reasoning: true,
|
||||
thinkingLevelMap: {
|
||||
@@ -31,176 +25,47 @@ const fullModel = {
|
||||
};
|
||||
|
||||
describe("ThinkingSelector", () => {
|
||||
it("uses reconciled model options and marks selected level", async () => {
|
||||
const user = userEvent.setup();
|
||||
it("uses reconciled model options", () => {
|
||||
render(
|
||||
<ThinkingSelector model={model} value="medium" onChange={vi.fn()} />,
|
||||
);
|
||||
|
||||
const trigger = screen.getByRole("button", { name: "Thinking Off" });
|
||||
await user.click(trigger);
|
||||
const menu = screen.getByRole("listbox", { name: "Thinking options" });
|
||||
const select = screen.getByRole("combobox", { name: "Thinking" });
|
||||
expect(select).toHaveValue("off");
|
||||
expect(
|
||||
within(menu)
|
||||
.getAllByRole("option")
|
||||
.map((option) => option.textContent),
|
||||
screen.getAllByRole("option").map((option) => option.textContent),
|
||||
).toEqual(["Off", "High", "XHigh"]);
|
||||
expect(within(menu).getByRole("option", { name: "Off" })).toHaveAttribute(
|
||||
"aria-selected",
|
||||
"true",
|
||||
);
|
||||
});
|
||||
|
||||
it("selects an option, closes menu, and restores trigger focus", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onChange = vi.fn();
|
||||
render(<ThinkingSelector model={model} value="off" onChange={onChange} />);
|
||||
|
||||
const trigger = screen.getByRole("button", { name: "Thinking Off" });
|
||||
await user.click(trigger);
|
||||
await user.click(screen.getByRole("option", { name: "High" }));
|
||||
expect(onChange).toHaveBeenCalledWith("high");
|
||||
expect(
|
||||
screen.queryByRole("listbox", { name: "Thinking options" }),
|
||||
).toBeNull();
|
||||
await waitFor(() => expect(trigger).toHaveFocus());
|
||||
});
|
||||
|
||||
it("roves options with arrows, Home, End, and Enter", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onChange = vi.fn();
|
||||
render(
|
||||
<ThinkingSelector model={fullModel} value="medium" onChange={onChange} />,
|
||||
);
|
||||
|
||||
const trigger = screen.getByRole("button", { name: "Thinking Medium" });
|
||||
await user.click(trigger);
|
||||
const menu = screen.getByRole("listbox", { name: "Thinking options" });
|
||||
const medium = within(menu).getByRole("option", { name: "Medium" });
|
||||
await waitFor(() => expect(medium).toHaveFocus());
|
||||
expect(medium).toHaveAttribute("tabindex", "0");
|
||||
|
||||
await user.keyboard("{ArrowDown}");
|
||||
await waitFor(() =>
|
||||
expect(within(menu).getByRole("option", { name: "High" })).toHaveFocus(),
|
||||
);
|
||||
await user.keyboard("{ArrowUp}{Home}");
|
||||
await waitFor(() =>
|
||||
expect(within(menu).getByRole("option", { name: "Off" })).toHaveFocus(),
|
||||
);
|
||||
await user.keyboard("{End}");
|
||||
await waitFor(() =>
|
||||
expect(within(menu).getByRole("option", { name: "XHigh" })).toHaveFocus(),
|
||||
);
|
||||
await user.keyboard("{Enter}");
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith("xhigh");
|
||||
expect(
|
||||
screen.queryByRole("listbox", { name: "Thinking options" }),
|
||||
).toBeNull();
|
||||
await waitFor(() => expect(trigger).toHaveFocus());
|
||||
});
|
||||
|
||||
it("selects active option with Space and cycles typeahead matches", async () => {
|
||||
const user = userEvent.setup();
|
||||
it("reports native selection changes", () => {
|
||||
const onChange = vi.fn();
|
||||
render(
|
||||
<ThinkingSelector model={fullModel} value="off" onChange={onChange} />,
|
||||
);
|
||||
|
||||
const trigger = screen.getByRole("button", { name: "Thinking Off" });
|
||||
await user.click(trigger);
|
||||
const menu = screen.getByRole("listbox", { name: "Thinking options" });
|
||||
await waitFor(() =>
|
||||
expect(within(menu).getByRole("option", { name: "Off" })).toHaveFocus(),
|
||||
);
|
||||
await user.keyboard("m");
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
within(menu).getByRole("option", { name: "Minimal" }),
|
||||
).toHaveFocus(),
|
||||
);
|
||||
await user.keyboard("m");
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
within(menu).getByRole("option", { name: "Medium" }),
|
||||
).toHaveFocus(),
|
||||
);
|
||||
await user.keyboard(" ");
|
||||
fireEvent.change(screen.getByRole("combobox", { name: "Thinking" }), {
|
||||
target: { value: "high" },
|
||||
});
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith("medium");
|
||||
expect(
|
||||
screen.queryByRole("listbox", { name: "Thinking options" }),
|
||||
).toBeNull();
|
||||
await waitFor(() => expect(trigger).toHaveFocus());
|
||||
expect(onChange).toHaveBeenCalledWith("high");
|
||||
});
|
||||
|
||||
it("closes on Escape with focus restore and outside pointer without closing pane", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<ThinkingSelector model={model} value="high" onChange={vi.fn()} />);
|
||||
|
||||
const trigger = screen.getByRole("button", { name: "Thinking High" });
|
||||
await user.click(trigger);
|
||||
await waitFor(() =>
|
||||
expect(screen.getByRole("option", { name: "High" })).toHaveFocus(),
|
||||
);
|
||||
await user.keyboard("{Escape}");
|
||||
expect(
|
||||
screen.queryByRole("listbox", { name: "Thinking options" }),
|
||||
).toBeNull();
|
||||
await waitFor(() => expect(trigger).toHaveFocus());
|
||||
|
||||
await user.click(trigger);
|
||||
fireEvent.pointerDown(document.body);
|
||||
expect(
|
||||
screen.queryByRole("listbox", { name: "Thinking options" }),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("closes an open menu when disabled without restoring focus", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onChange = vi.fn();
|
||||
const { rerender } = render(
|
||||
<ThinkingSelector model={model} value="high" onChange={onChange} />,
|
||||
);
|
||||
const trigger = screen.getByRole("button", { name: "Thinking High" });
|
||||
|
||||
await user.click(trigger);
|
||||
const option = screen.getByRole("option", { name: "High" });
|
||||
await waitFor(() => expect(option).toHaveFocus());
|
||||
rerender(
|
||||
it("supports labels, disabled state, and control classes", () => {
|
||||
render(
|
||||
<ThinkingSelector
|
||||
label="Default thinking"
|
||||
model={model}
|
||||
value="high"
|
||||
disabled
|
||||
onChange={onChange}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(
|
||||
screen.queryByRole("listbox", { name: "Thinking options" }),
|
||||
).toBeNull();
|
||||
expect(trigger).toBeDisabled();
|
||||
expect(trigger).not.toHaveFocus();
|
||||
fireEvent.click(option);
|
||||
option.focus();
|
||||
fireEvent.keyDown(option, { key: "Enter" });
|
||||
fireEvent.click(option, { detail: 0 });
|
||||
expect(onChange).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("supports disabled and downward trigger placement", () => {
|
||||
const { container } = render(
|
||||
<ThinkingSelector
|
||||
value="off"
|
||||
disabled
|
||||
placement="down"
|
||||
className="compact"
|
||||
controlClassName="toolbar-control"
|
||||
onChange={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
expect(screen.getByRole("button", { name: "Thinking Off" })).toBeDisabled();
|
||||
expect(
|
||||
container.querySelector(".thinking-selector-down"),
|
||||
).toBeInTheDocument();
|
||||
|
||||
const select = screen.getByRole("combobox", { name: "Default thinking" });
|
||||
expect(select).toBeDisabled();
|
||||
expect(select).toHaveClass("toolbar-control");
|
||||
expect(select.closest("label")).toHaveClass("compact");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,240 +1,53 @@
|
||||
import { useEffect, useId, useRef, useState } from "react";
|
||||
import { reconcileThinkingLevel, thinkingLevelOptions } from "../model-catalog";
|
||||
import type { Model } from "../workspace/types";
|
||||
import "./ModelSelector.css";
|
||||
import "./ThinkingSelector.css";
|
||||
|
||||
type ThinkingSelectorProps = {
|
||||
model?: Model;
|
||||
label?: string;
|
||||
value: string;
|
||||
disabled?: boolean;
|
||||
placement?: "up" | "down";
|
||||
className?: string;
|
||||
controlClassName?: string;
|
||||
onChange: (level: string) => void;
|
||||
model?: Model;
|
||||
label?: string;
|
||||
value: string;
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
controlClassName?: string;
|
||||
onChange: (level: string) => void;
|
||||
};
|
||||
|
||||
export function ThinkingSelector({
|
||||
model,
|
||||
label = "Thinking",
|
||||
value,
|
||||
disabled = false,
|
||||
placement = "up",
|
||||
className,
|
||||
controlClassName,
|
||||
onChange,
|
||||
}: ThinkingSelectorProps) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [activeIndex, setActiveIndex] = useState(0);
|
||||
const openRef = useRef(false);
|
||||
const disabledRef = useRef(disabled);
|
||||
const focusFrameRef = useRef<number | undefined>(undefined);
|
||||
const typeaheadRef = useRef({ query: "", time: 0 });
|
||||
const rootRef = useRef<HTMLDivElement>(null);
|
||||
const triggerRef = useRef<HTMLButtonElement>(null);
|
||||
const optionRefs = useRef<(HTMLButtonElement | null)[]>([]);
|
||||
disabledRef.current = disabled;
|
||||
const labelId = useId();
|
||||
const valueId = useId();
|
||||
const menuId = useId();
|
||||
const options = thinkingLevelOptions(model);
|
||||
const selected = reconcileThinkingLevel(model, value);
|
||||
const selectedIndex = options.findIndex(
|
||||
(option) => option.value === selected,
|
||||
);
|
||||
const selectedOption = options[selectedIndex];
|
||||
const classes = [
|
||||
"thinking-selector",
|
||||
`thinking-selector-${placement}`,
|
||||
model,
|
||||
label = "Thinking",
|
||||
value,
|
||||
disabled = false,
|
||||
className,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" ");
|
||||
const closeMenu = (restoreFocus = false) => {
|
||||
if (!openRef.current) return;
|
||||
openRef.current = false;
|
||||
setOpen(false);
|
||||
typeaheadRef.current = { query: "", time: 0 };
|
||||
if (restoreFocus) {
|
||||
window.cancelAnimationFrame(focusFrameRef.current ?? 0);
|
||||
focusFrameRef.current = window.requestAnimationFrame(() => {
|
||||
focusFrameRef.current = undefined;
|
||||
if (!disabledRef.current) triggerRef.current?.focus();
|
||||
});
|
||||
}
|
||||
};
|
||||
const openMenu = () => {
|
||||
if (disabledRef.current || openRef.current) return;
|
||||
setActiveIndex(selectedIndex >= 0 ? selectedIndex : 0);
|
||||
openRef.current = true;
|
||||
setOpen(true);
|
||||
};
|
||||
const selectOption = (index: number) => {
|
||||
const option = options[index];
|
||||
if (!option || disabledRef.current) return;
|
||||
onChange(option.value);
|
||||
closeMenu(true);
|
||||
};
|
||||
const moveActiveOption = (direction: 1 | -1) => {
|
||||
setActiveIndex(
|
||||
(index) => (index + direction + options.length) % options.length,
|
||||
);
|
||||
};
|
||||
const typeahead = (key: string) => {
|
||||
const now = Date.now();
|
||||
const previous = typeaheadRef.current;
|
||||
let query = now - previous.time < 500 ? `${previous.query}${key}` : key;
|
||||
let matches = options
|
||||
.map((option, index) => ({ option, index }))
|
||||
.filter(({ option }) =>
|
||||
option.label.toLocaleLowerCase().startsWith(query),
|
||||
);
|
||||
if (!matches.length && query.length > 1) {
|
||||
query = key;
|
||||
matches = options
|
||||
.map((option, index) => ({ option, index }))
|
||||
.filter(({ option }) =>
|
||||
option.label.toLocaleLowerCase().startsWith(query),
|
||||
);
|
||||
}
|
||||
typeaheadRef.current = { query, time: now };
|
||||
if (!matches.length) return;
|
||||
const next = matches.find(({ index }) => index > activeIndex) ?? matches[0];
|
||||
setActiveIndex(next.index);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!disabled) return;
|
||||
window.cancelAnimationFrame(focusFrameRef.current ?? 0);
|
||||
focusFrameRef.current = undefined;
|
||||
closeMenu();
|
||||
}, [disabled]);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
openRef.current = false;
|
||||
window.cancelAnimationFrame(focusFrameRef.current ?? 0);
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const focusFrame = window.requestAnimationFrame(() =>
|
||||
optionRefs.current[activeIndex]?.focus(),
|
||||
);
|
||||
return () => window.cancelAnimationFrame(focusFrame);
|
||||
}, [activeIndex, open]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const closeOnEscape = (event: KeyboardEvent) => {
|
||||
if (event.key !== "Escape") return;
|
||||
event.preventDefault();
|
||||
closeMenu(true);
|
||||
};
|
||||
const closeOutside = (event: PointerEvent) => {
|
||||
if (!rootRef.current?.contains(event.target as Node)) closeMenu();
|
||||
};
|
||||
window.addEventListener("keydown", closeOnEscape);
|
||||
window.addEventListener("pointerdown", closeOutside);
|
||||
return () => {
|
||||
window.removeEventListener("keydown", closeOnEscape);
|
||||
window.removeEventListener("pointerdown", closeOutside);
|
||||
};
|
||||
}, [open]);
|
||||
|
||||
return (
|
||||
<div className={classes}>
|
||||
<span id={labelId}>{label}</span>
|
||||
<div className="model-selector thinking-popup" ref={rootRef}>
|
||||
<button
|
||||
ref={triggerRef}
|
||||
type="button"
|
||||
className={["model-trigger", "thinking-trigger", controlClassName]
|
||||
.filter(Boolean)
|
||||
.join(" ")}
|
||||
aria-expanded={open}
|
||||
aria-haspopup="listbox"
|
||||
aria-controls={open ? menuId : undefined}
|
||||
aria-labelledby={`${labelId} ${valueId}`}
|
||||
disabled={disabled}
|
||||
onClick={() => {
|
||||
if (disabledRef.current) return;
|
||||
if (openRef.current) closeMenu();
|
||||
else openMenu();
|
||||
}}
|
||||
controlClassName,
|
||||
onChange,
|
||||
}: ThinkingSelectorProps) {
|
||||
const options = thinkingLevelOptions(model);
|
||||
return (
|
||||
<label
|
||||
className={["thinking-selector", className]
|
||||
.filter(Boolean)
|
||||
.join(" ")}
|
||||
>
|
||||
<span id={valueId}>{selectedOption?.label ?? "Off"}</span>
|
||||
</button>
|
||||
{open && (
|
||||
<div
|
||||
id={menuId}
|
||||
className="model-menu thinking-menu"
|
||||
role="listbox"
|
||||
aria-label={`${label} options`}
|
||||
>
|
||||
<div className="model-results thinking-options">
|
||||
{options.map((option, index) => (
|
||||
<button
|
||||
ref={(element) => {
|
||||
optionRefs.current[index] = element;
|
||||
}}
|
||||
type="button"
|
||||
className="model-option thinking-option"
|
||||
role="option"
|
||||
aria-selected={option.value === selected}
|
||||
tabIndex={index === activeIndex ? 0 : -1}
|
||||
value={option.value}
|
||||
key={option.value}
|
||||
onClick={() => selectOption(index)}
|
||||
onKeyDown={(event) => {
|
||||
switch (event.key) {
|
||||
case "ArrowDown":
|
||||
event.preventDefault();
|
||||
moveActiveOption(1);
|
||||
break;
|
||||
case "ArrowUp":
|
||||
event.preventDefault();
|
||||
moveActiveOption(-1);
|
||||
break;
|
||||
case "Home":
|
||||
event.preventDefault();
|
||||
setActiveIndex(0);
|
||||
break;
|
||||
case "End":
|
||||
event.preventDefault();
|
||||
setActiveIndex(options.length - 1);
|
||||
break;
|
||||
case "Enter":
|
||||
case " ":
|
||||
event.preventDefault();
|
||||
selectOption(activeIndex);
|
||||
break;
|
||||
case "Escape":
|
||||
event.preventDefault();
|
||||
closeMenu(true);
|
||||
break;
|
||||
default:
|
||||
if (
|
||||
event.key.length === 1 &&
|
||||
!event.altKey &&
|
||||
!event.ctrlKey &&
|
||||
!event.metaKey
|
||||
) {
|
||||
event.preventDefault();
|
||||
typeahead(event.key.toLocaleLowerCase());
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
{option.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
<span>{label}</span>
|
||||
<select
|
||||
className={[
|
||||
"model-trigger",
|
||||
"thinking-trigger",
|
||||
controlClassName,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" ")}
|
||||
value={reconcileThinkingLevel(model, value)}
|
||||
disabled={disabled}
|
||||
onChange={(event) => onChange(event.currentTarget.value)}
|
||||
>
|
||||
{options.map((option) => (
|
||||
<option value={option.value} key={option.value}>
|
||||
{option.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { fireEvent, render, screen, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { DirectorySidebar } from "./DirectorySidebar";
|
||||
@@ -199,10 +199,9 @@ describe("multi-session navigation", () => {
|
||||
onCommand={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
const user = userEvent.setup();
|
||||
await user.click(screen.getByRole("button", { name: "Thinking Medium" }));
|
||||
const thinking = screen.getByRole("combobox", { name: "Thinking" });
|
||||
expect(
|
||||
screen
|
||||
within(thinking)
|
||||
.getAllByRole("option")
|
||||
.map((option) => option.getAttribute("value")),
|
||||
).toEqual(["off", "minimal", "low", "medium", "xhigh"]);
|
||||
@@ -380,29 +379,16 @@ describe("multi-session navigation", () => {
|
||||
await user.type(search, "missing");
|
||||
expect(screen.getByText(/No saved sessions match/)).toBeInTheDocument();
|
||||
});
|
||||
it("focuses search, traps focus, and restores the opener", async () => {
|
||||
const user = userEvent.setup();
|
||||
const opener = document.createElement("button");
|
||||
document.body.append(opener);
|
||||
opener.focus();
|
||||
it("opens a native modal and handles cancellation", () => {
|
||||
const onClose = vi.fn();
|
||||
const { unmount } = render(
|
||||
<SessionPicker sessions={[]} onOpen={vi.fn()} onClose={onClose} />,
|
||||
);
|
||||
const search = screen.getByRole("searchbox", {
|
||||
name: "Search saved sessions",
|
||||
});
|
||||
const close = screen.getByRole("button", { name: "Close" });
|
||||
expect(search).toHaveFocus();
|
||||
await user.keyboard("{Shift>}{Tab}{/Shift}");
|
||||
expect(close).toHaveFocus();
|
||||
await user.keyboard("{Shift>}{Tab}{/Shift}");
|
||||
expect(search).toHaveFocus();
|
||||
await user.keyboard("{Escape}");
|
||||
render(<SessionPicker sessions={[]} onOpen={vi.fn()} onClose={onClose} />);
|
||||
const dialog = screen.getByRole("dialog", { name: "Saved sessions" });
|
||||
expect(dialog).toHaveAttribute("open");
|
||||
expect(
|
||||
screen.getByRole("searchbox", { name: "Search saved sessions" }),
|
||||
).toHaveFocus();
|
||||
fireEvent(dialog, new Event("cancel", { cancelable: true }));
|
||||
expect(onClose).toHaveBeenCalled();
|
||||
unmount();
|
||||
expect(opener).toHaveFocus();
|
||||
document.body.removeChild(opener);
|
||||
});
|
||||
it("labels permission requests with the action and exact details", async () => {
|
||||
const user = userEvent.setup();
|
||||
|
||||
@@ -254,12 +254,12 @@ describe("QuickPane", () => {
|
||||
bridgeMock([defaultModels]);
|
||||
const { container } = render(<QuickPane />);
|
||||
const model = await preparedTrigger();
|
||||
const thinking = screen.getByRole("button", { name: "Thinking Medium" });
|
||||
const thinking = screen.getByRole("combobox", { name: "Thinking" });
|
||||
const close = screen.getByRole("button", { name: "Close Quick Pane" });
|
||||
|
||||
for (const control of [model, thinking, close])
|
||||
expect(control).toHaveClass("quick-pane-toolbar-control");
|
||||
expect(thinking).toHaveTextContent("Medium");
|
||||
expect(thinking).toHaveValue("medium");
|
||||
expect(
|
||||
within(container.querySelector(".quick-pane-toolbar")!).queryByRole(
|
||||
"button",
|
||||
@@ -275,7 +275,7 @@ describe("QuickPane", () => {
|
||||
const toolbar = container.querySelector(".quick-pane-toolbar")!;
|
||||
const controls = [
|
||||
await preparedTrigger(),
|
||||
screen.getByRole("button", { name: "Thinking Medium" }),
|
||||
screen.getByRole("combobox", { name: "Thinking" }),
|
||||
screen.getByRole("button", { name: "Close Quick Pane" }),
|
||||
];
|
||||
|
||||
@@ -296,9 +296,7 @@ describe("QuickPane", () => {
|
||||
fireEvent.pointerDown(
|
||||
screen.getByRole("button", { name: "Close Quick Pane" }),
|
||||
);
|
||||
fireEvent.pointerDown(
|
||||
screen.getByRole("button", { name: "Thinking Medium" }),
|
||||
);
|
||||
fireEvent.pointerDown(screen.getByRole("combobox", { name: "Thinking" }));
|
||||
expect(mocks.startDragging).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
@@ -449,9 +447,9 @@ describe("QuickPane", () => {
|
||||
});
|
||||
render(<QuickPane />);
|
||||
await preparedTrigger();
|
||||
expect(
|
||||
screen.getByRole("button", { name: "Thinking High" }),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByRole("combobox", { name: "Thinking" })).toHaveValue(
|
||||
"high",
|
||||
);
|
||||
await ask("Inspect");
|
||||
await waitFor(() =>
|
||||
expect(mocks.invoke).toHaveBeenCalledWith("set_thinking_level", {
|
||||
@@ -481,14 +479,13 @@ describe("QuickPane", () => {
|
||||
);
|
||||
render(<QuickPane />);
|
||||
await preparedTrigger();
|
||||
const thinking = screen.getByRole("button", { name: "Thinking Off" });
|
||||
await userEvent.click(thinking);
|
||||
const thinking = screen.getByRole("combobox", { name: "Thinking" });
|
||||
expect(
|
||||
within(screen.getByRole("listbox", { name: "Thinking options" }))
|
||||
within(thinking)
|
||||
.getAllByRole("option")
|
||||
.map((option) => option.textContent),
|
||||
).toEqual(["Off", "High"]);
|
||||
await userEvent.click(screen.getByRole("option", { name: "High" }));
|
||||
fireEvent.change(thinking, { target: { value: "high" } });
|
||||
await ask("Inspect");
|
||||
await waitFor(() =>
|
||||
expect(mocks.invoke).toHaveBeenCalledWith("set_thinking_level", {
|
||||
@@ -498,7 +495,7 @@ describe("QuickPane", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("closes thinking menu while Ctrl+N replaces chat", async () => {
|
||||
it("disables thinking selection while Ctrl+N replaces chat", async () => {
|
||||
const closing = deferred<void>();
|
||||
const tracker = bridgeMock([defaultModels, defaultModels]);
|
||||
const baseImplementation = mocks.invoke.getMockImplementation();
|
||||
@@ -510,17 +507,10 @@ describe("QuickPane", () => {
|
||||
);
|
||||
render(<QuickPane />);
|
||||
await preparedTrigger();
|
||||
const thinking = screen.getByRole("button", { name: "Thinking Medium" });
|
||||
await userEvent.click(thinking);
|
||||
expect(
|
||||
screen.getByRole("listbox", { name: "Thinking options" }),
|
||||
).toBeInTheDocument();
|
||||
const thinking = screen.getByRole("combobox", { name: "Thinking" });
|
||||
|
||||
fireEvent.keyDown(window, { key: "n", ctrlKey: true, cancelable: true });
|
||||
await waitFor(() => expect(thinking).toBeDisabled());
|
||||
expect(
|
||||
screen.queryByRole("listbox", { name: "Thinking options" }),
|
||||
).toBeNull();
|
||||
|
||||
await act(async () => closing.resolve());
|
||||
await waitFor(() => expect(tracker.runtimeCount()).toBe(2));
|
||||
|
||||
@@ -1179,7 +1179,6 @@ export default function QuickPane() {
|
||||
<ThinkingSelector
|
||||
className="quick-pane-thinking"
|
||||
controlClassName="quick-pane-toolbar-control"
|
||||
placement="down"
|
||||
model={selectedCatalogModel}
|
||||
value={thinkingLevel}
|
||||
disabled={catalogOverlayActive || runActive || chatReplacing}
|
||||
|
||||
@@ -533,16 +533,10 @@ body {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.quick-pane-exchange .extension-backdrop,
|
||||
.quick-pane-exchange .extension {
|
||||
position: static;
|
||||
display: block;
|
||||
width: min(400px, calc(100cqw - 24px));
|
||||
max-height: calc(100cqh - 48px);
|
||||
padding: 7px 9px;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.quick-pane-exchange .extension-backdrop {
|
||||
flex: 0 0 auto;
|
||||
border: 1px solid #65533e;
|
||||
border-radius: 7px;
|
||||
background: #302b25;
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import { cleanup } from "@testing-library/react";
|
||||
import { afterEach } from "vitest";
|
||||
|
||||
if (!HTMLDialogElement.prototype.showModal) {
|
||||
HTMLDialogElement.prototype.showModal = function showModal() {
|
||||
this.open = true;
|
||||
};
|
||||
HTMLDialogElement.prototype.close = function close() {
|
||||
this.open = false;
|
||||
};
|
||||
}
|
||||
|
||||
afterEach(cleanup);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { render, screen, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { ConversationWorkspace } from "./components/ConversationWorkspace";
|
||||
import QuickPane from "./quick-pane/QuickPane";
|
||||
@@ -128,18 +127,12 @@ describe("thinking selector parity", () => {
|
||||
"matches Pi %s semantics in Conversation Workspace and Quick Pane",
|
||||
async (_name, metadata, expected) => {
|
||||
renderSurfaces({ provider: "provider", id: "model", ...metadata });
|
||||
const user = userEvent.setup();
|
||||
const triggers = await screen.findAllByRole("button", {
|
||||
name: /Thinking /,
|
||||
const selectors = await screen.findAllByRole("combobox", {
|
||||
name: "Thinking",
|
||||
});
|
||||
expect(triggers).toHaveLength(2);
|
||||
for (const trigger of triggers) {
|
||||
await user.click(trigger);
|
||||
expect(options(screen.getByRole("listbox", { name: "Thinking options" }))).toEqual(
|
||||
expected,
|
||||
);
|
||||
await user.click(trigger);
|
||||
}
|
||||
expect(selectors).toHaveLength(2);
|
||||
for (const selector of selectors)
|
||||
expect(options(selector)).toEqual(expected);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -10,9 +10,6 @@ const mocks = vi.hoisted(() => ({
|
||||
|
||||
vi.mock("@tauri-apps/api/core", () => ({ invoke: mocks.invoke }));
|
||||
vi.mock("@tauri-apps/api/event", () => ({ listen: mocks.listen }));
|
||||
vi.mock("@tauri-apps/api/window", () => ({
|
||||
getCurrentWindow: () => ({}),
|
||||
}));
|
||||
vi.mock("./persistence", () => ({
|
||||
legacyPreferences: () => ({}),
|
||||
loadPresentation: async () => ({
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
import { useCallback, useEffect, useReducer, useRef } from "react";
|
||||
import { initialWorkspaceState, workspaceReducer } from "./reducer";
|
||||
import {
|
||||
@@ -289,7 +288,6 @@ export function useWorkspace() {
|
||||
});
|
||||
}
|
||||
})();
|
||||
const appWindow = getCurrentWindow();
|
||||
const visibility = () =>
|
||||
dispatch({
|
||||
type: "setWindowActive",
|
||||
@@ -310,7 +308,6 @@ export function useWorkspace() {
|
||||
window.removeEventListener("blur", visibility);
|
||||
document.removeEventListener("visibilitychange", visibility);
|
||||
Object.values(timers.current).forEach(clearTimeout);
|
||||
void appWindow;
|
||||
};
|
||||
}, [consumePromotedRuntime, refresh, scheduleSnapshot]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user