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/src/server/providers/claude.ts

oversteppinge06f33f5e1d8
diff --git a/xspace-agent/xspace-agent/src/server/providers/claude.ts b/xspace-agent/xspace-agent/src/server/providers/claude.ts
new file mode 100644
index 000000000..4fb95833e
--- /dev/null
+++ b/xspace-agent/xspace-agent/src/server/providers/claude.ts
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: Apache-2.0
+// Copyright 2026 nirholas (https://github.com/nirholas/xspace-agent) [§83]
+
+import Anthropic from "@anthropic-ai/sdk"
+import type { Provider } from "../types"
+
+const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY })
+const MODEL = process.env.CLAUDE_MODEL || "claude-sonnet-4-20250514"
+const MAX_HISTORY = 20
+
+const history: Record<number, Array<{ role: "user" | "assistant"; content: string }>> = {
+ 0: [],
+ 1: [],
+}
+
+function addToHistory(agentId: number, role: "user" | "assistant", content: string): void {
+ 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: number,
+ userText: string,
+ systemPrompt: string,
+): AsyncGenerator<string, void, unknown> {
+ 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: number): void {
+ history[agentId] = []
+}
+
+const provider: Provider = { type: "socket", streamResponse, clearHistory }
+module.exports = provider
+
+