Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

add xspace-agent/xspace-agent/agent-voice-chat/lib/turn-manager.js

overstepping6fbd78842e30
diff --git a/xspace-agent/xspace-agent/agent-voice-chat/lib/turn-manager.js b/xspace-agent/xspace-agent/agent-voice-chat/lib/turn-manager.js
new file mode 100644
index 000000000..efe704a10
--- /dev/null
+++ b/xspace-agent/xspace-agent/agent-voice-chat/lib/turn-manager.js
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: Apache-2.0
+// Copyright 2026 nirholas (https://github.com/nirholas/xspace-agent)
+
+class TurnManager {
+ constructor({ onBroadcast, onTurnGranted } = {}) {
+ this.currentTurn = null
+ this.turnQueue = []
+ this.isProcessing = false
+ this.onBroadcast = onBroadcast || (() => {})
+ this.onTurnGranted = onTurnGranted || (() => {})
+ }
+
+ requestTurn(agentId) {
+ if (this.currentTurn === null && !this.isProcessing) {
+ this.currentTurn = agentId
+ this.isProcessing = true
+ this.onTurnGranted(agentId)
+ this.onBroadcast()
+ return true
+ }
+ if (!this.turnQueue.includes(agentId) && this.currentTurn !== agentId) {
+ this.turnQueue.push(agentId)
+ this.onBroadcast()
+ }
+ return false
+ }
+
+ releaseTurn(agentId) {
+ if (this.currentTurn !== agentId) return
+
+ this.currentTurn = null
+ this.isProcessing = false
+
+ if (this.turnQueue.length > 0) {
+ const nextAgent = this.turnQueue.shift()
+ setTimeout(() => {
+ this.currentTurn = nextAgent
+ this.isProcessing = true
+ this.onTurnGranted(nextAgent)
+ this.onBroadcast()
+ }, 500)
+ } else {
+ this.onBroadcast()
+ }
+ }
+
+ getState() {
+ return {
+ currentTurn: this.currentTurn,
+ turnQueue: [...this.turnQueue],
+ isProcessing: this.isProcessing
+ }
+ }
+
+ reset() {
+ this.currentTurn = null
+ this.turnQueue = []
+ this.isProcessing = false
+ }
+}
+
+module.exports = { TurnManager }
+
+