@henryqw/pi-ask-question 0.2.3 → 0.2.4
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 +2 -0
- package/extensions/ask-question.ts +20 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -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
|
}
|