mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-18 22:14:27 +00:00
Some checks are pending
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Votes / vote (full suite) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
* feat: Add Lia's Behavior Engine A framework-free engine that plays Lia's actions step by step, moves her along a platform, and lets her choose her own activities. An attention budget keeps her quiet while the user types and saves bigger routines for when they step away. The catalog holds feelings, speech, gestures, dances, travel, small routines and page reactions. * fix: Let a Click Wake Lia From a Nap and Run One Animation Loop * fix: Keep Lia Stopped When Stopped Mid-Frame and Snap Walks Under Reduced Motion * fix: Wake Lia When Typing Interrupts a Nap and Keep Her Walks on the Current Platform * test: Drive Lia's Engine on Real Animation Frames in a Browser * fix: Keep One Animation Loop Across a Mid-Frame Restart and Place Lia Before Her First Move * fix: Play Every Step of an Action the Host Chains From onAction * test: Require Lia's Reduced-Motion Chooser to Pick Something * fix: Keep Lia Free to Act Before the First Keystroke and Skip Pointer Walks Without a Pointer * fix: Hold Lia's Step While She Has No Layout and Replace Actions Without a Gap * fix: Keep the Walk of an Action Started When the Previous One Ends * fix: Wake Lia From a Nap Played Above Reaction Priority * fix: Pause Lia's Screen and Face Clocks Along With Her Step * fix: Stop Lia's Own Clock While She Has No Layout and Ignore Empty Obstacles
119 lines
4.2 KiB
TypeScript
119 lines
4.2 KiB
TypeScript
import { expect, test } from '@playwright/test';
|
|
import type { Page } from '@playwright/test';
|
|
import type * as Catalog from '../../../../client/src/components/Lia/engine/catalog';
|
|
import type * as Engine from '../../../../client/src/components/Lia/engine/engine';
|
|
import { openLiaEngine } from '../lia.helpers';
|
|
|
|
/**
|
|
* Lia's behavior engine, running on real animation frames and a real canvas. Nothing mounts it
|
|
* yet, so each test serves the engine modules to a blank page and drives it as a host would.
|
|
*/
|
|
type Lia = { engine: typeof Engine; catalog: typeof Catalog };
|
|
|
|
const openEngine = (page: Page) => openLiaEngine(page, ['engine', 'catalog']);
|
|
|
|
test.describe("Lia's behavior engine", () => {
|
|
test('Lia stays quiet while the user types and saves big routines for when they step away @scenario:lia-engine-attention-budget', async ({
|
|
page,
|
|
}) => {
|
|
await openEngine(page);
|
|
const result = await page.evaluate(async () => {
|
|
const { engine: mod, catalog } = (window as unknown as { lia: Lia }).lia;
|
|
const canvas = document.createElement('canvas');
|
|
document.body.appendChild(canvas);
|
|
const engine = new mod.LiaEngine(canvas, {
|
|
platform: () => ({ y: 200, x0: 100, x1: 700 }),
|
|
onBubble: () => undefined,
|
|
});
|
|
engine.life = false;
|
|
engine.start();
|
|
const frame = () => new Promise((resolve) => requestAnimationFrame(resolve));
|
|
for (let i = 0; i < 10; i++) {
|
|
await frame();
|
|
}
|
|
const pixels = (canvas.getContext('2d') as CanvasRenderingContext2D)
|
|
.getImageData(0, 0, canvas.width, canvas.height)
|
|
.data.some((v, i) => i % 4 === 3 && v > 0);
|
|
|
|
engine.play('travel-walk', 1);
|
|
await frame();
|
|
engine.noteTyping();
|
|
const afterTyping = engine.current?.id ?? null;
|
|
const choiceWhileTyping = engine.chooseLife();
|
|
|
|
engine.play('nap', 1);
|
|
engine.noteTyping();
|
|
const napAfterTyping = engine.current?.id ?? null;
|
|
engine.stop();
|
|
|
|
let s = 7;
|
|
const random = () => {
|
|
s = (s * 16807) % 2147483647;
|
|
return (s - 1) / 2147483646;
|
|
};
|
|
const bigShare = (now: number) => {
|
|
let big = 0;
|
|
for (let i = 0; i < 400; i++) {
|
|
const def = catalog.ACTION_BY_ID.get(engine.chooseLife(now, random) ?? '');
|
|
if (def && (def.moves || ['life', 'dance', 'travel'].includes(def.cat))) {
|
|
big += 1;
|
|
}
|
|
}
|
|
return big / 400;
|
|
};
|
|
const base = performance.now() + 10_000;
|
|
engine.noteActivity(false, base);
|
|
return {
|
|
pixels,
|
|
afterTyping,
|
|
choiceWhileTyping,
|
|
napAfterTyping,
|
|
present: bigShare(base),
|
|
away: bigShare(base + 60_000),
|
|
};
|
|
});
|
|
expect(result.pixels).toBe(true);
|
|
expect(result.afterTyping).toBeNull();
|
|
expect(result.choiceWhileTyping).toBeNull();
|
|
expect(result.napAfterTyping).toBe('r-wake');
|
|
expect(result.present).toBeLessThan(0.25);
|
|
expect(result.away).toBeGreaterThan(0.5);
|
|
});
|
|
|
|
test('Lia never walks under reduced motion @scenario:lia-engine-reduced-motion', async ({
|
|
page,
|
|
}) => {
|
|
await openEngine(page);
|
|
const result = await page.evaluate(async () => {
|
|
const { engine: mod, catalog } = (window as unknown as { lia: Lia }).lia;
|
|
const engine = new mod.LiaEngine(document.createElement('canvas'), {
|
|
platform: () => ({ y: 200, x0: 100, x1: 700 }),
|
|
onBubble: () => undefined,
|
|
});
|
|
engine.life = false;
|
|
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
engine.start();
|
|
await wait(100);
|
|
const before = engine.position.x;
|
|
engine.play('travel-run', 2);
|
|
await wait(150);
|
|
engine.reducedMotion = true;
|
|
const snapped = engine.position.x;
|
|
await wait(500);
|
|
const settled = engine.position.x;
|
|
engine.stop();
|
|
|
|
const moving: string[] = [];
|
|
for (let i = 0; i < 400; i++) {
|
|
const id = engine.chooseLife(performance.now() + 120_000);
|
|
if (id && catalog.ACTION_BY_ID.get(id)?.moves) {
|
|
moving.push(id);
|
|
}
|
|
}
|
|
return { before, snapped, settled, moving };
|
|
});
|
|
expect(result.snapped).not.toBe(result.before);
|
|
expect(result.settled).toBe(result.snapped);
|
|
expect(result.moving).toEqual([]);
|
|
});
|
|
});
|