component-registry.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * 组件注册表 - 直接使用 catalog.prompt() 运行时生成
  3. */
  4. 'use client';
  5. import { getCatalogPrompt } from './catalog/catalog';
  6. export interface ComponentConfig {
  7. type: string;
  8. description: string;
  9. schema: Record<string, string>;
  10. }
  11. /**
  12. * 获取组件提示词(同步)
  13. * 直接调用 catalog.prompt() 运行时生成
  14. */
  15. export function generateComponentsPrompt(): string {
  16. return getCatalogPrompt();
  17. }
  18. /**
  19. * 异步获取组件提示词(兼容旧代码)
  20. */
  21. export async function getComponentsPromptAsync(): Promise<string> {
  22. return getCatalogPrompt();
  23. }
  24. /**
  25. * 预加载(空操作)
  26. */
  27. export function preloadComponentsPrompt(): void {}
  28. /**
  29. * 清除缓存(空操作)
  30. */
  31. export function invalidateComponentsPromptCache(): void {}
  32. // 组件定义(向后兼容)
  33. export const AVAILABLE_COMPONENTS: Record<string, ComponentConfig> = {
  34. 'translation-result': {
  35. type: 'translation-result',
  36. description: '翻译结果卡片',
  37. schema: { translated: '译文', termsUsed: '术语列表' }
  38. },
  39. 'novel-list': {
  40. type: 'novel-list',
  41. description: '小说列表卡片',
  42. schema: { novels: '小说数组' }
  43. },
  44. 'card': {
  45. type: 'card',
  46. description: '卡片容器',
  47. schema: { title: '标题', children: '子元素' }
  48. },
  49. 'stack': {
  50. type: 'stack',
  51. description: '布局容器',
  52. schema: { direction: '方向', spacing: '间距' }
  53. },
  54. 'heading': {
  55. type: 'heading',
  56. description: '标题',
  57. schema: { text: '文本', level: '级别' }
  58. },
  59. 'text': {
  60. type: 'text',
  61. description: '文本',
  62. schema: { text: '内容' }
  63. },
  64. 'button': {
  65. type: 'button',
  66. description: '按钮',
  67. schema: { label: '文本' }
  68. },
  69. 'badge': {
  70. type: 'badge',
  71. description: '徽章',
  72. schema: { text: '文本' }
  73. },
  74. 'code-block': {
  75. type: 'code-block',
  76. description: '代码块',
  77. schema: { code: '代码', language: '语言' }
  78. },
  79. 'tool-call': {
  80. type: 'tool-call',
  81. description: '工具调用状态',
  82. schema: { toolName: '名称', status: '状态' }
  83. }
  84. };