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
feat(chat): gate wallet tools through the platform guard before they run
nirholas4305d1bb96fc
diff --git a/chat/src/App.svelte b/chat/src/App.svelteindex 3376c2922..d2bb472e3 100644--- a/chat/src/App.svelte+++ b/chat/src/App.svelte@@ -69,6 +69,7 @@feX,} from './feather.js';import { defaultToolSchema, agentToolSchema, pumpToolSchema, agentPaymentsToolSchema, pumpTradingToolSchema, walletToolSchema, curatedToolPacks } from './tools.js';+ import { guardPreflight, isFundMovingTool, lastGuardVerdict } from './guard.js';import { signMessageSolana, signMessageEVM } from './walletAuth.js';import { debounce, readFileAsDataURL, parseToolCallArguments } from './util.js';import { flash, focusOnMount } from './actions';@@ -849,7 +850,27 @@'choose',clientTool.clientDefinition.body);- const promise = clientFn(toolcall.arguments, choose);+ // Fund-moving tools preflight through the platform GuardChain+ // (/api/agent/guard) BEFORE the tool body runs, so a policy+ // block never reaches the wallet, and MEV-protective argument+ // adjustments (the slippage clamp) apply to the real call.+ const promise = (async () => {+ if (isFundMovingTool(toolcall.name)) {+ const verdict = await guardPreflight(toolcall.name, toolcall.arguments);+ if (verdict?.decision === 'block') {+ convo.messages[i].toolcalls[ti].finished = true;+ saveMessage(convo.messages[i]);+ return {+ error: `Blocked by the three.ws transaction guard: ${verdict.reason}`,+ guard: { decision: verdict.decision, blockedBy: verdict.blockedBy, warnings: verdict.warnings },+ };+ }+ if (verdict?.modifiedArguments) {+ Object.assign(toolcall.arguments, verdict.modifiedArguments);+ }+ }+ return clientFn(toolcall.arguments, choose);+ })();toolPromises.push(promise);} else if (BUILTIN_ACTION_TOOLS.has(toolcall.name)) {// Built-in scene/avatar action: run against the live <agent-3d>.@@ -2862,8 +2883,9 @@{#if txApprovalDetails}<TxApprovalModaldetails={txApprovalDetails}- onApprove={() => { const r = txApprovalResolve; txApprovalDetails = null; txApprovalResolve = null; txApprovalReject = null; r?.(); }}- onReject={() => { const r = txApprovalReject; txApprovalDetails = null; txApprovalResolve = null; txApprovalReject = null; r?.(new Error('User rejected transaction')); }}+ guard={$lastGuardVerdict}+ onApprove={() => { const r = txApprovalResolve; txApprovalDetails = null; txApprovalResolve = null; txApprovalReject = null; lastGuardVerdict.set(null); r?.(); }}+ onReject={() => { const r = txApprovalReject; txApprovalDetails = null; txApprovalResolve = null; txApprovalReject = null; lastGuardVerdict.set(null); r?.(new Error('User rejected transaction')); }}/>{/if}diff --git a/chat/src/TxApprovalModal.svelte b/chat/src/TxApprovalModal.svelteindex 5ecea1ea7..13ffcaa40 100644--- a/chat/src/TxApprovalModal.svelte+++ b/chat/src/TxApprovalModal.svelte@@ -4,11 +4,23 @@import Button from './Button.svelte';export let details; // { network, from, to, amount, token, memo?, estimatedFee? }+ export let guard = null; // GuardChain verdict from /api/agent/guard, when preflightedexport let onApprove; // () => voidexport let onReject; // () => voidlet pending = false;+ // A `block` verdict never reaches this modal (the tool body is refused+ // before the wallet prompt). The intervention layer always reads+ // approval_required here because this modal IS the intervention, so the+ // chip keys off every OTHER layer: "cleared" means nothing beyond the+ // approval you are already giving was flagged.+ $: guardFlags = (guard?.layers || []).filter(+ (l) => l.layer !== 'intervention' && ['warn', 'approval_required', 'block', 'error'].includes(l.status),+ );+ $: guardTone = guard && guardFlags.length === 0 ? 'ok' : 'review';+ $: guardCriticalSpots = (guard?.blindSpots || []).filter((s) => s.severity === 'critical');+function truncate(addr) {if (!addr || addr.length <= 12) return addr;return addr.slice(0, 6) + '…' + addr.slice(-4);@@ -63,6 +75,29 @@</tbody></table>+ {#if guard}+ <div class="mb-6 rounded-lg border border-slate-700 bg-slate-800/60 p-3 text-xs">+ <div class="mb-1.5 flex items-center gap-2">+ <span class="font-medium text-slate-300">Platform guard</span>+ {#if guardTone === 'ok'}+ <span class="rounded-full bg-emerald-900/70 px-2 py-0.5 font-medium text-emerald-300">cleared</span>+ {:else}+ <span class="rounded-full bg-amber-900/70 px-2 py-0.5 font-medium text-amber-300">review advised</span>+ {/if}+ <span class="ml-auto text-slate-500">{guard.coverageScore}% coverage</span>+ </div>+ {#each guardFlags as flag}+ <p class="mb-1 text-amber-200/90">{flag.label}: {flag.reason}</p>+ {/each}+ {#each guard.warnings || [] as warning}+ <p class="mb-1 text-amber-200/90">{warning}</p>+ {/each}+ {#each guardCriticalSpots as spot}+ <p class="text-slate-400">Unchecked: {spot.title}</p>+ {/each}+ </div>+ {/if}+<div class="flex gap-3"><Buttonvariant="outline"diff --git a/chat/src/guard.js b/chat/src/guard.jsnew file mode 100644index 000000000..3ced216fc--- /dev/null+++ b/chat/src/guard.js@@ -0,0 +1,87 @@+// GuardChain preflight for fund-moving client tools.+//+// Before a wallet tool body runs (and before the wallet ever prompts), the+// call is preflighted through POST /api/agent/guard, the seven-layer policy+// engine from @three-ws/agent-runtime. A `block` verdict stops the tool+// without touching the wallet; `require_approval` and `allow` proceed into+// the existing TxApprovalModal, enriched with the verdict so the user sees+// WHY the platform thinks this call is fine, risky, or under-checked.+// Argument adjustments (the MEV slippage clamp) are applied before execution.+//+// Fail-open by design: this endpoint is defense-in-depth on top of the+// wallet-approval modal, which always gates signing. If the preflight is+// unreachable, the modal still stands between the model and the wallet, so+// losing the enrichment is strictly better than bricking transfers.++import { writable } from 'svelte/store';++/** The most recent guard verdict, consumed by TxApprovalModal. */+export const lastGuardVerdict = writable(null);++/** Tools whose execution moves value out of the connected wallet. */+const FUND_MOVING_TOOLS = new Set([+ 'solana_transfer',+ 'solana_swap',+ 'evm_transfer',+ 'evm_swap',+ 'pumpfunBuy',+ 'pumpfunSell',+ 'pumpfunSellAll',+ 'LaunchPumpToken',+ 'MintScene',+ 'agentPaymentsDistribute',+ 'agentPaymentsWithdraw',+]);++export function isFundMovingTool(name) {+ return FUND_MOVING_TOOLS.has(name);+}++/** Pull the destination/token facts the firewall layers understand. */+function callFacts(name, args = {}) {+ const destination = args.recipient || args.destination || args.to || undefined;+ const token = args.token || args.inputMint || args.fromToken || args.mint || undefined;+ return { destination, token };+}++/**+ * Preflight one tool call. Resolves to the GuardChain verdict+ * ({ decision, reason, layers, warnings, blindSpots, coverageScore,+ * modifiedArguments }) or null when the guard endpoint cannot be reached.+ */+export async function guardPreflight(name, args) {+ const { destination, token } = callFacts(name, args);+ const controller = new AbortController();+ const timer = setTimeout(() => controller.abort(), 5000);+ try {+ const res = await fetch('/api/agent/guard', {+ method: 'POST',+ headers: { 'content-type': 'application/json' },+ signal: controller.signal,+ body: JSON.stringify({+ calls: [+ {+ identifier: name,+ apiName: name,+ arguments: args || {},+ destination,+ token,+ // The wallet modal always gates these tools, so the+ // intervention layer should agree with reality.+ interventionConfig: 'required',+ },+ ],+ approvalMode: 'manual',+ }),+ });+ if (!res.ok) return null;+ const data = await res.json();+ const verdict = data?.verdicts?.[0]?.verdict || null;+ if (verdict) lastGuardVerdict.set(verdict);+ return verdict;+ } catch {+ return null;+ } finally {+ clearTimeout(timer);+ }+}