Download src/components/friend/frontend/api.ts from chenbhao/codev: direct link, hf CLI and curl.
- Browser
- Download file 1.53 kB
-
https://huggingface.co/chenbhao/codev/resolve/afbc7edaae4e6bb0102ba024b49ce8be89d2264c/src/components/friend/frontend/api.ts
- Command line
-
hf download hf://chenbhao/codev@afbc7edaae4e6bb0102ba024b49ce8be89d2264c/src/components/friend/frontend/api.ts
-
curl -L -o api.ts https://huggingface.co/chenbhao/codev/resolve/afbc7edaae4e6bb0102ba024b49ce8be89d2264c/src/components/friend/frontend/api.ts
1.53 kB
| import type { VRMSceneHandle } from './components/VRMScene' | |
| /** VersperClaw server base URL */ | |
| export const SERVER_URL = 'http://127.0.0.1:3456' | |
| /** Base path for the Friend VRM plugin API */ | |
| export const FRIEND_API = `${SERVER_URL}/plugins/friend` | |
| let sceneHandle: VRMSceneHandle | null = null | |
| export function bindScene(handle: VRMSceneHandle | null) { | |
| sceneHandle = handle | |
| } | |
| /** | |
| * POST to a server API. If the request body contains an `emotion` field, | |
| * the VRM expression will automatically change to match. | |
| * | |
| * Body example: | |
| * { emotion: "happy", message: "hello", ... } | |
| * | |
| * Supported emotions: happy, sad, angry, surprised, think, neutral | |
| * | |
| * Optional fields: | |
| * emotionDuration — ms, auto-reset to neutral after this time | |
| * emotionIntensity — 0~1, defaults to 1 | |
| */ | |
| export async function postApi<T = any>(url: string, body: Record<string, any>): Promise<T> { | |
| // Trigger emotion from the request body | |
| if (body.emotion && sceneHandle) { | |
| const duration = body.emotionDuration as number | undefined | |
| const intensity = body.emotionIntensity as number | undefined | |
| if (duration) { | |
| sceneHandle.setEmotionWithReset(body.emotion, duration, intensity) | |
| } else { | |
| sceneHandle.setEmotion(body.emotion, intensity) | |
| } | |
| } | |
| const res = await fetch(url, { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify(body), | |
| }) | |
| if (!res.ok) { | |
| throw new Error(`API error: ${res.status} ${res.statusText}`) | |
| } | |
| return res.json() | |
| } | |