handleElicitationRequest dispatches an elicitation.requested event to the registered handler and sends the result back via the RPC layer. Auto-cancels on error.
(elicitCtx ElicitationContext, requestID string)
| 977 | // handleElicitationRequest dispatches an elicitation.requested event to the registered handler |
| 978 | // and sends the result back via the RPC layer. Auto-cancels on error. |
| 979 | func (s *Session) handleElicitationRequest(elicitCtx ElicitationContext, requestID string) { |
| 980 | handler := s.getElicitationHandler() |
| 981 | if handler == nil { |
| 982 | return |
| 983 | } |
| 984 | |
| 985 | ctx := context.Background() |
| 986 | |
| 987 | result, err := handler(elicitCtx) |
| 988 | if err != nil { |
| 989 | // Handler failed — attempt to cancel so the request doesn't hang. |
| 990 | s.RPC.UI.HandlePendingElicitation(ctx, &rpc.UIHandlePendingElicitationRequest{ |
| 991 | RequestID: requestID, |
| 992 | Result: rpc.UIElicitationResponse{ |
| 993 | Action: rpc.UIElicitationResponseActionCancel, |
| 994 | }, |
| 995 | }) |
| 996 | return |
| 997 | } |
| 998 | |
| 999 | var rpcContent map[string]rpc.UIElicitationFieldValue |
| 1000 | if result.Content != nil { |
| 1001 | rpcContent = make(map[string]rpc.UIElicitationFieldValue, len(result.Content)) |
| 1002 | for k, v := range result.Content { |
| 1003 | contentValue, err := toRPCContent(v) |
| 1004 | if err != nil { |
| 1005 | s.RPC.UI.HandlePendingElicitation(ctx, &rpc.UIHandlePendingElicitationRequest{ |
| 1006 | RequestID: requestID, |
| 1007 | Result: rpc.UIElicitationResponse{ |
| 1008 | Action: rpc.UIElicitationResponseActionCancel, |
| 1009 | }, |
| 1010 | }) |
| 1011 | return |
| 1012 | } |
| 1013 | rpcContent[k] = contentValue |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | s.RPC.UI.HandlePendingElicitation(ctx, &rpc.UIHandlePendingElicitationRequest{ |
| 1018 | RequestID: requestID, |
| 1019 | Result: rpc.UIElicitationResponse{ |
| 1020 | Action: result.Action, |
| 1021 | Content: rpcContent, |
| 1022 | }, |
| 1023 | }) |
| 1024 | } |
| 1025 | |
| 1026 | // toRPCContent converts an SDK content value to an RPC elicitation response value. |
| 1027 | func toRPCContent(v any) (rpc.UIElicitationFieldValue, error) { |
no test coverage detected