MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / askWiki

Function askWiki

deployments/desktop/static/desktop.js:4703–4790  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4701 }
4702
4703 async function askWiki() {
4704 const input = $("chatInput");
4705 const button = $("wikiAskBtn");
4706 const question = input.value.trim();
4707 if (!question) return;
4708 const payload = {
4709 user_id: currentUser(),
4710 question,
4711 scope: document.querySelector("input[name='chatScope']:checked")?.value || "all",
4712 limit: 8,
4713 mentions: activeMentionsForQuestion(question),
4714 session_id: state.chatSessionId || "",
4715 response_language: responseLanguage()
4716 };
4717 $("chatThread").insertAdjacentHTML("beforeend", `
4718 <div class="message user">
4719 <div class="avatar">${escapeHtml(ui().chat.me)}</div>
4720 <div class="bubble"><p>${escapeHtml(question)}</p></div>
4721 </div>
4722 `);
4723 input.value = "";
4724 clearChatMentions();
4725 window.clearTimeout(state.mentionSearchTimer);
4726 state.mentionSearchToken += 1;
4727 $("mentionSuggestions").hidden = true;
4728
4729 const messageId = `assistant-${Date.now()}`;
4730 $("chatThread").insertAdjacentHTML("beforeend", `
4731 <div class="message assistant" id="${messageId}">
4732 <div class="avatar">AI</div>
4733 <div class="bubble">
4734 <div class="answer-meta"><span>${escapeHtml(ui().chat.preparing)}</span></div>
4735 <div class="answer-text loading"><p>${escapeHtml(ui().chat.generating)}</p></div>
4736 </div>
4737 </div>
4738 `);
4739 const message = $(messageId);
4740 const metaTarget = message.querySelector(".answer-meta");
4741 const answerTarget = message.querySelector(".answer-text");
4742 const previousText = button.textContent;
4743 button.disabled = true;
4744 button.textContent = ui().papers.generating;
4745
4746 try {
4747 let data;
4748 if (DEMO_MODE) {
4749 data = await api("/api/wiki/ask", { method: "POST", body: JSON.stringify(payload) });
4750 const citations = normalizeCitations(data);
4751 metaTarget.outerHTML = renderAnswerMeta(data, citations);
4752 await streamAnswerText(answerTarget, data.text || "", citations);
4753 renderChatSources(citations);
4754 } else {
4755 try {
4756 data = await streamWikiAsk(payload, answerTarget, message);
4757 } catch (streamError) {
4758 console.warn("Streaming Wiki ask failed, falling back to JSON.", streamError);
4759 showFeedbackToast("warning", ui().chat.streamInterruptedTitle, ui().chat.streamInterruptedDetail);
4760 data = await api("/api/wiki/ask", { method: "POST", body: JSON.stringify(payload) });

Callers

nothing calls this directly

Calls 15

currentUserFunction · 0.85
responseLanguageFunction · 0.85
uiFunction · 0.85
clearChatMentionsFunction · 0.85
normalizeCitationsFunction · 0.85
renderAnswerMetaFunction · 0.85
streamAnswerTextFunction · 0.85
renderChatSourcesFunction · 0.85
streamWikiAskFunction · 0.85
showFeedbackToastFunction · 0.85
loadChatSessionsFunction · 0.85

Tested by

no test coverage detected