MCPcopy
hub / github.com/docker/genai-stack / send

Function send

front-end/src/lib/chat.store.js:41–71  ·  view source on GitHub ↗
(question, ragMode = false)

Source from the content-addressed store, hash-verified

39 }
40
41 async function send(question, ragMode = false) {
42 if (!question.trim().length) {
43 return;
44 }
45 update((state) => ({ ...state, state: chatStates.RECEIVING }));
46 addMessage("me", question, ragMode);
47 const messageId = addMessage("bot", "", ragMode);
48 try {
49 const evt = new EventSource(`${API_ENDPOINT}?text=${encodeURI(question)}&rag=${ragMode}`);
50 question = "";
51 evt.onmessage = (e) => {
52 if (e.data) {
53 const data = JSON.parse(e.data);
54 if (data.init) {
55 updateMessage(messageId, "", data.model);
56 return;
57 }
58 updateMessage(messageId, data.token);
59 }
60 };
61 evt.onerror = (e) => {
62 // Stream will end with an error
63 // and we want to close the connection on end (otherwise it will keep reconnecting)
64 evt.close();
65 update((state) => ({ ...state, state: chatStates.IDLE }));
66 };
67 } catch (e) {
68 updateMessage(messageId, "Error: " + e.message);
69 update((state) => ({ ...state, state: chatStates.IDLE }));
70 }
71 }
72
73 return {
74 subscribe,

Callers

nothing calls this directly

Calls 2

addMessageFunction · 0.85
updateMessageFunction · 0.85

Tested by

no test coverage detected