wyuc cec3c6aaea
Refactor widget actions into the scene action pipeline (#796)
* refactor: align widget actions with scene pipeline

* feat(edit): migrate legacy teacherActions off interactive content on load

The widget-actions pipeline no longer persists a teacherActions authoring
layer; playback reads only scene.actions. Add migrateInteractiveContent to
strip the dead field from existing documents as they load through migrateScene
(wired into all store/classroom load paths). Satisfies the #794 forward-migration
acceptance item.

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

* fix(generation): default widget_setState.state to {} when the LLM omits it

The removed TeacherAction->Action converter always defaulted state to {}.
Restore that guard in the structured-output parser so an action missing
state can't forward state: undefined into the widget iframe, where
SET_WIDGET_STATE handlers dereference it.

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

* fix(edit): also strip nested widgetConfig.teacherActions in migration

Legacy WidgetConfig variants each declared their own teacherActions, so existing
documents can carry the dead field nested inside content.widgetConfig as well as
at the top level. Extend migrateInteractiveContent to drop both, preserving all
other widgetConfig fields.

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

* feat(prompts): document stable widget-action selectors for diagram/game/viz3d

The interactive-actions prompt documented stable target selectors only for
procedural-skill and simulation widgets. Add the canonical selectors the
diagram / game / visualization3d content prompts actually emit (node IDs via
revealOrder; #zoom-in-btn / #canvas-container / #speed-slider / ...; #start-btn),
plus a rule to use widget_setState or a speech-only beat instead of guessing a
target when no stable selector is known (e.g. free-form code widgets). Hardens
against widget actions silently no-oping on non-existent selectors.

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

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: 杨慎 <117187635+cosarah@users.noreply.github.com>
2026-06-28 21:13:21 +08:00

213 lines
4.8 KiB
TypeScript

/**
* Widget Configuration Types for Ultra Interaction Mode
*/
// ==================== Base Types ====================
export type WidgetType =
| 'simulation'
| 'diagram'
| 'code'
| 'game'
| 'visualization3d'
| 'procedural-skill';
// ==================== 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>;
}>;
}
// ==================== 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
}
// ==================== 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;
}
// ==================== 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;
}>;
}
// ==================== 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>;
}>;
}
// ==================== Procedural Skill Widget ====================
export interface ProceduralSkillStep {
id: string;
title: string;
description: string;
tools?: string[];
successCriteria?: string[];
}
export interface ProceduralSkillConfig {
type: 'procedural-skill';
task: string;
description: string;
tools?: string[];
steps: ProceduralSkillStep[];
successCriteria?: string[];
}
// ==================== Union Types ====================
export type WidgetConfig =
| SimulationConfig
| DiagramConfig
| CodeConfig
| GameConfig
| Visualization3DConfig
| ProceduralSkillConfig;