File size: 1,233 Bytes
4e23b01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
 * `sessionApprovalService` — session-scope approval broker. Mirrors
 * `agent-core-v2/agent/interaction/approval.ts`. `ApprovalRequest.display` is
 * the protocol `ToolInputDisplay` union (huge); it crosses the wire
 * uninspected, so it is `z.unknown()` here.
 */

import { z } from 'zod';

import { noResult } from '../helpers.js';
import type { ServiceContract } from '../types.js';

export const approvalRequestSchema = z.object({
  id: z.string().optional(),
  sessionId: z.string().optional(),
  agentId: z.string().optional(),
  turnId: z.number().optional(),
  toolCallId: z.string().optional(),
  toolName: z.string(),
  action: z.string(),
  /** Protocol `ToolInputDisplay` — mirrored as `unknown` (see file header). */
  display: z.unknown(),
});

export const approvalResponseSchema = z.object({
  decision: z.enum(['approved', 'rejected', 'cancelled']),
  scope: z.literal('session').optional(),
  feedback: z.string().optional(),
  selectedLabel: z.string().optional(),
});

export const sessionApprovalContract = {
  listPending: { input: z.tuple([]), output: z.array(approvalRequestSchema) },
  decide: { input: z.tuple([z.string(), approvalResponseSchema]), output: noResult },
} satisfies ServiceContract;