type CodeFormat = "esm" | "script-installer" | "script-manual" | "script-advanced" | "react-component" | "react-advanced"; /** * Hook code templates for code generation. * Each hook can be provided as a string (code template) OR as an actual function. * Functions are automatically serialized via `.toString()`. * * IMPORTANT: When providing functions: * - Functions must be self-contained (no external variables/closures) * - External variables will be undefined when the generated code runs * - Use arrow functions or regular function expressions * * @example * ```typescript * // Both of these work: * * // As string: * { getHeaders: "async () => ({ 'Authorization': 'Bearer token' })" } * * // As function (recommended - better IDE support): * { getHeaders: async () => ({ 'Authorization': 'Bearer token' }) } * ``` */ type CodeGeneratorHooks = { /** * Custom getHeaders function. * Should return an object with header key-value pairs. * * @example * ```typescript * async () => ({ 'Authorization': `Bearer ${await getAuthToken()}` }) * ``` */ getHeaders?: string | (() => Record | Promise>); /** * Custom onFeedback callback for message actions. * Receives a feedback object with type, messageId, and message. * * @example * ```typescript * (feedback) => { console.log('Feedback:', feedback.type); } * ``` */ onFeedback?: string | ((feedback: { type: string; messageId: string; message: unknown; }) => void); /** * Custom onCopy callback for message actions. * Receives the message that was copied. * * @example * ```typescript * (message) => { analytics.track('message_copied', { id: message.id }); } * ``` */ onCopy?: string | ((message: unknown) => void); /** * Custom requestMiddleware function. * Receives { payload, config } context. * * @example * ```typescript * ({ payload }) => ({ ...payload, metadata: { pageUrl: window.location.href } }) * ``` */ requestMiddleware?: string | ((context: { payload: unknown; config: unknown; }) => unknown); /** * Custom action handlers array. * Array of handler functions. * * @example * ```typescript * [ * (action, context) => { * if (action.type === 'custom') { * return { handled: true }; * } * } * ] * ``` */ actionHandlers?: string | Array<(action: unknown, context: unknown) => unknown>; /** * Custom action parsers array. * Array of parser functions. */ actionParsers?: string | Array<(context: unknown) => unknown>; /** * Custom postprocessMessage function. * Receives { text, message, streaming, raw } context. * Will override the default markdownPostprocessor. * * @example * ```typescript * ({ text }) => customMarkdownProcessor(text) * ``` */ postprocessMessage?: string | ((context: { text: string; message?: unknown; streaming?: boolean; raw?: string; }) => string); /** * Custom context providers array. * Array of provider functions. */ contextProviders?: string | Array<() => unknown>; /** * Custom stream parser factory. * Should be a function that returns a StreamParser. */ streamParser?: string | (() => unknown); }; /** * Options for code generation beyond format selection. */ type CodeGeneratorOptions = { /** * Custom hook code to inject into the generated snippet. * Hooks are JavaScript/TypeScript code strings that will be * inserted at appropriate locations in the output. */ hooks?: CodeGeneratorHooks; /** * Whether to include comments explaining each hook. * @default true */ includeHookComments?: boolean; /** * If provided, emits `windowKey` in the generated `initAgentWidget()` call * so the widget handle is stored on `window[windowKey]`. * Only affects script formats (script-installer, script-manual, script-advanced). */ windowKey?: string; /** * CSS selector for the mount target. When omitted, the widget mounts on * `body` (the existing default). When provided, the generated snippet mounts * into that element: ESM / React / manual / advanced formats emit it as the * `target` argument to `initAgentWidget()`, and `script-installer` serializes * it into `data-config` (the installer reads `config.target`). * @default "body" */ target?: string; }; declare function generateCodeSnippet(config: any, format?: CodeFormat, options?: CodeGeneratorOptions): string; export { type CodeFormat, type CodeGeneratorHooks, type CodeGeneratorOptions, generateCodeSnippet };