Shangqing Tu c02a607377
feat: interactive mode clean (#461)
* feat: add interactive mode

* feat: add TeacherActions for interactive mode

* fix: better prompt for ultra mode

* feat: upgrade normal mode's interactive generation with 5 widget type and actions

* feat: make interactive mode button clear

* fix: remove unused TeacherOverlay

* fix: resolve PR #458 review feedback

- Revert unrelated infra changes (Dockerfile, docker-compose.yml)
- Fix placeholder strings in generateWidgetContent
- Rename ultraMode to interactiveMode consistently across codebase
- Extract duplicated patchHtmlForIframe to shared utility
- Fix widget store race condition by keying callbacks by sceneId
- Fix teacher-action ID collisions by using descriptive IDs in prompt
- Relax outline prompt constraints for flexibility
- Optimize sidebar thumbnail with IntersectionObserver lazy loading
- Add trailing newlines to modified files

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix: update generateSceneActions call signatures

The function signature changed to individual parameters instead of
options object pattern after cherry-pick.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* style: fix prettier formatting

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix: removed extra language arg

* style: fix prettier formatting v2

* fix:  add missing i18n keys

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-19 21:35:30 +08:00

201 lines
4.9 KiB
TypeScript

/**
* Widget Configuration Types for Ultra Interaction Mode
*/
// ==================== Base Types ====================
export type WidgetType = 'simulation' | 'diagram' | 'code' | 'game' | 'visualization3d';
export interface TeacherAction {
id: string;
type: 'speech' | 'highlight' | 'annotation' | 'reveal' | 'setState';
target?: string; // Element ID or selector to highlight/annotate
content?: string; // Speech text or annotation text
state?: Record<string, unknown>; // Widget state to set
label?: string; // Short label for UI button (e.g., "Next", "Try This")
}
// ==================== Simulation Widget ====================
export interface SimulationVariable {
name: string;
label: string;
min: number;
max: number;
default: number;
unit?: string;
step?: number;
}
export interface SimulationConfig {
type: 'simulation';
concept: string;
description: string;
variables: SimulationVariable[];
presets?: Array<{
name: string;
variables: Record<string, number>;
}>;
teacherActions?: TeacherAction[];
}
// ==================== Diagram Widget ====================
export interface DiagramNode {
id: string;
label: string;
position?: { x: number; y: number };
details?: string;
type?: 'default' | 'decision' | 'start' | 'end';
}
export interface DiagramEdge {
id: string;
from: string;
to: string;
label?: string;
}
export interface DiagramConfig {
type: 'diagram';
diagramType: 'flowchart' | 'mindmap' | 'hierarchy' | 'system';
description: string;
nodes: DiagramNode[];
edges: DiagramEdge[];
revealOrder?: string[]; // Node IDs in reveal sequence
teacherActions?: TeacherAction[];
}
// ==================== Code Widget ====================
export interface CodeTestCase {
id: string;
input: string;
expected: string;
description?: string;
isHidden?: boolean;
}
export interface CodeConfig {
type: 'code';
language: 'python' | 'javascript' | 'typescript' | 'java' | 'cpp';
description: string;
starterCode: string;
testCases: CodeTestCase[];
hints: string[];
solution: string;
teacherActions?: TeacherAction[];
}
// ==================== Game Widget ====================
export interface GameQuestion {
id: string;
question: string;
type: 'single' | 'multiple';
options: string[];
correct: number | number[];
explanation?: string;
points?: number;
}
export interface GameConfig {
type: 'game';
gameType: 'quiz' | 'puzzle' | 'strategy' | 'card';
description: string;
questions?: GameQuestion[];
scoring: {
correctPoints: number;
speedBonus?: number;
comboMultiplier?: number;
penalty?: number;
};
achievements?: Array<{
id: string;
name: string;
description: string;
icon: string;
condition: string;
}>;
teacherActions?: TeacherAction[];
}
// ==================== 3D Visualization Widget ====================
export interface Visualization3DObject {
id: string;
type: 'sphere' | 'box' | 'cylinder' | 'cone' | 'torus' | 'plane' | 'custom';
name?: string;
position?: { x: number; y: number; z: number };
rotation?: { x: number; y: number; z: number };
scale?: number | { x: number; y: number; z: number };
material?: {
type: 'basic' | 'lambert' | 'phong' | 'standard' | 'emissive';
color?: string;
emissive?: string;
wireframe?: boolean;
transparent?: boolean;
opacity?: number;
};
// For animated objects
animation?: {
type: 'orbit' | 'rotate' | 'bounce' | 'pulse';
speed?: number;
axis?: 'x' | 'y' | 'z';
};
// For hierarchical objects
children?: Visualization3DObject[];
}
export interface Visualization3DInteraction {
type: 'orbit' | 'zoom' | 'pan' | 'slider' | 'button' | 'toggle';
target?: string; // Object ID or 'camera'
label?: string;
param?: string;
min?: number;
max?: number;
default?: number;
step?: number;
}
export interface Visualization3DConfig {
type: 'visualization3d';
visualizationType: 'molecular' | 'solar' | 'anatomy' | 'geometry' | 'physics' | 'custom';
description: string;
objects: Visualization3DObject[];
interactions?: Visualization3DInteraction[];
camera?: {
position?: { x: number; y: number; z: number };
target?: { x: number; y: number; z: number };
fov?: number;
};
lighting?: {
ambient?: { color?: string; intensity?: number };
directional?: Array<{
color?: string;
intensity?: number;
position?: { x: number; y: number; z: number };
}>;
point?: Array<{
color?: string;
intensity?: number;
position?: { x: number; y: number; z: number };
}>;
};
presets?: Array<{
name: string;
description?: string;
state: Record<string, unknown>;
}>;
teacherActions?: TeacherAction[];
}
// ==================== Union Types ====================
export type WidgetConfig =
| SimulationConfig
| DiagramConfig
| CodeConfig
| GameConfig
| Visualization3DConfig;