@howaboua/pi-ask 0.0.1 → 0.0.2
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/ask/tool.ts +30 -11
- package/index.ts +5 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,6 +20,8 @@ The agent can present several independently decidable prompts in one tabbed pane
|
|
|
20
20
|
|
|
21
21
|
For work only you can complete—sign-in, authorization, hardware access, or another manual step—the agent can open a handoff and wait until you mark it done or unable to complete.
|
|
22
22
|
|
|
23
|
+
When Pi runs inside Herdr with its Pi integration installed, an open ask panel marks the pane as blocked until you submit, dismiss, or abort it.
|
|
24
|
+
|
|
23
25
|
`Other/rephrase` is always available. Submit it blank when the prompt needs to be rephrased, split, or followed up instead of answered as written.
|
|
24
26
|
|
|
25
27
|
## Prompt commands
|
package/ask/tool.ts
CHANGED
|
@@ -15,10 +15,19 @@ type AskInComposer = (
|
|
|
15
15
|
signal: AbortSignal | undefined,
|
|
16
16
|
) => Promise<unknown>;
|
|
17
17
|
|
|
18
|
+
interface BlockedState {
|
|
19
|
+
active: boolean;
|
|
20
|
+
label: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type OnBlockedChange = (state: BlockedState) => void;
|
|
24
|
+
|
|
18
25
|
export function createAskTool({
|
|
19
26
|
askInComposer,
|
|
27
|
+
onBlockedChange,
|
|
20
28
|
}: {
|
|
21
29
|
askInComposer?: AskInComposer;
|
|
30
|
+
onBlockedChange?: OnBlockedChange;
|
|
22
31
|
} = {}) {
|
|
23
32
|
return defineTool({
|
|
24
33
|
name: "ask",
|
|
@@ -43,17 +52,27 @@ export function createAskTool({
|
|
|
43
52
|
if (!askInComposer && !ctx.hasUI)
|
|
44
53
|
throw new Error("ask requires an interactive UI.");
|
|
45
54
|
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const blockedState = {
|
|
56
|
+
active: true,
|
|
57
|
+
label: handoff ? "Human action needed" : "Waiting for input",
|
|
58
|
+
};
|
|
59
|
+
onBlockedChange?.(blockedState);
|
|
60
|
+
let rawResponses: unknown;
|
|
61
|
+
try {
|
|
62
|
+
rawResponses = askInComposer
|
|
63
|
+
? await askInComposer(prompts, signal)
|
|
64
|
+
: ctx.mode === "tui"
|
|
65
|
+
? await askInTui(ctx, prompts, {
|
|
66
|
+
handoff,
|
|
67
|
+
...(signal ? { signal } : {}),
|
|
68
|
+
})
|
|
69
|
+
: await askWithPiUi(ctx, prompts, {
|
|
70
|
+
handoff,
|
|
71
|
+
...(signal ? { signal } : {}),
|
|
72
|
+
});
|
|
73
|
+
} finally {
|
|
74
|
+
onBlockedChange?.({ ...blockedState, active: false });
|
|
75
|
+
}
|
|
57
76
|
const responses = normalizeResponses(prompts, rawResponses);
|
|
58
77
|
if (!responses) {
|
|
59
78
|
return {
|
package/index.ts
CHANGED
|
@@ -9,7 +9,11 @@ export { createAskTool } from "./ask/tool.js";
|
|
|
9
9
|
const PROMPTS_DIR = join(dirname(fileURLToPath(import.meta.url)), "prompts");
|
|
10
10
|
|
|
11
11
|
export default function humanInTheLoop(pi: ExtensionAPI): void {
|
|
12
|
-
pi.registerTool(
|
|
12
|
+
pi.registerTool(
|
|
13
|
+
createAskTool({
|
|
14
|
+
onBlockedChange: (state) => pi.events.emit("herdr:blocked", state),
|
|
15
|
+
}),
|
|
16
|
+
);
|
|
13
17
|
pi.on("resources_discover", () => {
|
|
14
18
|
const config = loadAskConfig();
|
|
15
19
|
return {
|