Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

1.7 KB
Raw Blame
import { PermissionCard } from '@app/features/agent-interactions/components/PermissionCard';
import { fireAndForget } from '@core/util/fireAndForget';
import type { PendingPermission } from '@service-agent-fold/generated/types';
import { useOptionalAgentSession } from '../context/AgentSessionContext';
import { toolCallDetail, toolLabel } from './parts/shared';

/** Live approval above the composer, with context from the requested tool. */
export function PermissionRequest(props: { request: PendingPermission }) {
  const session = useOptionalAgentSession();
  const identity = () => ({ ...props.request, kind: 'permission' as const });
  const tool = () =>
    session
      ?.messages()
      .find(
        (message) =>
          message.author.kind === 'agent' && message.turn === props.request.turn
      )
      ?.parts.find(
        (part) => part.kind === 'tool_use' && part.id === props.request.toolCall
      );
  const detail = () => {
    const part = tool();
    return part?.kind === 'tool_use' ? toolCallDetail(part) : undefined;
  };
  const action = () => {
    const part = tool();
    if (part?.kind !== 'tool_use') return undefined;
    return part.detail.kind === 'terminal'
      ? 'Run command'
      : toolLabel(part.name);
  };
  return (
    <PermissionCard
      action={action()}
      detail={detail()}
      options={props.request.options}
      canAnswer={session?.interactions.canAnswer() === true}
      disabled={session?.interactions.answering(identity())}
      onSelect={(optionId) =>
        fireAndForget(
          session?.interactions.respond({
            ...identity(),
            answer: { kind: 'selected', optionId },
          }),
          'agent-interactions'
        )
      }
    />
  );
}