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.

feat(wallet): intent handling, widget actions, and dashboard account updates

nirholas5891f10a430e
diff --git a/api/_lib/wallet-intents.js b/api/_lib/wallet-intents.js
index 0a661c41b..4fbbd6c65 100644
--- a/api/_lib/wallet-intents.js
+++ b/api/_lib/wallet-intents.js
@@ -560,6 +560,28 @@ async function callOpenRouterCompile({ apiKey, system, messages }) {
return JSON.parse(call.function.arguments);
}
+async function callGrokCompile({ apiKey, system, messages }) {
+ const resp = await fetchWithTimeout('https://api.x.ai/v1/chat/completions', {
+ method: 'POST',
+ headers: {
+ Authorization: `Bearer ${apiKey}`,
+ 'content-type': 'application/json',
+ },
+ body: JSON.stringify({
+ model: 'grok-4.1-fast',
+ max_tokens: 700,
+ messages: [{ role: 'system', content: system }, ...messages],
+ tools: [OPENAI_COMPILE_TOOL],
+ tool_choice: { type: 'function', function: { name: COMPILE_TOOL.name } },
+ }),
+ });
+ if (!resp.ok) throw new Error(`grok ${resp.status}`);
+ const j = await resp.json();
+ const call = j.choices?.[0]?.message?.tool_calls?.[0];
+ if (!call?.function?.arguments) throw new Error('grok: no tool_call');
+ return JSON.parse(call.function.arguments);
+}
+
/**
* Compile a plain-language rule into a validated structured intent. The model is
* forced to emit the tool schema; the server then re-validates every field. A
@@ -575,8 +597,9 @@ export async function compileIntentFromText(text, ctx = {}) {
if (utterance.length > 1000) return { ok: false, error: 'too_long', message: 'that is too long — shorten the rule' };
const anthropicKey = ctx.anthropicKey || process.env.ANTHROPIC_API_KEY;
+ const grokKey = ctx.grokKey || process.env.GROK_API_KEY;
const openrouterKey = ctx.openrouterKey || process.env.OPENROUTER_API_KEY;
- if (!anthropicKey && !openrouterKey) {
+ if (!anthropicKey && !grokKey && !openrouterKey) {
return { ok: false, error: 'unavailable', message: 'the rule compiler is not configured on this deployment — build the rule with the form instead' };
}
@@ -597,6 +620,10 @@ export async function compileIntentFromText(text, ctx = {}) {
try { raw = await callAnthropicCompile({ apiKey: anthropicKey, system, messages }); provider = 'anthropic'; }
catch (e) { tried.push(`anthropic:${e.message}`); }
}
+ if (!raw && grokKey) {
+ try { raw = await callGrokCompile({ apiKey: grokKey, system, messages }); provider = 'grok'; }
+ catch (e) { tried.push(`grok:${e.message}`); }
+ }
if (!raw && openrouterKey) {
try { raw = await callOpenRouterCompile({ apiKey: openrouterKey, system, messages }); provider = 'openrouter'; }
catch (e) { tried.push(`openrouter:${e.message}`); }
diff --git a/api/agents/solana-intent.js b/api/agents/solana-intent.js
index f2f2b7135..33754277f 100644
--- a/api/agents/solana-intent.js
+++ b/api/agents/solana-intent.js
@@ -296,6 +296,28 @@ async function callOpenRouter({ apiKey, system, messages }) {
return JSON.parse(call.function.arguments);
}
+async function callGrok({ apiKey, system, messages }) {
+ const resp = await fetchWithTimeout('https://api.x.ai/v1/chat/completions', {
+ method: 'POST',
+ headers: {
+ Authorization: `Bearer ${apiKey}`,
+ 'content-type': 'application/json',
+ },
+ body: JSON.stringify({
+ model: 'grok-4.1-fast',
+ max_tokens: 600,
+ messages: [{ role: 'system', content: system }, ...messages],
+ tools: [OPENAI_TOOL],
+ tool_choice: { type: 'function', function: { name: INTENT_TOOL.name } },
+ }),
+ });
+ if (!resp.ok) throw new Error(`grok ${resp.status}`);
+ const j = await resp.json();
+ const call = j.choices?.[0]?.message?.tool_calls?.[0];
+ if (!call?.function?.arguments) throw new Error('grok: no tool_call');
+ return JSON.parse(call.function.arguments);
+}
+
// ── handler ──────────────────────────────────────────────────────────────────────
export async function handleIntent(req, res, id) {
@@ -353,6 +375,7 @@ export async function handleIntent(req, res, id) {
userKeys = {};
}
const anthropicKey = userKeys.anthropic || process.env.ANTHROPIC_API_KEY;
+ const grokKey = userKeys.grok || process.env.GROK_API_KEY;
const openrouterKey = userKeys.openrouter || process.env.OPENROUTER_API_KEY;
let rawIntent = null;
@@ -366,6 +389,14 @@ export async function handleIntent(req, res, id) {
tried.push(`anthropic:${e.message}`);
}
}
+ if (!rawIntent && grokKey) {
+ try {
+ rawIntent = await callGrok({ apiKey: grokKey, system, messages });
+ provider = 'grok';
+ } catch (e) {
+ tried.push(`grok:${e.message}`);
+ }
+ }
if (!rawIntent && openrouterKey) {
try {
rawIntent = await callOpenRouter({ apiKey: openrouterKey, system, messages });
@@ -376,7 +407,7 @@ export async function handleIntent(req, res, id) {
}
if (!rawIntent) {
- if (!anthropicKey && !openrouterKey) {
+ if (!anthropicKey && !grokKey && !openrouterKey) {
// Honest signal so the client can fall back to the manual HUD form rather
// than fake a parse.
return error(res, 503, 'intent_unavailable', 'voice trading is not configured on this deployment — use the wallet form');
diff --git a/api/agents/wallet-intents.js b/api/agents/wallet-intents.js
index 60c609471..117ebbde1 100644
--- a/api/agents/wallet-intents.js
+++ b/api/agents/wallet-intents.js
@@ -147,6 +147,7 @@ async function compileContext(req, owned, network) {
limits: getSpendLimits(owned.meta),
tradeLimits: getTradeLimits(owned.meta),
anthropicKey: userKeys.anthropic,
+ grokKey: userKeys.grok,
openrouterKey: userKeys.openrouter,
};
}
diff --git a/api/widgets/[id]/[action].js b/api/widgets/[id]/[action].js
index 1c7b1b63a..bde4bfc3d 100644
--- a/api/widgets/[id]/[action].js
+++ b/api/widgets/[id]/[action].js
@@ -93,6 +93,14 @@ const PROVIDERS = {
url: 'https://api.openai.com/v1/chat/completions',
style: 'openai',
},
+ // xAI Grok (api.x.ai): paid, OpenAI-compatible; last-resort backstop like
+ // Anthropic/OpenAI. Required here because it is in DEFAULT_PROVIDER_ORDER.
+ grok: {
+ envKey: 'GROK_API_KEY',
+ defaultModel: PROVIDER_MODEL_DEFAULTS.grok,
+ url: 'https://api.x.ai/v1/chat/completions',
+ style: 'openai',
+ },
// IBM watsonx.ai. Granite 3.x speaks OpenAI-shaped tool calls over the chat
// API, so a Granite-brained widget animates and gestures like the others; the
// IAM token + project scoping live in callWatsonx (auth is async, so it can't
@@ -106,11 +114,11 @@ const PROVIDERS = {
// Brain settings that surface in widget config. `auto` picks the first
// configured provider; `custom`/`none` keep their legacy meanings.
-const BRAIN_PROVIDERS = new Set(['auto', 'anthropic', 'openrouter', 'groq', 'nvidia', 'openai', 'watsonx']);
+const BRAIN_PROVIDERS = new Set(['auto', 'anthropic', 'openrouter', 'groq', 'nvidia', 'openai', 'grok', 'watsonx']);
const chatBody = z.object({
message: z.string().trim().min(1).max(4000),
- provider: z.enum(['auto', 'anthropic', 'openrouter', 'groq', 'nvidia', 'openai', 'watsonx']).optional(),
+ provider: z.enum(['auto', 'anthropic', 'openrouter', 'groq', 'nvidia', 'openai', 'grok', 'watsonx']).optional(),
model: z.string().min(1).max(160).optional(),
history: z
.array(
diff --git a/src/dashboard-next/pages/account.js b/src/dashboard-next/pages/account.js
index 1081fc3e5..5a9a1b87b 100644
--- a/src/dashboard-next/pages/account.js
+++ b/src/dashboard-next/pages/account.js
@@ -270,6 +270,7 @@ async function copyToClipboard(text) {
const PROVIDER_META = {
anthropic: { label: 'Anthropic (Claude)', placeholder: 'sk-ant-api03-…', url: 'https://console.anthropic.com/settings/keys' },
openai: { label: 'OpenAI (GPT-4)', placeholder: 'sk-proj-…', url: 'https://platform.openai.com/api-keys' },
+ grok: { label: 'Grok (xAI)', placeholder: 'xai-…', url: 'https://console.x.ai' },
meshy: { label: 'Meshy AI (3D gen)', placeholder: 'msy_…', url: 'https://www.meshy.ai/settings/api' },
tripo: { label: 'Tripo AI (3D gen)', placeholder: 'tsk_…', url: 'https://platform.tripo3d.ai/api-keys' },
rodin: { label: 'Rodin · Hyper3D (3D gen)', placeholder: 'your Rodin key', url: 'https://developer.hyper3d.ai' },
diff --git a/src/editor/manifest-builder.js b/src/editor/manifest-builder.js
index 5528641d0..a89725f27 100644
--- a/src/editor/manifest-builder.js
+++ b/src/editor/manifest-builder.js
@@ -26,6 +26,13 @@ const ANTHROPIC_MODELS = [
{ id: 'claude-opus-4-6', label: 'Claude Opus 4.6' },
{ id: 'claude-opus-4-7', label: 'Claude Opus 4.7' },
];
+// xAI Grok, routed through the same we-pay proxy (OpenAI-compatible upstream;
+// the proxy translates shapes server-side). Paid on the host's GROK_API_KEY.
+const GROK_MODELS = [
+ { id: 'grok-4.5', label: 'Grok 4.5 (xAI)' },
+ { id: 'grok-4.3', label: 'Grok 4.3 (xAI · 1M context)' },
+ { id: 'grok-4.1-fast', label: 'Grok 4.1 Fast (xAI · budget)' },
+];
const OPENAI_MODELS = [
{ id: 'gpt-5.6-sol', label: 'GPT-5.6 Sol' },
{ id: 'gpt-5.6-terra', label: 'GPT-5.6 Terra' },
@@ -992,10 +999,11 @@ export function mountManifestBuilder(rootEl, options = {}) {
models = OPENAI_MODELS;
sel.innerHTML = models.map(optHtml).join('');
} else {
- models = [...FREE_MODELS, ...ANTHROPIC_MODELS];
+ models = [...FREE_MODELS, ...ANTHROPIC_MODELS, ...GROK_MODELS];
sel.innerHTML = `
<optgroup label="Free — host-paid (recommended)">${FREE_MODELS.map(optHtml).join('')}</optgroup>
<optgroup label="Paid Claude (host's Anthropic key)">${ANTHROPIC_MODELS.map(optHtml).join('')}</optgroup>
+ <optgroup label="Paid Grok (host's xAI key)">${GROK_MODELS.map(optHtml).join('')}</optgroup>
`;
}
if (models.find((m) => m.id === state.brainModel)) {
diff --git a/src/widget-types.js b/src/widget-types.js
index 79cadd968..84ef67bc0 100644
--- a/src/widget-types.js
+++ b/src/widget-types.js
@@ -207,7 +207,7 @@ const TYPE_SCHEMAS = {
agentTitle: z.string().max(80).default('AI Agent'),
avatar: z.enum(['embedded', 'chat-only']).default('embedded'),
brainProvider: z
- .enum(['none', 'auto', 'anthropic', 'openrouter', 'groq', 'openai', 'watsonx', 'custom'])
+ .enum(['none', 'auto', 'anthropic', 'openrouter', 'groq', 'openai', 'grok', 'watsonx', 'custom'])
.default('anthropic'),
proxyURL: z.string().url().startsWith('https://').or(z.literal('')).default(''),
systemPrompt: z.string().max(4000).default(''),