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 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | /** * All tool definitions for the OpenAI Realtime API, extracted from route.ts. * * Static tools are exported as constants; context-dependent tools are factories. * Composed sets group tools by session mode. */ import type { RealtimeTool, ModeContext } from './types' import { AVAILABLE_EXPLORATIONS } from '../explorationRegistry' import { GAME_IDS, getGameToolDescription } from '../gameRegistry' // ── Static tools ──────────────────────────────────────────────────────────── export const TOOL_HANG_UP: RealtimeTool = { type: 'function', name: 'hang_up', description: 'End the phone call. You MUST say a clear, warm goodbye to the child BEFORE calling this — never hang up silently. Say something like "It was great talking to you! Bye!" in character, THEN call this tool. The child needs closure.', parameters: { type: 'object', properties: {} }, } export const TOOL_LOOK_AT: RealtimeTool = { type: 'function', name: 'look_at', description: 'Pan and zoom the number line to show a specific region. The child sees the number line animate smoothly to the new view. Use this whenever you\'re talking about a specific number or region — e.g. "let me show you where I live", "look over at 100", "let\'s zoom out and see the big picture". You control what the child sees.', parameters: { type: 'object', properties: { center: { type: 'number', description: 'The number to center the view on', }, range: { type: 'number', description: 'How wide a range to show (in number-line units). E.g. range=10 shows roughly 5 units on each side of center. Default: 20. Use small values (2-5) to zoom in close, large values (50-1000) to zoom out.', }, }, required: ['center'], }, } export const TOOL_INDICATE: RealtimeTool = { type: 'function', name: 'indicate', description: 'Highlight specific numbers or a range on the number line with a temporary glowing visual indicator. Use this to point things out — "see these primes?", "this whole area here", "look, I live right here". IMPORTANT: If the numbers or range you want to highlight are outside what the child can currently see, call look_at FIRST to navigate there, THEN call indicate — otherwise the highlight will be invisible. You can control how long the highlight stays visible with duration_seconds.', parameters: { type: 'object', properties: { numbers: { type: 'array', items: { type: 'number' }, description: 'Specific numbers to highlight with glowing dots on the number line', }, range: { type: 'object', properties: { from: { type: 'number', description: 'Start of the range to highlight' }, to: { type: 'number', description: 'End of the range to highlight' }, }, required: ['from', 'to'], description: 'A range to highlight as a shaded band on the number line', }, duration_seconds: { type: 'number', description: 'How long the highlight stays visible (default 4). Use longer durations (8-15) when explaining something about the highlighted region, shorter (2-3) for quick "look here" moments. Ignored when persistent is true.', }, persistent: { type: 'boolean', description: 'When true, the highlight stays visible until replaced by another indicate call or the game ends. Use this during games to show persistent state (e.g. remaining stones in Nim).', }, }, }, } export const TOOL_EVOLVE_STORY: RealtimeTool = { type: 'function', name: 'evolve_story', description: "Call this PROACTIVELY to get a fresh story development. Do NOT wait for awkward silence — call it after 4-6 exchanges when the initial topic is settling, when the child gives a short answer, when you feel the conversation could use a new thread, or during any natural breath. Call it even when things are going okay — fresh material keeps the conversation engaging. The only bad time to call this is in the middle of a rapid back-and-forth exchange. You'll get back a development, a new tension, and a suggestion to weave in naturally.", parameters: { type: 'object', properties: {} }, } export const TOOL_TRANSFER_CALL: RealtimeTool = { type: 'function', name: 'transfer_call', description: 'Transfer the phone call to another number. Use this when the child asks to talk to a different number (e.g. "can I talk to 7?"). Say something like "Sure, let me transfer you!" then call this tool.', parameters: { type: 'object', properties: { target_number: { type: 'number', description: 'The number to transfer the call to', }, }, required: ['target_number'], }, } export const TOOL_ADD_TO_CALL: RealtimeTool = { type: 'function', name: 'add_to_call', description: 'Add one or more numbers to the current call as a conference/group call. Use this when the child wants multiple numbers talking together (e.g. "can 12 join us?", "add 5 and 7 to the call", "let\'s get 3, 8, and 12 on here"). Always pass ALL requested numbers in a single call. After calling this, you will play multiple characters.', parameters: { type: 'object', properties: { target_numbers: { type: 'array', items: { type: 'number' }, description: 'The numbers to add to the conference call', }, }, required: ['target_numbers'], }, } export const TOOL_SWITCH_SPEAKER: RealtimeTool = { type: 'function', name: 'switch_speaker', description: 'Switch which number character you are speaking as during a conference call. Call this BEFORE speaking as a different number — it updates the visual indicator showing the child who is talking. NEVER start speaking as a different character without calling this first. The child sees which number is talking on screen, and it MUST match what you say.', parameters: { type: 'object', properties: { number: { type: 'number', description: 'The number to speak as (must be on the current call)', }, }, required: ['number'], }, } export const TOOL_START_EXPLORATION: RealtimeTool = { type: 'function', name: 'start_exploration', description: `Launch an animated visual exploration on the number line. For constant explorations (phi, pi, tau, e, gamma, sqrt2, ramanujan): the animation starts PAUSED — introduce the constant to the child first, then call resume_exploration when ready. A pre-recorded narrator handles the narration. Stay quiet during playback. For tour explorations (primes): you will need to hang up first — the tour launches automatically after the call ends. Explain the tour to the child, say goodbye warmly, invite them to call back after watching, then call hang_up. Available explorations: ${AVAILABLE_EXPLORATIONS.map((e) => `${e.id} (${e.name})`).join(', ')}.`, parameters: { type: 'object', properties: { constant_id: { type: 'string', enum: AVAILABLE_EXPLORATIONS.map((e) => e.id), description: 'Which exploration to launch', }, }, required: ['constant_id'], }, } export const TOOL_PAUSE_EXPLORATION: RealtimeTool = { type: 'function', name: 'pause_exploration', description: 'Pause the currently playing exploration animation. The animation also pauses automatically when the child speaks. Use this for deliberate pauses when you want to highlight something or linger on an interesting moment.', parameters: { type: 'object', properties: {} }, } export const TOOL_RESUME_EXPLORATION: RealtimeTool = { type: 'function', name: 'resume_exploration', description: "Resume the exploration animation from where it was paused. Call this after you've answered the child's question and they're ready to continue watching.", parameters: { type: 'object', properties: {} }, } export const TOOL_SEEK_EXPLORATION: RealtimeTool = { type: 'function', name: 'seek_exploration', description: 'Jump the exploration animation to a specific segment by number (1-indexed, matching the script you received). The animation pauses at that segment so you can discuss it. Use this when the child asks to see a specific part again, e.g. "show me the part about the spiral" — find the matching segment number from the script and seek to it.', parameters: { type: 'object', properties: { segment_number: { type: 'number', description: 'Which segment to jump to (1-indexed)', }, }, required: ['segment_number'], }, } export const TOOL_SET_NUMBER_LINE_STYLE: RealtimeTool = { type: 'function', name: 'set_number_line_style', description: 'Adjust the visual style of number labels on the number line. Use this to make labels larger and more visible when playing games or when the current zoom makes labels hard to read.', parameters: { type: 'object', properties: { label_scale: { type: 'number', description: 'Font size multiplier for labels (0.5–3, default 1). Use 1.5–2 to make labels clearly readable at wide zoom levels.', }, label_min_opacity: { type: 'number', description: 'Minimum opacity for all labels (0–1, default 0). Set to 0.8–1.0 to make even small numbers fully visible.', }, }, }, } export const TOOL_END_EXPLORATION: RealtimeTool = { type: 'function', name: 'end_exploration', description: 'Stop the current exploration and return to conversation. Use this when the child wants to stop watching and do something else — play a game, talk, etc.', parameters: { type: 'object', properties: {} }, } export const TOOL_END_GAME: RealtimeTool = { type: 'function', name: 'end_game', description: 'End the current game and return to open play.', parameters: { type: 'object', properties: {} }, } export const TOOL_MARK_MOMENT: RealtimeTool = { type: 'function', name: 'mark_moment', description: 'Silently bookmark a memorable moment. NEVER acknowledge, reference, or hint that you are doing this — no "let me remember this", no "that was special", no change in tone. The child must have ZERO awareness that bookmarking exists. Just call it and keep talking normally. Use whenever something noteworthy happens. Aim for 5-10 per call.', parameters: { type: 'object', properties: { caption: { type: 'string', description: 'Brief description of the moment (1 sentence)', }, category: { type: 'string', enum: ['question', 'discovery', 'game', 'exploration', 'conversation', 'conference'], description: 'What kind of moment this is', }, significance: { type: 'number', description: 'How memorable is this moment, 1-10', }, }, required: ['caption', 'category', 'significance'], }, } export const TOOL_SEND_POSTCARD: RealtimeTool = { type: 'function', name: 'send_postcard', description: 'Send the child a postcard from this call. Only call after getting their consent. The postcard will be generated from the memorable moments you marked during the call.', parameters: { type: 'object', properties: { session_summary: { type: 'string', description: 'Brief 1-2 sentence summary of the call from your perspective', }, }, required: ['session_summary'], }, } export const TOOL_REQUEST_MORE_TIME: RealtimeTool = { type: 'function', name: 'request_more_time', description: 'Call this when the conversation is going great and you want more time to keep talking. IMPORTANT: Do NOT mention the time extension to the child. Just keep talking naturally as if nothing happened.', parameters: { type: 'object', properties: {} }, } // ── Factory tools (context-dependent) ─────────────────────────────────────── export function makeIdentifyCallerTool( players: Array<{ id: string; name: string; emoji: string }> ): RealtimeTool { const nameList = players.map((p) => p.name).join(', ') return { type: 'function', name: 'identify_caller', description: `Call this when you learn a child's name, or when a different child takes over the phone. ` + `Pass your best guess of the name — it will be fuzzy-matched. Don't hesitate to call this even if you're not 100% sure of the spelling. ` + `Known names: ${nameList}. ` + `You can call this again anytime a different kid takes over.`, parameters: { type: 'object', properties: { name: { type: 'string', description: 'The name the child said (your best guess — fuzzy matching will handle misspellings)', }, }, required: ['name'], }, } } export function makeStartGameTool(): RealtimeTool { return { type: 'function', name: 'start_game', description: getGameToolDescription(), parameters: { type: 'object', properties: { game_id: { type: 'string', enum: GAME_IDS, description: 'Which game to start', }, target: { type: 'number', description: 'For find_number: the target number to find. For race: the target to reach (default 21).', }, min: { type: 'number', description: 'For guess_my_number: lower bound of the range (default 1).', }, max: { type: 'number', description: 'For guess_my_number: upper bound of the range (default 100).', }, stones: { type: 'number', description: 'For nim/poison: total number of stones (default 15). Must be a positive integer.', }, max_take: { type: 'number', description: 'For nim/poison: maximum stones a player can take per turn (default 3). Must be a positive integer.', }, max_add: { type: 'number', description: 'For race: maximum a player can add per turn (default 3). Must be a positive integer.', }, }, required: ['game_id'], }, } } // ── Composed tool sets per mode ───────────────────────────────────────────── export function getAnsweringTools(): RealtimeTool[] { return [TOOL_LOOK_AT, TOOL_HANG_UP] } export function getFamiliarizingTools(ctx: ModeContext): RealtimeTool[] { const tools: RealtimeTool[] = [TOOL_LOOK_AT, TOOL_INDICATE, TOOL_HANG_UP] if (ctx.availablePlayers.length > 0) { tools.unshift(makeIdentifyCallerTool(ctx.availablePlayers)) } return tools } export function getDefaultTools(ctx: ModeContext): RealtimeTool[] { const tools: RealtimeTool[] = [] // Always include identify_caller when players are available (allows mid-call switching) if (ctx.availablePlayers.length > 0) { tools.push(makeIdentifyCallerTool(ctx.availablePlayers)) } tools.push( TOOL_REQUEST_MORE_TIME, TOOL_HANG_UP, TOOL_TRANSFER_CALL, TOOL_ADD_TO_CALL, TOOL_START_EXPLORATION, TOOL_LOOK_AT, TOOL_EVOLVE_STORY, makeStartGameTool(), TOOL_SET_NUMBER_LINE_STYLE, TOOL_INDICATE, TOOL_MARK_MOMENT ) return tools } export function getConferenceTools(): RealtimeTool[] { return [ TOOL_SWITCH_SPEAKER, TOOL_ADD_TO_CALL, TOOL_LOOK_AT, TOOL_INDICATE, TOOL_EVOLVE_STORY, TOOL_START_EXPLORATION, makeStartGameTool(), TOOL_HANG_UP, TOOL_REQUEST_MORE_TIME, TOOL_SET_NUMBER_LINE_STYLE, TOOL_MARK_MOMENT, ] } export function getExplorationTools(): RealtimeTool[] { return [ TOOL_PAUSE_EXPLORATION, TOOL_RESUME_EXPLORATION, TOOL_SEEK_EXPLORATION, TOOL_END_EXPLORATION, TOOL_HANG_UP, ] } export function getHangingUpTools(): RealtimeTool[] { return [TOOL_HANG_UP] } |