Move per-session permission auto-accept policy ownership from the UI to the OpenChamber server so enabled sessions continue running when clients disconnect or the server restarts. - persist explicit per-session policies in OpenChamber settings - inherit the nearest explicit policy across subagent session hierarchies - allow child sessions to opt out of an inherited parent policy - immediately accept matching global and directory-scoped pending requests - process future requests without requiring a connected UI client - reconcile pending permissions after startup and event-stream reconnects - deduplicate concurrent requests and retry transient reply failures - synchronize policy updates across connected clients - migrate existing browser-persisted policies to server storage - suppress auto-accepted permission cards before they enter UI state - show deduplicated permission toasts for inactive sessions - preserve foreground-only permission handling in VS Code - integrate directory-aware notification routing from main - add coverage for persistence, inheritance, retries, reconciliation, pending requests, client hydration, and inactive-session toasts
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import type { PermissionRequest } from '@/types/permission';
|
|
|
|
type PermissionToastOptions = {
|
|
permission: PermissionRequest;
|
|
directory: string;
|
|
isViewed: boolean;
|
|
pendingIds: Set<string>;
|
|
show: (title: string, options: {
|
|
id: string;
|
|
description: string;
|
|
action: { label: string; onClick: () => void };
|
|
}) => void;
|
|
openSession: (sessionId: string, directory: string) => void;
|
|
};
|
|
|
|
export const getPermissionToastKey = (sessionId?: string, requestId?: string) => {
|
|
if (!sessionId || !requestId) return null;
|
|
return `${sessionId}:${requestId}`;
|
|
};
|
|
|
|
export const showPermissionNeededToast = ({
|
|
permission,
|
|
directory,
|
|
isViewed,
|
|
pendingIds,
|
|
show,
|
|
openSession,
|
|
}: PermissionToastOptions): boolean => {
|
|
const key = getPermissionToastKey(permission.sessionID, permission.id);
|
|
if (isViewed || !key || pendingIds.has(key)) return false;
|
|
|
|
pendingIds.add(key);
|
|
const description = typeof permission.permission === 'string' && permission.permission.trim().length > 0
|
|
? permission.permission
|
|
: 'Agent needs your approval';
|
|
show('Permission needed', {
|
|
id: `permission-${key}`,
|
|
description,
|
|
action: {
|
|
label: 'Open session',
|
|
onClick: () => openSession(permission.sessionID, directory),
|
|
},
|
|
});
|
|
return true;
|
|
};
|