@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 +6 -4
- package/extensions/ask-question.ts +20 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# `@henryqw/pi-ask-question`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Pause Pi for one clear user choice, with up to three options or a custom answer.
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|
|
|
7
7
|
## Why
|
|
8
8
|
|
|
9
|
-
- **Created for**:
|
|
10
|
-
- **Advantage**:
|
|
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
|
-
|
|
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
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
:
|
|
41
|
-
|
|
42
|
-
: details.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
}
|