MCPcopy
hub / github.com/wavetermdev/waveterm / WaveAIPostMessageHandler

Function WaveAIPostMessageHandler

pkg/aiusechat/usechat.go:635–732  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

633}
634
635func WaveAIPostMessageHandler(w http.ResponseWriter, r *http.Request) {
636 // Only allow POST method
637 if r.Method != http.MethodPost {
638 http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
639 return
640 }
641
642 // Parse request body
643 var req PostMessageRequest
644 if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
645 http.Error(w, fmt.Sprintf("Invalid request body: %v", err), http.StatusBadRequest)
646 return
647 }
648
649 // Validate chatid is present and is a UUID
650 if req.ChatID == "" {
651 http.Error(w, "chatid is required in request body", http.StatusBadRequest)
652 return
653 }
654 if _, err := uuid.Parse(req.ChatID); err != nil {
655 http.Error(w, "chatid must be a valid UUID", http.StatusBadRequest)
656 return
657 }
658
659 // Get RTInfo from TabId or BuilderId
660 var rtInfo *waveobj.ObjRTInfo
661 if req.TabId != "" {
662 oref := waveobj.MakeORef(waveobj.OType_Tab, req.TabId)
663 rtInfo = wstore.GetRTInfo(oref)
664 } else if req.BuilderId != "" {
665 oref := waveobj.MakeORef(waveobj.OType_Builder, req.BuilderId)
666 rtInfo = wstore.GetRTInfo(oref)
667 }
668 if rtInfo == nil {
669 rtInfo = &waveobj.ObjRTInfo{}
670 }
671
672 // Get WaveAI settings
673 premium := shouldUsePremium()
674 builderMode := req.BuilderId != ""
675 if req.AIMode == "" {
676 http.Error(w, "aimode is required in request body", http.StatusBadRequest)
677 return
678 }
679 aiOpts, err := getWaveAISettings(premium, builderMode, *rtInfo, req.AIMode)
680 if err != nil {
681 http.Error(w, fmt.Sprintf("WaveAI configuration error: %v", err), http.StatusInternalServerError)
682 return
683 }
684
685 // Call the core WaveAIPostMessage function
686 chatOpts := uctypes.WaveChatOpts{
687 ChatId: req.ChatID,
688 ClientId: wstore.GetClientId(),
689 Config: *aiOpts,
690 WidgetAccess: req.WidgetAccess,
691 AllowNativeWebSearch: true,
692 BuilderId: req.BuilderId,

Callers

nothing calls this directly

Calls 15

MakeORefFunction · 0.92
GetRTInfoFunction · 0.92
GetClientIdFunction · 0.92
MakeSSEHandlerChFunction · 0.92
shouldUsePremiumFunction · 0.85
getWaveAISettingsFunction · 0.85
getSystemPromptFunction · 0.85
GenerateTabStateAndToolsFunction · 0.85
generateBuilderAppDataFunction · 0.85

Tested by

no test coverage detected