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/providers/claude.js

oversteppingcfa3a4e85bb7
diff --git a/xspace-agent/providers/claude.js b/xspace-agent/providers/claude.js
new file mode 100644
index 000000000..d1bed9da5
--- /dev/null
+++ b/xspace-agent/providers/claude.js
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: Apache-2.0
+// Copyright 2026 nirholas (https://github.com/nirholas/xspace-agent) [§79]
+
+// DEPRECATED: Use packages/core (xspace-agent) instead.
+// This file is kept for backward compatibility with server.js.
+// Will be removed in v1.0.
+
+const Anthropic = require("@anthropic-ai/sdk")
+
+const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY })
+const MODEL = process.env.CLAUDE_MODEL || "claude-sonnet-4-20250514"
+const MAX_HISTORY = 20
+
+// Per-agent conversation history
+const history = { 0: [], 1: [] }
+
+function addToHistory(agentId, role, content) {
+ if (!history[agentId]) history[agentId] = []
+ history[agentId].push({ role, content })
+ if (history[agentId].length > MAX_HISTORY) {
+ history[agentId] = history[agentId].slice(-MAX_HISTORY)
+ }
+}
+
+async function* streamResponse(agentId, userText, systemPrompt) {
+ addToHistory(agentId, "user", userText)
+
+ const stream = await client.messages.stream({
+ model: MODEL,
+ max_tokens: 300,
+ system: systemPrompt,
+ messages: history[agentId]
+ })
+
+ let fullResponse = ""
+
+ for await (const event of stream) {
+ if (event.type === "content_block_delta" && event.delta?.type === "text_delta") {
+ const text = event.delta.text
+ fullResponse += text
+ yield text
+ }
+ }
+
+ addToHistory(agentId, "assistant", fullResponse)
+}
+
+function clearHistory(agentId) {
+ history[agentId] = []
+}
+
+module.exports = {
+ type: "socket",
+ streamResponse,
+ clearHistory
+}
+
+