Carry a question in the event model, not in one provider's JSON
A question is now fully described by the event that reports it: the tag it was asked under, each option's label, what it means, and the sample of what picking it would produce, plus whether several may be picked at once. The app renders from that alone. It had been reading Claude Code's tool input to find the parts the event dropped -- that dialect's schema, written out a second time in Kotlin, where no other provider could reach it and where it would drift the first time the schema moved. Echo could not describe an option at all, and llama never will. Answers travel as a list for the same reason. A question that takes one answer sends a list of one rather than being a different shape, and the one place that flattens it is where the CLI is spoken to: its answers map holds a string, so several choices are joined there. That join was in the phone. Also here because it is the same rule: the permission ask reuses the question body rather than owning a second one, so Allow/Deny renders and resolves through exactly the code an AskUserQuestion does. Verified against both, since a refactor that only satisfies the case it was written for has been tried on the half that cannot fail: a two question `/ask` answered from the phone, one option and then two, and a real sonnet session's `rm -f` permission asked, allowed, and run.
This commit is contained in:
1 parent
fea8e7e92b
commit
bebaae7a94
13 files changed
+419
-237
No files matched your search
+12
-3
@@ -15,7 +15,7 @@
|
||||
//! (a backlog past CATCH_UP_LIMIT arrives as a
|
||||
//! `reset` frame plus the newest window)
|
||||
//! POST /sessions/{id}/message {text, attachmentIds?}
|
||||
//! POST /sessions/{id}/answer {questionId, answer} (questions and permissions)
|
||||
//! POST /sessions/{id}/answer {questionId, answers} (questions and permissions)
|
||||
//! POST /sessions/{id}/interrupt
|
||||
//! POST /sessions/{id}/title {title}
|
||||
//! POST /sessions/{id}/model {model}
|
||||
@@ -620,7 +620,11 @@ async fn message(
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct AnswerRequest {
|
||||
question_id: String,
|
||||
answer: String,
|
||||
/// Everything chosen, in the order it was offered. A question that
|
||||
/// takes one answer sends a list of one, so there is one shape here
|
||||
/// rather than a single-answer route and a multi-answer route beside
|
||||
/// it.
|
||||
answers: Vec<String>,
|
||||
}
|
||||
|
||||
async fn answer(
|
||||
@@ -628,7 +632,12 @@ async fn answer(
|
||||
UrlPath(id): UrlPath<String>,
|
||||
axum::Json(body): axum::Json<AnswerRequest>,
|
||||
) -> Result<StatusCode, ApiError> {
|
||||
lookup(&manager, &id)?.answer_question(&body.question_id, &body.answer);
|
||||
if body.answers.is_empty() {
|
||||
return Err(bad_request(anyhow::anyhow!(
|
||||
"an answer needs at least one choice"
|
||||
)));
|
||||
}
|
||||
lookup(&manager, &id)?.answer_question(&body.question_id, &body.answers);
|
||||
Ok(StatusCode::NO_CONTENT)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user