{"version":3,"file":"AIUIRenderer.mjs","names":[],"sources":["../../../../../src/plugins/AIComponents/GenerativeUI/AIUIRenderer.ts"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport type { AIUIComponent } from './AIUIComponent';\nimport type { AIUIDocument, AIUIFormat } from './AIUIDocument';\nimport type { AIUIHost } from './AIUIHost';\nimport type { AIUIClientToolDefinition } from './AIUITools';\n\n/**\n * Shows the documents of one conversation in a renderer's format. A host makes one per\n * renderer, the first time the renderer receives or shows something, and keeps it as long as\n * the host lives, so what a reply's UI holds, such as a form's values, survives scrolling. The\n * counterpart of `AIUIEngine` in StreamChatAI.\n */\nexport type AIUIEngine = {\n  /**\n   * The view of a reply's document, or `null` when it shows nothing of its own, such as a reply\n   * that only changed an earlier one's UI, so the reply's text shows. It is called while the\n   * conversation renders, so keep what it makes for a reply and return it again.\n   */\n  view: (document: AIUIDocument, messageId: string) => ReactNode | null;\n  /**\n   * Takes a reply's document as it arrives or changes, oldest reply first, whether or not the\n   * reply is on screen, so a format whose later replies change an earlier one's UI can follow\n   * them all. It comes while the conversation renders, before any reply's view is asked for:\n   * change what is already on screen afterwards, such as in a microtask.\n   */\n  receive?: (document: AIUIDocument, messageId: string) => void;\n  /**\n   * Forgets a reply that left the conversation, or whose UI did, such as one that was deleted,\n   * so the engine can let go of what it kept for it.\n   */\n  remove?: (messageId: string) => void;\n};\n\n/**\n * Reads one format of generated UI, such as A2UI. A plug-in of `AIUIHost`: the AI components\n * know no format themselves. The counterpart of `AIUIRenderer` in StreamChatAI.\n */\nexport type AIUIRenderer = {\n  /** Makes what shows the documents of one conversation. */\n  createEngine: (host: AIUIHost) => AIUIEngine;\n  /** The format it reads. */\n  format: AIUIFormat;\n  /**\n   * What the agent's backend needs to have its model write UI this renderer shows with\n   * `components` and calls the app's `tools` from, such as the model's instructions, which may\n   * take loading the format's packages to write. None by default.\n   */\n  capabilities?: (\n    components: AIUIComponent[],\n    tools: AIUIClientToolDefinition[],\n  ) => Record<string, unknown> | Promise<Record<string, unknown>>;\n  /** Whether it reads documents of `version`, or of no version. Every version by default. */\n  supports?: (version: string | undefined) => boolean;\n};\n\n/** Whether `renderer` reads `document`: its format, in a version it supports. */\nexport const aiUIRendererReads = (renderer: AIUIRenderer, document: AIUIDocument) =>\n  renderer.format === document.format && (renderer.supports?.(document.version) ?? true);\n"],"mappings":";;AAyDA,IAAa,qBAAqB,UAAwB,aACxD,SAAS,WAAW,SAAS,WAAW,SAAS,WAAW,SAAS,OAAO,KAAK"}