Skip to content
Merged
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
35 changes: 34 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ function getSessionIDFromEvent(event: unknown): string | null {
return getStringField(properties, "sessionID")
}

function getPermissionIDFromEvent(event: unknown): string | null {
const properties = getNestedRecord(event, "properties")
const id = getStringField(properties, "id")
if (id) {
return id
}
const request = getNestedRecord(event, "properties", "request")
return getStringField(request, "id")
}

interface SessionLifecycleInfo {
id: string | null
title: string | null
Expand Down Expand Up @@ -537,7 +547,30 @@ export const NotifierPlugin: Plugin = async ({ client, directory }) => {

if ((event as any).type === "permission.asked") {
const sessionID = getSessionIDFromEvent(event)
if (!shouldSuppressPermissionAlert(sessionID)) {
const permissionID = getPermissionIDFromEvent(event)
let stillPending = true
if (permissionID) {
// Auto-approved requests are resolved immediately, so wait briefly
// and only notify when the request is still pending.
await new Promise((resolve) => setTimeout(resolve, 300))
try {
const inner = (client as any)?._client || (client as any)?.session?._client
if (inner && typeof inner.get === "function") {
const listResponse = await inner.get({ url: "/permission" })
const body = listResponse?.data ?? listResponse
const pendingList = Array.isArray(body) ? body : Array.isArray(body?.data) ? body.data : null
if (pendingList) {
stillPending = pendingList.some((p: { id?: string }) => p?.id === permissionID)
}
}
} catch {
stillPending = true
}
}
// Claim the shared dedupe window only when a notification is actually
// about to fire: a silently skipped auto-approved request must not mute a
// real one arriving within the same second.
if (stillPending && !shouldSuppressPermissionAlert(sessionID)) {
await handleEventWithElapsedTime(client, config, "permission", projectName, event)
}
}
Expand Down