MCPcopy
hub / github.com/stitionai/devika / initializeSockets

Function initializeSockets

ui/src/lib/sockets.js:8–73  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6let prevMonologue = null;
7
8export function initializeSockets() {
9
10 socket.connect();
11
12 let state = get(agentState);
13 prevMonologue = state?.internal_monologue;
14
15 socket.emit("socket_connect", { data: "frontend connected!" });
16 socket.on("socket_response", function (msg) {
17 console.log(msg);
18 });
19
20 socket.on("server-message", function (data) {
21 console.log(data)
22 messages.update((msgs) => [...msgs, data["messages"]]);
23 });
24
25 socket.on("agent-state", function (state) {
26 const lastState = state[state.length - 1];
27 agentState.set(lastState);
28 if (lastState.completed) {
29 isSending.set(false);
30 }
31 });
32
33 socket.on("tokens", function (tokens) {
34 tokenUsage.set(tokens["token_usage"]);
35 });
36
37 socket.on("inference", function (error) {
38 if (error["type"] == "error") {
39 toast.error(error["message"]);
40 isSending.set(false);
41 } else if (error["type"] == "warning") {
42 toast.warning(error["message"]);
43 }
44 });
45
46 socket.on("info", function (info) {
47 if (info["type"] == "error") {
48 toast.error(info["message"]);
49 isSending.set(false);
50 } else if (info["type"] == "warning") {
51 toast.warning(info["message"]);
52 } else if (info["type"] == "info") {
53 toast.info(info["message"]);
54 }
55 });
56
57
58 agentState.subscribe((state) => {
59 function handleMonologueChange(newValue) {
60 if (newValue) {
61 toast(newValue);
62 }
63 }
64 if (
65 state &&

Callers

nothing calls this directly

Calls 4

handleMonologueChangeFunction · 0.85
errorMethod · 0.80
warningMethod · 0.80
infoMethod · 0.80

Tested by

no test coverage detected