channel-format-hints.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * Per-platform response formatting hints for inbound context injection.
  3. *
  4. * These are injected into the model's system-level context so it knows
  5. * how to format responses for the target platform.
  6. */
  7. import type { ChannelPlatform } from './channel-route.js';
  8. export interface ResponseFormatHint {
  9. /** Markup language the platform supports. */
  10. text_markup: string;
  11. /** Formatting rules the model should follow. */
  12. rules: string[];
  13. }
  14. const FEISHU_FORMAT: ResponseFormatHint = {
  15. text_markup: 'markdown_subset',
  16. rules: [
  17. 'Use plain text or basic markdown (bold, italic, code blocks, lists).',
  18. 'Feishu does not render full HTML or advanced markdown tables.',
  19. 'Keep messages concise — long messages are hard to read in chat.',
  20. 'Use code blocks with language tags for code snippets.',
  21. 'Avoid inline images or complex formatting.',
  22. ],
  23. };
  24. const TELEGRAM_FORMAT: ResponseFormatHint = {
  25. text_markup: 'telegram_markdown_v2',
  26. rules: [
  27. 'Use Telegram MarkdownV2 formatting.',
  28. 'Escape special characters: _ * [ ] ( ) ~ ` > # + - = | { } . !',
  29. 'Use ``` for code blocks (no language tag support in some clients).',
  30. 'Keep messages under 4096 characters (Telegram limit).',
  31. 'Avoid nested formatting (bold inside italic, etc.).',
  32. ],
  33. };
  34. const FORMAT_HINTS: Partial<Record<ChannelPlatform, ResponseFormatHint>> = {
  35. feishu: FEISHU_FORMAT,
  36. telegram: TELEGRAM_FORMAT,
  37. };
  38. /**
  39. * Get response format hints for a platform.
  40. * Returns undefined for platforms without specific formatting needs (e.g. 'api').
  41. */
  42. export function getResponseFormatHint(platform: ChannelPlatform): ResponseFormatHint | undefined {
  43. return FORMAT_HINTS[platform];
  44. }