@giladbarnea/pi-user-agents 0.0.9 → 0.0.10
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/package.json +4 -3
- package/runner.ts +16 -7
- package/shared.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@giladbarnea/pi-user-agents",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "Run, view, and control background Pi agents.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"test": "bun test"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@earendil-works/pi-coding-agent": "
|
|
36
|
+
"@earendil-works/pi-coding-agent": ">=1.1.0",
|
|
37
37
|
"@earendil-works/pi-tui": "*"
|
|
38
38
|
},
|
|
39
39
|
"publishConfig": {
|
|
@@ -45,7 +45,8 @@
|
|
|
45
45
|
]
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@earendil-works/pi-
|
|
48
|
+
"@earendil-works/pi-ai": "1.1.0",
|
|
49
|
+
"@earendil-works/pi-coding-agent": "1.1.0",
|
|
49
50
|
"@earendil-works/pi-tui": "0.85.1"
|
|
50
51
|
}
|
|
51
52
|
}
|
package/runner.ts
CHANGED
|
@@ -625,7 +625,9 @@ export async function runChildTurns(
|
|
|
625
625
|
): Promise<void> {
|
|
626
626
|
let instruction = initialInstruction;
|
|
627
627
|
while (true) {
|
|
628
|
+
if (runningAgent.aborted) return;
|
|
628
629
|
const turnMessageStart = session.agent.state.messages.length;
|
|
630
|
+
runningAgent.runAborted = false;
|
|
629
631
|
if (!runningAgent.interruptRequested) {
|
|
630
632
|
logSteering(runningAgent.id, "turn-prompt-started", {
|
|
631
633
|
streaming: session.isStreaming,
|
|
@@ -633,8 +635,13 @@ export async function runChildTurns(
|
|
|
633
635
|
});
|
|
634
636
|
await session.prompt(instruction);
|
|
635
637
|
}
|
|
636
|
-
if (runningAgent.
|
|
637
|
-
|
|
638
|
+
if (runningAgent.aborted) return;
|
|
639
|
+
if (runningAgent.interruptRequested || runningAgent.runAborted) {
|
|
640
|
+
const response = interruptedTurnResponse(
|
|
641
|
+
session,
|
|
642
|
+
turnMessageStart,
|
|
643
|
+
runningAgent.interruptRequested ? "Interrupted by user." : "Run cancelled.",
|
|
644
|
+
);
|
|
638
645
|
runningAgent.interruptRequested = false;
|
|
639
646
|
runningAgent.mainContextState = "separate";
|
|
640
647
|
runningAgent.status = "done-waiting-to-post";
|
|
@@ -693,14 +700,14 @@ export async function runChildTurns(
|
|
|
693
700
|
}
|
|
694
701
|
}
|
|
695
702
|
|
|
696
|
-
function interruptedTurnResponse(session: AgentSession, turnMessageStart: number): string {
|
|
703
|
+
function interruptedTurnResponse(session: AgentSession, turnMessageStart: number, reason: string): string {
|
|
697
704
|
const assistantMessages = session.agent.state.messages
|
|
698
705
|
.slice(turnMessageStart)
|
|
699
706
|
.filter((message) => message.role === "assistant");
|
|
700
707
|
const lastAssistantMessage = assistantMessages.at(-1);
|
|
701
708
|
const partialResponse = lastAssistantMessage ? assistantText(lastAssistantMessage).trim() : "";
|
|
702
|
-
if (!partialResponse) return
|
|
703
|
-
return
|
|
709
|
+
if (!partialResponse) return reason;
|
|
710
|
+
return `${reason}\n\n${partialResponse}`;
|
|
704
711
|
}
|
|
705
712
|
|
|
706
713
|
async function createChildSession(
|
|
@@ -835,8 +842,10 @@ export function subscribeToChildSession(
|
|
|
835
842
|
streaming: session.isStreaming,
|
|
836
843
|
messageCount: event.messages.length,
|
|
837
844
|
});
|
|
838
|
-
if (event.type === "agent_settled")
|
|
839
|
-
|
|
845
|
+
if (event.type === "agent_settled") {
|
|
846
|
+
runningAgent.runAborted = event.aborted;
|
|
847
|
+
logSteering(runningAgent.id, "child-agent-settled", { streaming: session.isStreaming, aborted: event.aborted });
|
|
848
|
+
}
|
|
840
849
|
if (event.type === "turn_start")
|
|
841
850
|
logSteering(runningAgent.id, "turn-started", { streaming: session.isStreaming });
|
|
842
851
|
if (event.type === "turn_end")
|
package/shared.ts
CHANGED
|
@@ -144,6 +144,8 @@ export type RunningAgent = {
|
|
|
144
144
|
aborted?: boolean;
|
|
145
145
|
/** Set when the user interrupts only the active turn, leaving the child session alive. */
|
|
146
146
|
interruptRequested?: boolean;
|
|
147
|
+
/** Cancellation outcome of the current prompt, reported at session-level settlement. */
|
|
148
|
+
runAborted?: boolean;
|
|
147
149
|
};
|
|
148
150
|
|
|
149
151
|
export type CompletedAgent = {
|