Start local TUI without account login
This commit is contained in:
@@ -26,6 +26,7 @@ pub use model_state::ModelState;
|
||||
use std::io::Write;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use hoshizukimio_acp_lib::{AcpAgentTx, AcpClientRx, acp_send};
|
||||
use hoshizukimio_mio_config::{Capability, Distribution};
|
||||
use hoshizukimio_mio_shell::agent::auth_method::AuthMethodKind;
|
||||
use hoshizukimio_mio_shell::agent::config::Config as AgentConfig;
|
||||
use hoshizukimio_mio_shell::sampling::types::ReasoningEffort;
|
||||
@@ -242,20 +243,25 @@ pub(in crate::acp) async fn initialize_connection(
|
||||
};
|
||||
startup::enter(StartupPhase::AcpInitialize);
|
||||
let agent = initialize(&tx, flags).await?;
|
||||
let (needs_login, login_label, login_method_id, auth_start_mode) =
|
||||
startup_auth_metadata(&agent.auth_methods);
|
||||
startup::enter(StartupPhase::EagerAuth);
|
||||
let (needs_login, login_label, login_method_id, auth_start_mode, auth_meta) =
|
||||
bounded_eager_auth(
|
||||
&tx,
|
||||
&agent.auth_methods,
|
||||
agent.default_auth_method_id.as_ref(),
|
||||
needs_login,
|
||||
login_label,
|
||||
login_method_id,
|
||||
auth_start_mode,
|
||||
)
|
||||
.await;
|
||||
if agent.is_mio_shell && !Distribution::current().allows(Capability::AccountLogin) {
|
||||
// The local shell resolves credentials at the model endpoint and advertises no account methods.
|
||||
(false, None, None, AuthStartMode::Pending, None)
|
||||
} else {
|
||||
let (needs_login, login_label, login_method_id, auth_start_mode) =
|
||||
startup_auth_metadata(&agent.auth_methods);
|
||||
bounded_eager_auth(
|
||||
&tx,
|
||||
&agent.auth_methods,
|
||||
agent.default_auth_method_id.as_ref(),
|
||||
needs_login,
|
||||
login_label,
|
||||
login_method_id,
|
||||
auth_start_mode,
|
||||
)
|
||||
.await
|
||||
};
|
||||
Ok(AcpConnection {
|
||||
tx,
|
||||
rx,
|
||||
|
||||
@@ -30,6 +30,7 @@ use std::path::Path;
|
||||
use agent_client_protocol as acp;
|
||||
use tokio::task::JoinSet;
|
||||
use hoshizukimio_acp_lib::{AcpAgentTx, acp_send};
|
||||
use hoshizukimio_mio_config::{Capability, Distribution};
|
||||
use hoshizukimio_mio_telemetry::startup::{self, StartupPhase};
|
||||
use actions::{
|
||||
ClipboardPasteTarget, Effect, SubagentKillOutcome, SwitchModelError, TaskResult,
|
||||
@@ -2100,7 +2101,7 @@ pub(crate) fn execute(
|
||||
}
|
||||
});
|
||||
}
|
||||
Effect::FetchChangelog => {
|
||||
Effect::FetchChangelog if Distribution::current().allows(Capability::RemoteFetch) => {
|
||||
tasks
|
||||
.spawn(async move {
|
||||
let changelog = tokio::task::spawn_blocking(|| {
|
||||
@@ -2121,6 +2122,7 @@ pub(crate) fn execute(
|
||||
}
|
||||
});
|
||||
}
|
||||
Effect::FetchChangelog => {}
|
||||
Effect::PersistAnnouncementsHidden { hidden_ids } => {
|
||||
tasks
|
||||
.spawn(async move {
|
||||
|
||||
@@ -171,12 +171,12 @@ def verify_acp(binary, root, env):
|
||||
|
||||
@contextlib.contextmanager
|
||||
def terminal(binary, root, env):
|
||||
args = [binary, "--no-leader"]
|
||||
args = [binary, "--no-leader", "Respond with the test phrase."]
|
||||
if os.name == "nt":
|
||||
from winpty import PtyProcess
|
||||
process = PtyProcess.spawn(args, cwd=str(root), env=env, dimensions=(32, 110))
|
||||
try:
|
||||
yield lambda: process.read(16384), process.isalive
|
||||
yield lambda: process.read(16384)
|
||||
finally:
|
||||
if process.isalive():
|
||||
with contextlib.suppress(EOFError):
|
||||
@@ -202,7 +202,7 @@ def terminal(binary, root, env):
|
||||
with subprocess.Popen(args, cwd=root, env=env, stdin=slave, stdout=slave,
|
||||
stderr=slave, start_new_session=True) as process:
|
||||
try:
|
||||
yield lambda: os.read(master, 16384).decode("utf-8", "replace"), lambda: process.poll() is None
|
||||
yield lambda: os.read(master, 16384).decode("utf-8", "replace")
|
||||
finally:
|
||||
process.terminate()
|
||||
try:
|
||||
@@ -217,16 +217,20 @@ def terminal(binary, root, env):
|
||||
def verify_tui(binary, root, env):
|
||||
output = queue.SimpleQueue()
|
||||
screen = ""
|
||||
with terminal(binary, root, env) as (reader, is_alive):
|
||||
with terminal(binary, root, env) as reader:
|
||||
threading.Thread(target=read_stream, args=(reader, output), daemon=True).start()
|
||||
stop = time.monotonic() + 45
|
||||
while (remaining := stop - time.monotonic()) > 0:
|
||||
data = output.get(timeout=remaining)
|
||||
try:
|
||||
data = output.get(timeout=remaining)
|
||||
except queue.Empty:
|
||||
break
|
||||
assert data is not None, screen
|
||||
screen = (screen + data)[-64000:]
|
||||
if "\x1b[" in screen and "mio" in screen.lower() and is_alive():
|
||||
assert "preferred_method=api_key" not in screen and "Login with mio.invalid" not in screen, screen
|
||||
if TEXT in screen:
|
||||
return
|
||||
raise TimeoutError(f"TUI did not render: {screen}")
|
||||
raise TimeoutError(f"TUI did not display a model response: {screen}")
|
||||
|
||||
|
||||
def verify(binary, tui):
|
||||
@@ -314,7 +318,10 @@ def verify(binary, tui):
|
||||
print("Passed ACP initialization and session creation")
|
||||
if tui:
|
||||
verify_tui(binary, root, env)
|
||||
print("Passed TUI startup")
|
||||
while not requests.empty():
|
||||
requests.get_nowait()
|
||||
assert unexpected.empty(), unexpected.get_nowait()
|
||||
print("Passed interactive TUI inference")
|
||||
|
||||
settings.write_text(
|
||||
f'[model.smoke]\nmodel = "{MODEL}"\nbase_url = "{api}/redirect/v1"\n'
|
||||
|
||||
Reference in New Issue
Block a user