{"version":3,"file":"useConversation.mjs","names":["createContext","useContext","useMemo","useSyncExternalStore","Conversation","ConversationStore","AiChatItem","AiConversationStore","ConversationStoreContext","useConversationStore","useConversation","id","$","_c","store","t0","ensure","useConversations","t1","listener","subscribe","_temp","list","NONE"],"sources":["../../src/aiAssistant/useConversation.ts"],"sourcesContent":["import { createContext, useContext, useMemo, useSyncExternalStore } from 'react';\nimport { Conversation, ConversationStore } from './conversationState';\nimport type { AiChatItem } from './types';\n\nexport type AiConversationStore = ConversationStore<AiChatItem>;\n\n/** Provided by UdpAiProvider; null when a surface is used without one. */\nexport const ConversationStoreContext = createContext<AiConversationStore | null>(null);\n\nexport const useConversationStore = (): AiConversationStore | null => useContext(ConversationStoreContext);\n\n/**\n * The conversation a surface should drive. With an id and a store in scope,\n * the same Conversation comes back for that id across remounts and from any\n * surface — a docked panel that collapses keeps its chat, a tab list can show\n * it. Without an id (or without a provider) the conversation is private to\n * this mount.\n */\nexport const useConversation = (id?: string): Conversation<AiChatItem> => {\n  const store = useConversationStore();\n  return useMemo(\n    () => (id && store ? store.ensure(id) : new Conversation<AiChatItem>()),\n    [store, id],\n  );\n};\n\n/** Every conversation in the store, live — for a chat list or tab strip. */\nexport const useConversations = (): readonly Conversation<AiChatItem>[] => {\n  const store = useConversationStore();\n  return useSyncExternalStore(\n    (listener) => store?.subscribe(listener) ?? (() => undefined),\n    () => store?.list() ?? NONE,\n  );\n};\n\nconst NONE: readonly Conversation<AiChatItem>[] = [];\n"],"mappings":";;;;;AAOA,MAAaQ,2BAA2BR,cAA0C,KAAK;AAEvF,MAAaS,6BAAuB;AAAA,QAAkCR,WAAWO,yBAAyB;;;;;;;;;AAS1G,MAAaE,mBAAkBC,OAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAC7B,MAAAC,QAAcL,sBAAsB;CAAC,IAAAM;AAAA,KAAAH,EAAA,OAAAD,MAAAC,EAAA,OAAAE,OAAA;AAE5BC,OAAAJ,MAAAG,QAAcA,MAAKE,OAAQL,GAAoC,GAA/D,IAAqCP,cAA0B;AAAAQ,IAAA,KAAAD;AAAAC,IAAA,KAAAE;AAAAF,IAAA,KAAAG;OAAAA,MAAAH,EAAA;AAAA,QAA/DG;;;AAMX,MAAaE,yBAAmB;CAAA,MAAAL,IAAAC,EAAA,EAAA;CAC9B,MAAAC,QAAcL,sBAAsB;CAAC,IAAAM;CAAA,IAAAG;AAAA,KAAAN,EAAA,OAAAE,OAAA;AAEnCC,QAAAI,aAAcL,OAAKM,UAAYD,SAA8B,IAA/CE;AACdH,aAAMJ,OAAKQ,MAAgB,IAArBC;AAAqBX,IAAA,KAAAE;AAAAF,IAAA,KAAAG;AAAAH,IAAA,KAAAM;QAAA;AAAAH,OAAAH,EAAA;AAAAM,OAAAN,EAAA;;AAAA,QAFtBT,qBACLY,IACAG,GACD;;AAGH,MAAMK,OAA4C,EAAE;AARpB,SAAAF,QAAA"}