fix: tsc errors — use correct ExtensionAPI event names (tool_execution_start/end, session_start)
This commit is contained in:
parent
fcfe729d23
commit
8ff635e6f5
|
|
@ -93,7 +93,9 @@ export default function remoteControl(pi: ExtensionAPI) {
|
||||||
updateStatus(ctx);
|
updateStatus(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
pi.on("session_switch", async (_event, ctx) => {
|
// session_switch is not in the ExtensionAPI — use session_start instead
|
||||||
|
// to sync state when a session becomes active.
|
||||||
|
pi.on("session_start", async (_event, ctx) => {
|
||||||
scheduleSync(ctx);
|
scheduleSync(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,72 +28,41 @@ export type StateCallback = (event: StateEvent) => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscribe to pi agent lifecycle events.
|
* Subscribe to pi agent lifecycle events.
|
||||||
* Returns an unsubscribe function.
|
*
|
||||||
|
* Note: `pi.on()` returns void and has no unsubscribe mechanism — event
|
||||||
|
* handlers are scoped to the extension lifetime, not to individual calls.
|
||||||
|
* The returned function is a no-op kept for API compatibility.
|
||||||
*/
|
*/
|
||||||
export function subscribeAgentEvents(
|
export function subscribeAgentEvents(
|
||||||
pi: ExtensionAPI,
|
pi: ExtensionAPI,
|
||||||
onState: StateCallback,
|
onState: StateCallback,
|
||||||
): () => void {
|
): () => void {
|
||||||
const unsubs: Array<() => void> = [];
|
|
||||||
|
|
||||||
// agent_start → thinking
|
// agent_start → thinking
|
||||||
try {
|
pi.on("agent_start", () => {
|
||||||
const off = pi.on("agent_start", () => {
|
|
||||||
onState({ value: "thinking", ts: Date.now() });
|
onState({ value: "thinking", ts: Date.now() });
|
||||||
});
|
});
|
||||||
if (off) unsubs.push(off);
|
|
||||||
} catch {
|
|
||||||
// event may not exist in this pi version
|
|
||||||
}
|
|
||||||
|
|
||||||
// agent_end → idle
|
// agent_end → idle
|
||||||
try {
|
pi.on("agent_end", () => {
|
||||||
const off = pi.on("agent_end", () => {
|
|
||||||
onState({ value: "idle", ts: Date.now() });
|
onState({ value: "idle", ts: Date.now() });
|
||||||
});
|
});
|
||||||
if (off) unsubs.push(off);
|
|
||||||
} catch {
|
|
||||||
// event may not exist
|
|
||||||
}
|
|
||||||
|
|
||||||
// tool_start → tool
|
// tool_execution_start → tool (carries toolName directly on the event)
|
||||||
try {
|
pi.on("tool_execution_start", (event) => {
|
||||||
const off = pi.on("tool_start", (data: unknown) => {
|
onState({ value: "tool", tool: event.toolName, ts: Date.now() });
|
||||||
const toolName =
|
|
||||||
data &&
|
|
||||||
typeof data === "object" &&
|
|
||||||
"name" in data &&
|
|
||||||
typeof (data as { name: unknown }).name === "string"
|
|
||||||
? (data as { name: string }).name
|
|
||||||
: undefined;
|
|
||||||
onState({ value: "tool", tool: toolName, ts: Date.now() });
|
|
||||||
});
|
});
|
||||||
if (off) unsubs.push(off);
|
|
||||||
} catch {
|
|
||||||
// event may not exist
|
|
||||||
}
|
|
||||||
|
|
||||||
// tool_end → thinking (agent is still running after tool)
|
// tool_execution_end → thinking (agent loop continues after tool completes)
|
||||||
try {
|
pi.on("tool_execution_end", () => {
|
||||||
const off = pi.on("tool_end", () => {
|
|
||||||
onState({ value: "thinking", ts: Date.now() });
|
onState({ value: "thinking", ts: Date.now() });
|
||||||
});
|
});
|
||||||
if (off) unsubs.push(off);
|
|
||||||
} catch {
|
|
||||||
// event may not exist
|
|
||||||
}
|
|
||||||
|
|
||||||
// awaiting_input → awaiting-input
|
// input → awaiting-input (fired when pi pauses to wait for user input)
|
||||||
try {
|
pi.on("input", () => {
|
||||||
const off = pi.on("awaiting_input", () => {
|
|
||||||
onState({ value: "awaiting-input", ts: Date.now() });
|
onState({ value: "awaiting-input", ts: Date.now() });
|
||||||
});
|
});
|
||||||
if (off) unsubs.push(off);
|
|
||||||
} catch {
|
|
||||||
// event may not exist
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
for (const off of unsubs) off();
|
// No-op: pi event subscriptions cannot be cancelled.
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue