tool-schemas.ts 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Action Schemas for Stateless Generation
  3. *
  4. * Text descriptions of actions for inclusion in structured output prompts.
  5. * Actions are parsed from JSON array items in the model's response.
  6. */
  7. import { SLIDE_ONLY_ACTIONS } from '@/lib/types/action';
  8. // ==================== Effective Actions ====================
  9. /**
  10. * Filter allowed actions by scene type.
  11. * Slide-only actions (spotlight, laser) are removed for non-slide scenes.
  12. */
  13. export function getEffectiveActions(allowedActions: string[], sceneType?: string): string[] {
  14. if (!sceneType || sceneType === 'slide') return allowedActions;
  15. return allowedActions.filter(
  16. (a) => !SLIDE_ONLY_ACTIONS.includes(a as (typeof SLIDE_ONLY_ACTIONS)[number]),
  17. );
  18. }
  19. // ==================== Text Descriptions ====================
  20. /**
  21. * Get text descriptions of allowed actions for inclusion in system prompts.
  22. * Used when the model generates structured output with JSON array format.
  23. */
  24. export function getActionDescriptions(allowedActions: string[]): string {
  25. const descriptions: Record<string, string> = {
  26. spotlight:
  27. 'Focus attention on a single key element by dimming everything else. Use sparingly — max 1-2 per response. Parameters: { elementId: string, dimOpacity?: number }',
  28. laser:
  29. 'Point at an element with a laser pointer effect. Parameters: { elementId: string, color?: string }',
  30. wb_open:
  31. 'Open the whiteboard for hand-drawn explanations, formulas, diagrams, or step-by-step derivations. Creates a new whiteboard if none exists. Call this before adding elements. Parameters: {}',
  32. wb_draw_text:
  33. 'Add text to the whiteboard. Use for writing formulas, steps, or key points. Parameters: { content: string, x: number, y: number, width?: number, height?: number, fontSize?: number, color?: string, elementId?: string }',
  34. wb_draw_shape:
  35. 'Add a shape to the whiteboard. Use for diagrams and visual explanations. Parameters: { shape: "rectangle"|"circle"|"triangle", x: number, y: number, width: number, height: number, fillColor?: string, elementId?: string }',
  36. wb_draw_chart:
  37. 'Add a chart to the whiteboard. Use for data visualization (bar charts, line graphs, pie charts, etc.). Parameters: { chartType: "bar"|"column"|"line"|"pie"|"ring"|"area"|"radar"|"scatter", x: number, y: number, width: number, height: number, data: { labels: string[], legends: string[], series: number[][] }, themeColors?: string[], elementId?: string }',
  38. wb_draw_latex:
  39. 'Add a LaTeX formula to the whiteboard. Use for mathematical equations and scientific notation. Parameters: { latex: string, x: number, y: number, width?: number, height?: number, color?: string, elementId?: string }',
  40. wb_draw_table:
  41. 'Add a table to the whiteboard. Use for structured data display and comparisons. Parameters: { x: number, y: number, width: number, height: number, data: string[][] (first row is header), outline?: { width: number, style: string, color: string }, theme?: { color: string }, elementId?: string }',
  42. wb_draw_line:
  43. 'Add a line or arrow to the whiteboard. Use for connecting elements, drawing relationships, flow diagrams, or annotations. Parameters: { startX: number, startY: number, endX: number, endY: number, color?: string (default "#333333"), width?: number (line thickness, default 2), style?: "solid"|"dashed" (default "solid"), points?: [startMarker, endMarker] where marker is ""|"arrow" (default ["",""]), elementId?: string }',
  44. wb_clear:
  45. 'Clear all elements from the whiteboard. Use when whiteboard is too crowded before adding new elements. Parameters: {}',
  46. wb_delete:
  47. 'Delete a specific element from the whiteboard by its ID. Use to remove an outdated, incorrect, or overlapping element without clearing the entire board. Parameters: { elementId: string }',
  48. wb_close:
  49. 'Close the whiteboard and return to the slide view. Always close after you finish drawing. Parameters: {}',
  50. play_video:
  51. 'Start playback of a video element on the current slide. Synchronous — blocks until the video finishes playing. Use a speech action before this to introduce the video. Parameters: { elementId: string }',
  52. };
  53. if (allowedActions.length === 0) {
  54. return 'You have no actions available. You can only speak to students.';
  55. }
  56. const lines = allowedActions
  57. .filter((action) => descriptions[action])
  58. .map((action) => `- ${action}: ${descriptions[action]}`);
  59. return lines.join('\n');
  60. }