opencode
opencode copied to clipboard
feat(core): expose `Question.ask` via API/SDK
What does this PR do?
Fixes: #8384
Exposes a new POST /question/ask server endpoint that allows clients and the SDK to programmatically ask questions to users without blocking. Key changes:
-
Refactored
Question.ask()function to support an optionaloptionsparameter with anawaitAnswerskey:- When
awaitAnswers: true(default): blocks and returns the answers (existing behavior) - When
awaitAnswers: false: returns the question request ID immediately without waiting for answers
- When
-
Added new
/question/askAPI endpoint that creates a question request and returns its ID, enabling async question flows from external clients-
/question/askendpoint performs session existence validation and returns 404 when the session doesn't exist
-
-
Extracted
Question.AskInputschema fromQuestion.Requestto provide a clean input type for the new endpoint (without the server-generatedidfield) -
Regenerated SDK with the new
Question.ask()method and types (QuestionAskInput,QuestionAskResponses, etc.)
How did you verify your code works?
- Called endpoint locally and tested with my plugin
- Added a test for the
Question.askrefactor intest/question/question.test.ts - Added server endpoint tests in
test/server/question.test.ts:- Happy path: returns question ID and adds to pending list
- Returns 404 when session does not exist
- Returns 400 when session ID format is invalid
- Returns 400 when header exceeds max length (12 chars)