Files
buzz/desktop/src/features/agents/lib/canViewAgentActivity.ts
Taylor Ho 2865d3f99f feat(agents): gate activity by relay ownership
- Add a relay ownership endpoint backed by agent_owner_pubkey and is_agent_owner so desktop activity visibility uses the same source of truth as observer telemetry authorization.
- Add a Tauri ownership command, frontend API wrapper, and useCanViewAgentActivity hook with local managed-agent optimism only while relay ownership is loading.
- Replace profile popover, profile panel, and members sidebar activity gates so owned agents can open activity across different builds and worktrees without relying on local managed-agent lists.
- Refactor channel agent session candidate resolution so owned agents can keep an activity panel open when channel metadata is stale, while preserving local-only lifecycle controls.
- Add focused desktop unit coverage for the ownership predicate and stale-metadata session resolution path, plus E2E bridge support for ownership mocks.
2026-06-14 20:30:39 -07:00

44 lines
1.2 KiB
TypeScript

import type { AgentOwnershipStatus } from "@/shared/api/tauriAgentOwnership";
export type CanViewAgentActivityInput = {
relayOwnership: AgentOwnershipStatus | undefined;
isManagedAgent: boolean | undefined;
isOwnershipLoading: boolean;
isManagedLoading: boolean;
};
export type CanViewAgentActivityResult = {
canView: boolean;
isLoading: boolean;
};
/**
* Unified predicate for Show Activity / Activity log ingresses.
*
* Final permission comes from relay `is_agent_owner`. While the relay lookup
* is in flight, locally managed agents may show activity optimistically.
*/
export function resolveCanViewAgentActivity({
relayOwnership,
isManagedAgent,
isOwnershipLoading,
isManagedLoading,
}: CanViewAgentActivityInput): CanViewAgentActivityResult {
if (relayOwnership?.isOwner === true) {
return { canView: true, isLoading: false };
}
if (relayOwnership?.isOwner === false) {
return { canView: false, isLoading: false };
}
const isLoading =
isOwnershipLoading || (isManagedAgent === undefined && isManagedLoading);
if (isManagedAgent === true && isOwnershipLoading) {
return { canView: true, isLoading: true };
}
return { canView: false, isLoading };
}