forked from stitionai/devika
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
153 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
</script> | ||
|
||
<Sonner | ||
richColors | ||
theme={$mode} | ||
position="bottom-left" | ||
class="toaster group" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { socket } from "./api"; | ||
import { messages, agentState, isSending, tokenUsage } from "./store"; | ||
import { toast } from "svelte-sonner"; | ||
import { get } from "svelte/store"; | ||
|
||
let prevMonologue = null; | ||
|
||
export function initializeSockets() { | ||
socket.connect(); | ||
|
||
let state = get(agentState); | ||
prevMonologue = state?.internal_monologue; | ||
|
||
socket.emit("socket_connect", { data: "frontend connected!" }); | ||
socket.on("socket_response", function (msg) { | ||
console.log(msg); | ||
}); | ||
|
||
socket.on("server-message", function (data) { | ||
console.log("server-message: ", data); | ||
messages.update((msgs) => [...msgs, data["messages"]]); | ||
}); | ||
|
||
socket.on("agent-state", function (state) { | ||
const lastState = state[state.length - 1]; | ||
agentState.set(lastState); | ||
if (lastState.completed) { | ||
isSending.set(false); | ||
} | ||
}); | ||
|
||
socket.on("tokens", function (tokens) { | ||
tokenUsage.set(tokens["token_usage"]); | ||
}); | ||
|
||
socket.on("inference", function (error) { | ||
if (error["type"] == "error") { | ||
toast.error(error["message"]); | ||
} else if (error["type"] == "warning") { | ||
toast.warning(error["message"]); | ||
} | ||
}); | ||
|
||
socket.on("info", function (info) { | ||
if (info["type"] == "error") { | ||
toast.error(info["message"]); | ||
} else if (info["type"] == "warning") { | ||
toast.warning(info["message"]); | ||
} else if (info["type"] == "info") { | ||
toast.info(info["message"]); | ||
} | ||
}); | ||
|
||
|
||
agentState.subscribe((state) => { | ||
function handleMonologueChange(newValue) { | ||
if (newValue) { | ||
toast(newValue); | ||
} | ||
} | ||
if ( | ||
state && | ||
state.internal_monologue && | ||
state.internal_monologue !== prevMonologue | ||
) { | ||
handleMonologueChange(state.internal_monologue); | ||
prevMonologue = state.internal_monologue; | ||
} | ||
}); | ||
} | ||
|
||
export function destroySockets() { | ||
if (socket.connected) { | ||
socket.off("socket_response"); | ||
socket.off("server-message"); | ||
socket.off("agent-state"); | ||
socket.off("tokens"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.