{"version":3,"file":"tanstack-ai.cjs","sources":["../src/tanstack-ai.tsx"],"sourcesContent":["// The TanStack AI agentic surface for @simplepdf/react-embed-pdf: the React mirror\n// of @simplepdf/embed's /tanstack-ai subpath. Importing THIS module is what pulls\n// @tanstack/ai (the only added peer), so a non-agentic app never loads it. Pair it\n// with useEmbed():\n//\n//   const { embedRef } = useEmbed()\n//   const tools = clientTools(...useEmbedTools(embedRef)) // from @tanstack/ai-react\n//   useChat({ connection, tools })\n\nimport * as React from 'react';\nimport type { RefObject } from 'react';\nimport type { AnyClientTool } from '@tanstack/ai';\nimport { routeToolCall } from '@simplepdf/embed/tools';\nimport { simplePDFToolDefinitions } from '@simplepdf/embed/tanstack-ai';\nimport type { EmbedActions } from './embed-pdf';\nimport { notMounted } from './not-mounted';\n\n// The server-side tool definitions are NOT re-exported here on purpose: this module\n// imports React (for the hook), so re-exporting them would drag React into a server\n// route that only needs the defs. Import those from the React-free core instead\n// (`@simplepdf/embed/tanstack-ai`). Only the tool-name type (erased at build) is re-exported.\nexport type { SimplePDFToolName } from '@simplepdf/embed/tanstack-ai';\n\n// The agentic tools bound to the live editor via useEmbed().embedRef. Stable and\n// null-safe before the editor mounts (each .client() reads embedRef.current at call\n// time). Pass to clientTools(...) -> useChat({ tools }).\nexport const useEmbedTools = (embedRef: RefObject<EmbedActions | null>): AnyClientTool[] =>\n  React.useMemo<AnyClientTool[]>(\n    () =>\n      simplePDFToolDefinitions().map((definition) =>\n        definition.client((input) =>\n          embedRef.current === null ? notMounted() : routeToolCall(embedRef.current, definition.name, input),\n        ),\n      ),\n    [embedRef],\n  );\n"],"names":["embedRef","React","useMemo","simplePDFToolDefinitions","map","definition","client","input","current","notMounted","routeToolCall","name"],"mappings":"mcA0B6B,SAACA,GAC5B,OAAAC,EAAMC,QACJ,WACE,OAAAC,6BAA2BC,IAAI,SAACC,GAC9B,OAAAA,EAAWC,OAAO,SAACC,GACjB,OAAqB,OAArBP,EAASQ,QAAmBC,eAAeC,gBAAcV,EAASQ,QAASH,EAAWM,KAAMJ,EAA5F,EADF,EADF,EAKF,CAACP,GAPH"}