File size: 1,645 Bytes
68d7816
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* oxlint-disable typescript-eslint/no-unsafe-declaration-merging, eslint-plugin-import/namespace -- Event2 class+payload-interface declaration merging is the sanctioned event-declaration idiom. */
import { z } from 'zod';

import { AgentEvent2, registerEvent2Class } from '#/app/event/event2';
import type { InteractionKind } from '#/human/interaction/interaction';

const interactionRequestSchema = z.object({
  agentId: z.string(),
  id: z.string(),
  kind: z.enum(['approval', 'question', 'user_tool']),
  toolCallId: z.string().optional(),
  request: z.unknown(),
});

export class InteractionRequestEvent extends AgentEvent2<
  z.infer<typeof interactionRequestSchema>
> {
  static override readonly type = 'interaction.request';
  static override readonly durable = true;
  static override readonly schema = interactionRequestSchema;
}
export interface InteractionRequestEvent {
  readonly agentId: string;
  readonly id: string;
  readonly kind: InteractionKind;
  readonly toolCallId?: string;
  readonly request: unknown;
}

const interactionResolvedSchema = z.object({
  agentId: z.string(),
  id: z.string(),
  response: z.unknown(),
});

export class InteractionResolvedEvent extends AgentEvent2<
  z.infer<typeof interactionResolvedSchema>
> {
  static override readonly type = 'interaction.resolved';
  static override readonly durable = true;
  static override readonly schema = interactionResolvedSchema;
}
export interface InteractionResolvedEvent {
  readonly agentId: string;
  readonly id: string;
  readonly response: unknown;
}

registerEvent2Class(InteractionRequestEvent);
registerEvent2Class(InteractionResolvedEvent);