[PR #12046] feat(core): expose Question.ask via API/SDK #14048

Open
opened 2026-02-16 18:18:52 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12046

State: open
Merged: No


What does this PR do?

Fixes: #8384

Important

The LOC changes are misleading, it's mostly tests and generated code.

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 optional options parameter with an awaitAnswers key:
    • When awaitAnswers: true (default): blocks and returns the answers (existing behavior)
    • When awaitAnswers: false: returns the question request ID immediately without waiting for answers
  • Added new /question/ask API endpoint that creates a question request and returns its ID, enabling async question flows from external clients
    • /question/ask endpoint performs session existence validation and returns 404 when the session doesn't exist
  • Extracted Question.AskInput schema from Question.Request to provide a clean input type for the new endpoint (without the server-generated id field)
  • 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.ask refactor in test/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)
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12046 **State:** open **Merged:** No --- ### What does this PR do? Fixes: #8384 > [!IMPORTANT] > The LOC changes are misleading, it's mostly tests and generated code. 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 optional `options` parameter with an `awaitAnswers` key: - When `awaitAnswers: true` (default): blocks and returns the answers (existing behavior) - When `awaitAnswers: false`: returns the question request ID immediately without waiting for answers - **Added new `/question/ask` API endpoint** that creates a question request and returns its ID, enabling async question flows from external clients - **`/question/ask` endpoint performs session existence validation** and returns 404 when the session doesn't exist - **Extracted `Question.AskInput` schema** from `Question.Request` to provide a clean input type for the new endpoint (without the server-generated `id` field) - **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.ask` refactor in `test/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)
yindo added the pull-request label 2026-02-16 18:18:52 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14048