Skip to content

Commit ef98093

Browse files
authored
fix: approval in edit mode not working if log printed (#67)
1 parent f674bec commit ef98093

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

packages/blink/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blink",
3-
"version": "1.1.26",
3+
"version": "1.1.27",
44
"description": "Blink is a tool for building and deploying AI agents.",
55
"type": "module",
66
"bin": {

packages/blink/src/react/use-dev-mode.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -523,28 +523,30 @@ export default function useDevMode(options: UseDevModeOptions): UseDevMode {
523523
setAutoApprove(true);
524524
}
525525

526-
const messages = chat.messages;
527-
if (messages.length === 0) {
528-
return;
529-
}
530-
const lastMsg = messages[messages.length - 1];
531-
if (!lastMsg) {
532-
return;
533-
}
534-
if (lastMsg.role !== "assistant") {
535-
return;
536-
}
537-
if (!Array.isArray(lastMsg.parts)) {
538-
return;
539-
}
540-
if (approvalHandledRef.current === lastMsg.id) {
526+
const lastApprovalMessage = chat.messages.reverse().find((msg) => {
527+
if (msg.role !== "assistant") {
528+
return false;
529+
}
530+
if (!Array.isArray(msg.parts)) {
531+
return false;
532+
}
533+
return msg.parts.some(
534+
(part) =>
535+
"output" in part &&
536+
isToolApprovalOutput(part.output) &&
537+
part.output.outcome === "pending"
538+
);
539+
});
540+
541+
if (!lastApprovalMessage) {
541542
return;
542543
}
544+
543545
// CRITICAL: all code before this point must be synchronous.
544546
// Otherwise, the approval may be handled multiple times.
545-
approvalHandledRef.current = lastMsg.id;
547+
approvalHandledRef.current = lastApprovalMessage.id;
546548
// Update all pending approval outputs
547-
const updatedParts = lastMsg.parts.map((part: any) => {
549+
const updatedParts = lastApprovalMessage.parts.map((part: any) => {
548550
if (
549551
part.output &&
550552
isToolApprovalOutput(part.output) &&
@@ -562,7 +564,7 @@ export default function useDevMode(options: UseDevModeOptions): UseDevMode {
562564
});
563565

564566
await chat.upsertMessage({
565-
...lastMsg,
567+
...lastApprovalMessage,
566568
parts: updatedParts,
567569
});
568570

0 commit comments

Comments
 (0)