review classifier: run on ACP when the swarm settings choose it
The swarm settings gain `runtime` (`api-key`, the default, or `acp`) and an `acp` provider record: an https base URL, the provider's model, and its prices per million tokens. A PUT now changes only the fields its body names, so the settings form that sends model, effort and limit leaves the runtime alone; `null` clears `effort` or `acp`. The body stays strict, and the stored document keeps #5192's lenient read. The controller sends the runtime in each run request. On `acp` the classifier runs one prompt on a new `opencode acp` session per classification through hive-runtime's AcpRuntime, in a scratch directory, with a config rendered from the settings. opencode runs `read` and other tools without asking, so OPENCODE_PERMISSION {"*":"deny"} takes every tool away from the model, and a deny-all policy refuses any request on top. The title call, which resends the prompt, is turned off. The deadline cancels the turn, and a turn that does not end within 15s of that is dropped, which also covers an agent stuck before its prompt. The answer is the final assistant text, as ACP has no result event. The provider key is read per run from swarm/services/review-classifier/acp-provider, which the bao UI's admins login may create and update, and reaches opencode through AcpRuntime::with_provider_key and the trampoline's allowlist. Each ACP classification's cost is computed from the configured prices and the reported tokens, and added to hyperhive.review_classifier.cost.usage labelled repo, pr, model and currency. Part of #5096
This commit is contained in:
parent
38ee68c31d
commit
1b4e764e5c
24 changed files with 1622 additions and 262 deletions
|
|
@ -415,6 +415,19 @@ impl<P: CompactionPolicy> AcpRuntime<P> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Spawn the agent with `key` in the variable
|
||||
/// [`AcpCommand::api_key_env`] names, in place of the key read from the
|
||||
/// agent's own store path. For a caller that is not an agent and has read
|
||||
/// its key itself; without `api_key_env` the key is not used.
|
||||
#[must_use]
|
||||
pub fn with_provider_key(mut self, key: String) -> Self {
|
||||
self.resolve_key = Arc::new(move |name| {
|
||||
let value = key.clone();
|
||||
Box::pin(async move { Some(KeyVar { name, value }) })
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
/// Names a new session until its first prompt has been answered, so a
|
||||
/// failed first prompt is retried on the same session.
|
||||
fn pending_file(&self) -> PathBuf {
|
||||
|
|
@ -1520,6 +1533,19 @@ done
|
|||
assert_eq!(keys(dir.path()), ["old"]);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_given_provider_key_reaches_the_agent() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut runtime = runtime(dir.path(), "ok").with_provider_key("given".to_owned());
|
||||
runtime.command.api_key_env = Some("TEST_PROVIDER_KEY".to_owned());
|
||||
|
||||
runtime
|
||||
.run(&config(dir.path()), "one", &NoopSink)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(keys(dir.path()), ["given"]);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn an_end_turn_with_output_but_no_usage_succeeds() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
|
|
|||
Loading…
Reference in a new issue