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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
add xspace-agent/xspace-agent/src/providers/llm/groq.ts
overstepping95938f580530
diff --git a/xspace-agent/xspace-agent/src/providers/llm/groq.ts b/xspace-agent/xspace-agent/src/providers/llm/groq.tsnew file mode 100644index 000000000..8f5e08e63--- /dev/null+++ b/xspace-agent/xspace-agent/src/providers/llm/groq.ts@@ -0,0 +1,105 @@+// SPDX-License-Identifier: Apache-2.0+// Copyright 2026 nirholas (https://github.com/nirholas/xspace-agent) [§70]++import axios from "axios";+import { config } from "../../config.js";+import { createChildLogger } from "../../utils/logger.js";+import type { LLMProvider } from "../../types.js";++const log = createChildLogger("llm:groq");++interface MessageParam {+ role: "system" | "user" | "assistant";+ content: string;+}++export class GroqLLM implements LLMProvider {+ readonly type = "socket" as const;+ private apiKey: string;+ private model: string;+ private history: Record<number, MessageParam[]> = {};++ constructor() {+ if (!config.groqApiKey)+ throw new Error("GROQ_API_KEY is required for Groq provider");+ this.apiKey = config.groqApiKey;+ this.model = config.groqModel;+ log.info("Initialized with model: %s", this.model);+ }++ private addToHistory(+ agentId: number,+ role: "user" | "assistant",+ content: string,+ ): void {+ if (!this.history[agentId]) this.history[agentId] = [];+ this.history[agentId]!.push({ role, content });+ if (this.history[agentId]!.length > 20) {+ this.history[agentId] = this.history[agentId]!.slice(-20);+ }+ }++ async *streamResponse(+ agentId: number,+ userText: string,+ systemPrompt: string,+ ): AsyncGenerator<string, void, unknown> {+ this.addToHistory(agentId, "user", userText);++ const messages: MessageParam[] = [+ { role: "system", content: systemPrompt },+ ...(this.history[agentId] ?? []),+ ];++ const response = await axios.post(+ "https://api.groq.com/openai/v1/chat/completions",+ {+ model: this.model,+ messages,+ max_tokens: config.maxTokens,+ stream: true,+ },+ {+ headers: {+ Authorization: `Bearer ${this.apiKey}`,+ "Content-Type": "application/json",+ },+ responseType: "stream",+ timeout: config.providerTimeout,+ },+ );++ let fullResponse = "";++ for await (const chunk of response.data as AsyncIterable<Buffer>) {+ const lines = chunk+ .toString()+ .split("\n")+ .filter((l: string) => l.startsWith("data: "));+ for (const line of lines) {+ const data = line.slice(6).trim();+ if (data === "[DONE]") break;+ try {+ const parsed = JSON.parse(data) as {+ choices?: Array<{ delta?: { content?: string } }>;+ };+ const delta = parsed.choices?.[0]?.delta?.content;+ if (delta) {+ fullResponse += delta;+ yield delta;+ }+ } catch {+ // skip malformed chunks+ }+ }+ }++ this.addToHistory(agentId, "assistant", fullResponse);+ }++ clearHistory(agentId: number): void {+ this.history[agentId] = [];+ }+}++