Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/blink/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blink",
"version": "1.1.26",
"version": "1.1.27",
"description": "Blink is a tool for building and deploying AI agents.",
"type": "module",
"bin": {
Expand Down
38 changes: 20 additions & 18 deletions packages/blink/src/react/use-dev-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,28 +523,30 @@ export default function useDevMode(options: UseDevModeOptions): UseDevMode {
setAutoApprove(true);
}

const messages = chat.messages;
if (messages.length === 0) {
return;
}
const lastMsg = messages[messages.length - 1];
if (!lastMsg) {
return;
}
if (lastMsg.role !== "assistant") {
return;
}
if (!Array.isArray(lastMsg.parts)) {
return;
}
if (approvalHandledRef.current === lastMsg.id) {
const lastApprovalMessage = chat.messages.reverse().find((msg) => {
if (msg.role !== "assistant") {
return false;
}
if (!Array.isArray(msg.parts)) {
return false;
}
return msg.parts.some(
(part) =>
"output" in part &&
isToolApprovalOutput(part.output) &&
part.output.outcome === "pending"
);
});

if (!lastApprovalMessage) {
return;
}

// CRITICAL: all code before this point must be synchronous.
// Otherwise, the approval may be handled multiple times.
approvalHandledRef.current = lastMsg.id;
approvalHandledRef.current = lastApprovalMessage.id;
// Update all pending approval outputs
const updatedParts = lastMsg.parts.map((part: any) => {
const updatedParts = lastApprovalMessage.parts.map((part: any) => {
if (
part.output &&
isToolApprovalOutput(part.output) &&
Expand All @@ -562,7 +564,7 @@ export default function useDevMode(options: UseDevModeOptions): UseDevMode {
});

await chat.upsertMessage({
...lastMsg,
...lastApprovalMessage,
parts: updatedParts,
});

Expand Down