@henryqw/pi-ask-question 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # `@henryqw/pi-ask-question`
2
2
 
3
- Ask the user one interactive question with up to three choices, or a custom answer.
3
+ Pause Pi for one clear user choice, with up to three options or a custom answer.
4
4
 
5
5
  ![Pi asking the user to choose a database](./example.png)
6
6
 
7
7
  ## Why
8
8
 
9
- - **Created for**: Ask the user one interactive question with up to three choices during a Pi session.
10
- - **Advantage**: Show a keyboard-selectable prompt and return one explicit answer instead of parsing free-form chat.
9
+ - **Created for**: Agents and extensions that need one decision before they continue.
10
+ - **Advantage**: A keyboard-selectable prompt returns an explicit answer without parsing free-form chat.
11
11
 
12
12
  ## Install
13
13
 
@@ -17,7 +17,7 @@ pi install npm:@henryqw/pi-ask-question
17
17
 
18
18
  ## Use
19
19
 
20
- Use `ask_question` to pause for one interactive answer.
20
+ Call `ask_question` to pause for one interactive answer. Pi shows the choices and returns the selected or custom answer.
21
21
 
22
22
  ```json
23
23
  {
@@ -36,4 +36,6 @@ Use `ask_question` to pause for one interactive answer.
36
36
 
37
37
  The tool returns an error for empty questions, blank or duplicate labels, empty lists, more than three options, and non-interactive sessions. Aborting the tool closes the pending question.
38
38
 
39
+ While an interactive TUI question is open, the tool publishes `herdr:blocked` with the `Input required` label. It clears the status after completion, cancellation, or failure.
40
+
39
41
  Extensions can reuse the validated interaction with `askQuestion(params, ctx, signal)`. This package export returns the tool's answer details without registering another UI flow.
@@ -31,20 +31,26 @@ export default function askQuestionExtension(pi: ExtensionAPI): void {
31
31
  executionMode: "sequential",
32
32
 
33
33
  async execute(_toolCallId, params, signal, _onUpdate, ctx) {
34
- const details = await askQuestion(params, ctx, signal);
35
- return {
36
- content: [{
37
- type: "text" as const,
38
- text: details.error
39
- ? `Error: ${details.error}`
40
- : !details.answer
41
- ? "User cancelled question"
42
- : details.wasCustom
43
- ? `User wrote: ${details.answer}`
44
- : `User selected: ${details.selectedIndex}. ${details.answer}`,
45
- }],
46
- details,
47
- };
34
+ const interactive = ctx.mode === "tui";
35
+ try {
36
+ if (interactive) pi.events.emit("herdr:blocked", { active: true, label: "Input required" });
37
+ const details = await askQuestion(params, ctx, signal);
38
+ return {
39
+ content: [{
40
+ type: "text" as const,
41
+ text: details.error
42
+ ? `Error: ${details.error}`
43
+ : !details.answer
44
+ ? "User cancelled question"
45
+ : details.wasCustom
46
+ ? `User wrote: ${details.answer}`
47
+ : `User selected: ${details.selectedIndex}. ${details.answer}`,
48
+ }],
49
+ details,
50
+ };
51
+ } finally {
52
+ if (interactive) pi.events.emit("herdr:blocked", { active: false });
53
+ }
48
54
  },
49
55
  });
50
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henryqw/pi-ask-question",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Ask Pi users one interactive question with choices or a custom answer.",
5
5
  "keywords": [
6
6
  "pi-package",