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.

2.4 KB
Raw Blame
// `dress_avatar` — apply or remove accessories on a spawned avatar session
// and optionally set the pose. Returns the updated session manifest and a
// refreshed viewer URL.

import { z } from 'zod';

import { ACCESSORIES, POSE_PRESETS, findAccessory, getSession, updateSession, viewerUrlFor } from '../lib/avatars.js';

export const def = {
	name: 'dress_avatar',
	title: 'Apply accessories + pose to a spawned avatar',
	// MCP ToolAnnotations — safety hints surfaced to MCP clients.
	annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
	description:
		'Apply (or replace) accessories on a spawned avatar session and optionally set a pose. Pass accessoryIds to set the full accessory list (empty array clears them). Pass pose to switch animations. Returns the updated viewer URL. Use this after spawn_avatar to change what a session wears or how it poses; for a still image of the result, call render_avatar with the same sessionId.',
	inputSchema: {
		sessionId: z.string().describe('Session id returned by spawn_avatar.'),
		accessoryIds: z.array(z.string()).optional()
			.describe(`Full list of accessory ids to wear. Allowed: ${ACCESSORIES.map((a) => a.id).join(', ')}. Empty array clears.`),
		pose: z.string().optional()
			.describe(`Pose preset. Allowed: ${POSE_PRESETS.join(', ')}.`),
	},
	async handler(args) {
		const { sessionId, accessoryIds, pose } = args || {};
		const session = getSession(sessionId);
		if (!session) {
			return { ok: false, error: 'unknown_session', message: `No session ${sessionId}. Call spawn_avatar first.` };
		}
		const patch = {};
		if (Array.isArray(accessoryIds)) {
			const resolved = [];
			const missing = [];
			for (const id of accessoryIds) {
				const acc = findAccessory(id);
				if (!acc) {
					missing.push(id);
					continue;
				}
				resolved.push(acc);
			}
			if (missing.length) {
				return { ok: false, error: 'unknown_accessory', missing, allowed: ACCESSORIES.map((a) => a.id) };
			}
			patch.accessories = resolved;
		}
		if (pose) {
			if (!POSE_PRESETS.includes(pose)) {
				return { ok: false, error: 'unknown_pose', pose, allowed: POSE_PRESETS };
			}
			patch.pose = pose;
		}
		const updated = updateSession(sessionId, patch);
		return {
			ok: true,
			sessionId: updated.id,
			avatar: updated.avatar,
			accessories: updated.accessories,
			pose: updated.pose,
			viewerUrl: viewerUrlFor(updated),
			lastUpdated: updated.lastUpdated,
		};
	},
};