| 1 | export type InteractionKind = "ask" | "approval" | "plan" | "recovery" | "mcp"; |
| 2 | |
| 3 | export type InteractionTarget = Readonly<{ |
| 4 | tabId: string; |
| 5 | sessionKey: string; |
| 6 | hostId?: string; |
| 7 | sessionId?: string; |
| 8 | sessionGeneration?: number; |
| 9 | promptId: string; |
| 10 | turnId?: string; |
| 11 | runtimeEpoch?: string; |
| 12 | kind: InteractionKind; |
| 13 | instanceKey: string; |
| 14 | requestGeneration?: number; |
| 15 | permissionRevision?: number; |
| 16 | }>; |
| 17 | |
| 18 | export function interactionInstanceKey(target: Omit<InteractionTarget, "instanceKey">): string { |
| 19 | return JSON.stringify([ |
| 20 | target.sessionKey, |
| 21 | target.hostId ?? "", |
| 22 | target.sessionId ?? "", |
| 23 | target.sessionGeneration ?? 0, |
| 24 | target.runtimeEpoch ?? "", |
| 25 | target.turnId ?? "", |
| 26 | target.kind, |
| 27 | target.promptId, |
| 28 | target.requestGeneration ?? 0, |
| 29 | target.permissionRevision ?? 0, |
| 30 | ]); |
| 31 | } |
| 32 | |
| 33 | export function sameInteractionIdentity( |
| 34 | prompt: { id: string; turnId?: string; runtimeEpoch?: string } | undefined, |
| 35 | target: Pick<InteractionTarget, "promptId" | "turnId" | "runtimeEpoch">, |
| 36 | ): boolean { |
| 37 | return Boolean(prompt) && prompt?.id === target.promptId && |
| 38 | (target.turnId === undefined || prompt.turnId === target.turnId) && |
| 39 | (target.runtimeEpoch === undefined || prompt.runtimeEpoch === target.runtimeEpoch); |
| 40 | } |
| 41 |