Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | /** * Pappus character data provider for the admin panel. * * Derives all prompts from the canonical GeometryTeacherConfig to ensure * admin panel shows exactly the same prompts as runtime. */ import { PAPPUS_CHARACTER, PAPPUS_TEACHING_STYLE, PAPPUS_WHAT_NOT_TO_DO, PAPPUS_POINT_LABELING, PAPPUS_HIDDEN_DEPTH, } from '@/components/toys/euclid/pappusCharacter' import { PROP_REGISTRY } from '@/components/toys/euclid/propositions/registry' import { PROPOSITION_SUMMARIES } from '@/components/toys/euclid/agent/euclidReferenceContext' import { TOOL_HANG_UP, TOOL_HIGHLIGHT, TOOL_THINK_HARD } from '@/components/toys/euclid/agent/tools' import { pappusConfig } from '@/components/toys/euclid/characters/pappusConfig' import type { GeometryModeContext } from '@/components/toys/euclid/agent/types' import { splitPromptByKnownBlocks, type KnownBlock, type PromptBreakdown } from '../promptBreakdown' import { getVariantSuffix, type ProfileSize, type ProfileTheme, type ProfileState, } from '../../profile-variants' import type { CharacterSummary, CharacterData, CharacterDataProvider, ProfileVariantPath, } from './index' /** Personality block metadata for the admin panel. */ const PERSONALITY_BLOCKS = [ { key: 'character', label: 'CHARACTER', text: PAPPUS_CHARACTER, sourceFile: 'src/components/toys/euclid/pappusCharacter.ts', sourceExport: 'PAPPUS_CHARACTER', }, { key: 'attitudes.teacher.style', label: 'TEACHING STYLE', text: PAPPUS_TEACHING_STYLE, sourceFile: 'src/components/toys/euclid/pappusCharacter.ts', sourceExport: 'PAPPUS_TEACHING_STYLE', }, { key: 'attitudes.teacher.dontDo', label: 'WHAT NOT TO DO', text: PAPPUS_WHAT_NOT_TO_DO, sourceFile: 'src/components/toys/euclid/pappusCharacter.ts', sourceExport: 'PAPPUS_WHAT_NOT_TO_DO', }, { key: 'pointLabeling', label: 'POINT LABELING', text: PAPPUS_POINT_LABELING, sourceFile: 'src/components/toys/euclid/pappusCharacter.ts', sourceExport: 'PAPPUS_POINT_LABELING', }, { key: 'attitudes.teacher.hiddenDepth', label: 'THE COMPLETENESS QUESTION', text: PAPPUS_HIDDEN_DEPTH, sourceFile: 'src/components/toys/euclid/pappusCharacter.ts', sourceExport: 'PAPPUS_HIDDEN_DEPTH', }, ] as const /** Known blocks used for prompt breakdown. */ const KNOWN_BLOCKS: KnownBlock[] = PERSONALITY_BLOCKS.map((b) => ({ text: b.text, label: b.label, layerId: 'core-personality', layerLabel: 'Core Personality', sourceFile: b.sourceFile, sourceExport: b.sourceExport, })) /** Build a sample GeometryModeContext for prompt generation. */ function buildSampleContext(propositionId: number, step: number): GeometryModeContext { const prop = PROP_REGISTRY[propositionId] const propSummary = PROPOSITION_SUMMARIES[propositionId] const steps = prop?.steps ?? [] const totalSteps = steps.length const currentStep = Math.min(step, totalSteps - 1) return { propositionId, propositionTitle: propSummary?.statement ?? prop?.title ?? `Proposition I.${propositionId}`, propositionKind: (propSummary?.type?.toLowerCase() as 'construction' | 'theorem') ?? 'construction', currentStep: Math.max(0, currentStep), totalSteps, isComplete: false, construction: { elements: [], nextLabelIndex: 0, nextColorIndex: 0 }, proofFacts: [], screenshotDataUrl: null, playgroundMode: false, steps, } } /** Build the prompt breakdown for a voice mode. */ function buildVoiceModeBreakdown( modeId: string, prompt: string, sourceFile: string ): PromptBreakdown { return splitPromptByKnownBlocks(prompt, KNOWN_BLOCKS, { layerId: `voice-${modeId}`, layerLabel: `Voice: ${modeId.charAt(0).toUpperCase() + modeId.slice(1)}`, sourceFile, }) } /** Build the prompt breakdown for text chat. */ function buildChatBreakdown(prompt: string): PromptBreakdown { return splitPromptByKnownBlocks(prompt, KNOWN_BLOCKS, { layerId: 'text-chat', layerLabel: 'Text Chat', sourceFile: 'src/app/api/realtime/euclid/chat/route.ts', }) } /** Available propositions for context selector. */ function getAvailablePropositions(): Array<{ id: number; title: string; type: string }> { return Object.entries(PROPOSITION_SUMMARIES).map(([id, p]) => ({ id: Number(id), title: p.statement, type: p.type, })) } const def = pappusConfig.definition export const pappusProvider: CharacterDataProvider = { id: 'pappus', getSummary(): CharacterSummary { return { id: 'pappus', displayName: def.displayName, nativeDisplayName: def.nativeDisplayName, profileImage: def.profileImage, type: 'historical-figure', } }, getFullData(opts): CharacterData { const propositionId = opts?.propositionId ?? 5 const step = opts?.step ?? 0 const sampleCtx = buildSampleContext(propositionId, step) // Generate prompts from the canonical GeometryTeacherConfig modes const greetingPrompt = pappusConfig.modes.greeting.getInstructions(sampleCtx) const conversingPrompt = pappusConfig.modes.conversing.getInstructions(sampleCtx) const thinkingPrompt = pappusConfig.modes.thinking.getInstructions(sampleCtx) const chatPrompt = pappusConfig.buildChatSystemPrompt({ propositionId, currentStep: step, isComplete: false, playgroundMode: false, constructionGraph: 'Points: A(0,2), B(-2,-1), C(2,-1)\nSegments: AB, AC, BC', toolState: 'No tool selected', proofFacts: 'No facts proven yet.', stepList: sampleCtx.steps .map( (s, i) => `${i === step ? '\u2192' : i < step ? '\u2713' : ' '} Step ${i + 1}: ${s.instruction}` ) .join('\n'), isMobile: false, }) // Build all 18 variant paths from the base profile image (3 sizes × 3 themes × 2 states) const baseImage = def.profileImage const sizes: ProfileSize[] = ['default', 'sm', 'lg'] const themes: ProfileTheme[] = ['default', 'light', 'dark'] const states: ProfileState[] = ['idle', 'speaking'] const profileVariants: ProfileVariantPath[] = sizes.flatMap((size) => themes.flatMap((theme) => states.map((state) => ({ size, theme, state, path: baseImage.replace('.png', `${getVariantSuffix(size, theme, state)}.png`), })) ) ) return { identity: { id: 'pappus', displayName: def.displayName, nativeDisplayName: def.nativeDisplayName, profileImage: def.profileImage, type: 'historical-figure', profilePrompt: [ 'Portrait of Pappus (\u03A0\u03AC\u03C0\u03C0\u03BF\u03C2) of Alexandria, depicted as an iPhone contact profile picture.', 'Circular crop-friendly composition centered on the face/bust.', 'Late Roman-era Greek man, scholarly, warm but serious expression, neatly trimmed grey beard, draped in a simple linen himation.', "Background: warm parchment with faint geometric diagrams — circles, triangles, and construction lines in muted tones, subtly referencing the style of Byrne's illustrated Euclid.", 'Art style: clean illustration, slightly stylized (not photorealistic), warm tones, approachable and scholarly — this is a teacher children will talk to.', 'No text, no labels, no letters. Square 1:1 composition.', ].join(' '), profileVariants, }, voiceConfig: { realtimeVoice: pappusConfig.voice.id, ttsVoice: pappusConfig.voice.ttsVoice ?? pappusConfig.voice.id, baseDurationMs: pappusConfig.voice.baseDurationMs, extensionMs: pappusConfig.voice.extensionMs, sessionEndpoint: pappusConfig.voice.sessionEndpoint, chatEndpoint: pappusConfig.voice.chatEndpoint, thinkHardEndpoint: pappusConfig.voice.thinkHardEndpoint, }, personalityBlocks: PERSONALITY_BLOCKS.map((b) => ({ key: b.key, label: b.label, text: b.text, tokenEstimate: Math.ceil(b.text.length / 4), sourceFile: b.sourceFile, sourceExport: b.sourceExport, })), chatConfig: { placeholder: def.chat.placeholder, emptyPrompt: def.chat.emptyPrompt, streamingLabel: def.chat.streamingLabel, sourceFile: 'src/components/toys/euclid/pappusCharacterDef.ts', }, modes: { greeting: { id: 'greeting', label: 'Greeting', trigger: 'Call established', exit: 'Student speaks \u2192 onResponseDone \u2192 transition to conversing', tools: ['hang_up'], prompt: greetingPrompt, promptBreakdown: buildVoiceModeBreakdown( 'greeting', greetingPrompt, 'src/components/toys/euclid/agent/modes/greetingMode.ts' ), sourceFile: 'src/components/toys/euclid/agent/modes/greetingMode.ts', }, conversing: { id: 'conversing', label: 'Conversing', trigger: 'Greeting complete + student spoke', exit: 'None (temporarily enters thinking via think_hard tool)', tools: ['highlight', 'think_hard', 'hang_up'], prompt: conversingPrompt, promptBreakdown: buildVoiceModeBreakdown( 'conversing', conversingPrompt, 'src/components/toys/euclid/agent/modes/conversingMode.ts' ), sourceFile: 'src/components/toys/euclid/agent/modes/conversingMode.ts', }, thinking: { id: 'thinking', label: 'Thinking', trigger: 'think_hard tool called', exit: 'Async result \u2192 system message + auto-exit to conversing', tools: ['hang_up'], prompt: thinkingPrompt, promptBreakdown: buildVoiceModeBreakdown( 'thinking', thinkingPrompt, 'src/components/toys/euclid/agent/modes/thinkingMode.ts' ), sourceFile: 'src/components/toys/euclid/agent/modes/thinkingMode.ts', }, chat: { id: 'chat', label: 'Text Chat', trigger: 'User opens chat panel', exit: 'N/A \u2014 always available', tools: [], prompt: chatPrompt, promptBreakdown: buildChatBreakdown(chatPrompt), sourceFile: 'src/app/api/realtime/euclid/chat/route.ts', api: 'gpt-5.2 Responses API', }, }, modeTransitions: [ { from: 'greeting', to: 'conversing', trigger: 'Student speaks' }, { from: 'conversing', to: 'thinking', trigger: 'think_hard tool called' }, { from: 'thinking', to: 'conversing', trigger: 'Async result arrives' }, ], tools: [ { name: TOOL_HIGHLIGHT.name, description: TOOL_HIGHLIGHT.description, parameters: TOOL_HIGHLIGHT.parameters, modes: ['conversing'], behavior: 'Golden glow on canvas entity, 4s auto-clear', promptResponse: false, }, { name: TOOL_THINK_HARD.name, description: TOOL_THINK_HARD.description, parameters: TOOL_THINK_HARD.parameters, modes: ['conversing'], behavior: 'Async: screenshot + proof state \u2192 POST \u2192 enterMode: thinking \u2192 asyncResult \u2192 auto-exit', promptResponse: true, }, { name: TOOL_HANG_UP.name, description: TOOL_HANG_UP.description, parameters: TOOL_HANG_UP.parameters, modes: ['greeting', 'conversing', 'thinking'], behavior: 'isHangUp: true \u2192 wait for audio \u2192 cleanup', promptResponse: true, }, ], availablePropositions: getAvailablePropositions(), currentPropositionId: propositionId, currentStep: step, } }, } |