permission-request-store.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. export interface PermissionRequestRecord {
  2. requestId: string;
  3. sessionId: string;
  4. agentName?: string;
  5. msgId?: string;
  6. toolName: string;
  7. ruleContents: string[];
  8. /** Human-readable tool input (e.g. actual command or file path) for user display. */
  9. toolInput?: string;
  10. /** Short description of the tool action provided by the AI model (e.g. "Lists files in current directory"). */
  11. toolDescription?: string;
  12. /** Reason shown to the user for why confirmation is required. */
  13. reason?: string;
  14. /**
  15. * Rewritten tool input produced by the permission layer (e.g. `rm` →
  16. * `mavis-trash`). Persisted so that the ASK card flow does not lose
  17. * the rewrite — the framework adapter checks `rewrittenInput` BEFORE
  18. * `behavior` and instructs the agent to re-run with the rewritten
  19. * command regardless of allow/ask/deny.
  20. */
  21. rewrittenInput?: Record<string, unknown>;
  22. createdAt?: number;
  23. }
  24. /**
  25. * Permission-request store contract for pending permission requests keyed by requestId.
  26. * All methods are async to allow non-blocking implementations.
  27. * Concrete implementations live in `store/impl/`.
  28. */
  29. export interface PermissionRequestStore {
  30. /** Insert or update a permission request. Unique key: `requestId`. */
  31. upsert(record: PermissionRequestRecord): Promise<void>;
  32. get(requestId: string): Promise<PermissionRequestRecord | null>;
  33. delete(requestId: string): Promise<boolean>;
  34. getAll(): Promise<PermissionRequestRecord[]>;
  35. deleteBySession(sessionId: string): Promise<number>;
  36. findPendingByFingerprint(
  37. sessionId: string,
  38. toolName: string,
  39. ruleContents: string[],
  40. agentName?: string,
  41. ): Promise<PermissionRequestRecord | null>;
  42. }