Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
feat(chat): a slot where the next generated-UI element lands
trohitg03d681da7096
diff --git a/client/src/features/chat/__tests__/chatUi.test.tsx b/client/src/features/chat/__tests__/chatUi.test.tsxnew file mode 100644index 00000000..c817452e--- /dev/null+++ b/client/src/features/chat/__tests__/chatUi.test.tsx@@ -0,0 +1,57 @@+/**+ * A generated interface arriving in a reply (genui/ChatUi.tsx): while the run+ * streams it, a dashed slot below the elements shown so far stands for the+ * ones still to come, and goes once the last has risen in; one read back+ * later, or under reduced motion, shows whole, with no slot.+ */++import { readFileSync } from 'node:fs';+import { join } from 'node:path';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { act, render } from '@testing-library/react';+import { REVEAL_STEP_MS } from '@/lib/jsonRender';+import { setReducedMotion } from '@/test/waapi';+import ChatUi from '../genui/ChatUi';++const SPEC = JSON.parse(readFileSync(join(__dirname, '..', '__fixtures__', 'saturday-booking.spec.json'), 'utf-8'));+const ACTIONS = { ask: vi.fn(), event: vi.fn() };++function slot(container: HTMLElement) {+ return container.querySelector('[data-slot="next"]');+}++describe('ChatUi', () => {+ let restoreMotion: () => void;++ beforeEach(() => {+ restoreMotion = setReducedMotion(false);+ vi.useFakeTimers({ toFake: ['setInterval', 'clearInterval', 'performance'] });+ });++ afterEach(() => {+ vi.useRealTimers();+ restoreMotion();+ });++ it('keeps a slot for what is still arriving', () => {+ const { container } = render(<ChatUi partId="ui_1" spec={SPEC} live actions={ACTIONS} />);+ expect(slot(container)).not.toBeNull();+ expect(slot(container)?.getAttribute('aria-hidden')).toBe('true');+ act(() => {+ vi.advanceTimersByTime(REVEAL_STEP_MS * 60);+ });+ expect(slot(container)).toBeNull();+ });++ it('shows a reply read back later whole', () => {+ const { container } = render(<ChatUi partId="ui_1" spec={SPEC} live={false} actions={ACTIONS} />);+ expect(slot(container)).toBeNull();+ });++ it('shows everything at once under reduced motion', () => {+ restoreMotion();+ restoreMotion = setReducedMotion(true);+ const { container } = render(<ChatUi partId="ui_1" spec={SPEC} live actions={ACTIONS} />);+ expect(slot(container)).toBeNull();+ });+});diff --git a/client/src/features/chat/genui/ChatUi.tsx b/client/src/features/chat/genui/ChatUi.tsxindex 8a0ec75a..03c73e7b 100644--- a/client/src/features/chat/genui/ChatUi.tsx+++ b/client/src/features/chat/genui/ChatUi.tsx@@ -6,9 +6,10 @@** - **Arriving.** While the run streams it (`live`), the elements appear one* at a time (REVEAL_STEP_MS each, all at once under reduced motion or on a- * hidden page) and each rises in once. The count only moves forward, so- * patches that land in several bursts never restart it. A UI read back- * later shows at once, without motion.+ * hidden page) and each rises in once, a dashed slot below them standing+ * for the ones still to come. The count only moves forward, so patches+ * that land in several bursts never restart it. A UI read back later shows+ * at once, without motion.* - **State.** It keeps its own state store (lib/jsonRender/uiState.ts),* seeded from what the owner last set (`state`) or the spec's own, and* reports every change to `onStateChange`.@@ -82,6 +83,9 @@ function ChatUiBody({ partId, spec, state, live, actions, onStateChange }: Omit<<LiveUiContext.Provider value={live}><JSONUIProvider registry={chatRegistry} store={store} handlers={handlers}><Renderer spec={shown} registry={chatRegistry} loading={count < total} fallback={NoElement} />+ {count < total && (+ <div aria-hidden data-slot="next" className="opencompany-shimmer-slot h-9 rounded-xl border border-dashed border-border-default" />+ )}</JSONUIProvider></LiveUiContext.Provider>);