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/agent-voice-chat/providers/conversation-history.js

oversteppinge4880a17fd52
diff --git a/xspace-agent/agent-voice-chat/providers/conversation-history.js b/xspace-agent/agent-voice-chat/providers/conversation-history.js
new file mode 100644
index 000000000..736e218ad
--- /dev/null
+++ b/xspace-agent/agent-voice-chat/providers/conversation-history.js
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: Apache-2.0
+// Copyright 2026 nirholas (https://github.com/nirholas/xspace-agent)
+
+const DEFAULT_MAX_HISTORY = 20
+
+class ConversationHistory {
+ constructor(maxHistory = DEFAULT_MAX_HISTORY) {
+ this.maxHistory = maxHistory
+ this.histories = {}
+ }
+
+ _key(roomId, agentId) {
+ return `${roomId || "default"}:${agentId}`
+ }
+
+ add(roomId, agentId, role, content) {
+ const key = this._key(roomId, agentId)
+ if (!this.histories[key]) this.histories[key] = []
+ this.histories[key].push({ role, content })
+ if (this.histories[key].length > this.maxHistory) {
+ this.histories[key] = this.histories[key].slice(-this.maxHistory)
+ }
+ }
+
+ get(roomId, agentId) {
+ return this.histories[this._key(roomId, agentId)] || []
+ }
+
+ clear(agentId, roomId) {
+ delete this.histories[this._key(roomId, agentId)]
+ }
+
+ clearRoom(roomId) {
+ const prefix = `${roomId}:`
+ for (const key of Object.keys(this.histories)) {
+ if (key.startsWith(prefix)) delete this.histories[key]
+ }
+ }
+}
+
+module.exports = { ConversationHistory }
+
+