{"version":3,"file":"useToolPrompt.mjs","names":[],"sources":["../../../src/web/stores/useToolPrompt.ts"],"sourcesContent":["import { useStore } from '@tanstack/react-store';\nimport { useMemo } from 'react';\n\nimport { type ComposerPromptClaim, toolPromptClaim } from '../lib/toolPrompt';\nimport { menuStore } from './menuStore';\nimport { sessionsStore } from './sessionsStore';\nimport { useActiveSession } from './sessionStore';\nimport { toolPromptStore } from './toolPromptStore';\nimport { useWebPluginRegistry } from './useWebPluginRegistry';\n\n/**\n * The running tool standing in for the composer, or null while none is.\n *\n * The composer and the host's dialog both read this, so the request has\n * exactly one owner on any given frame. The facts are selected apart and\n * the verdict memoized on them, including the session's plugin registry revision:\n * a claim is a fresh object each time it is\n * computed, and selecting it directly would make every unrelated frame look\n * like a change.\n */\nexport function useToolPrompt(): ComposerPromptClaim | null {\n  const sessionId = useStore(sessionsStore, (state) => state.activeId);\n  const registryRevision = useWebPluginRegistry();\n  const dialog = useActiveSession((state) => state.dialog);\n  const entries = useActiveSession((state) => state.entries);\n  const activeTools = useActiveSession((state) => state.activeTools);\n  const statuses = useActiveSession((state) => state.statuses);\n  const claimedMenu = useStore(menuStore, (state) => state.claimed?.dialogId ?? null);\n  const failed = useStore(toolPromptStore, (state) => state.failedDialogId);\n  // Both ids can be stale, so neither speaks for the open request unless it\n  // names it: a claim left over from an earlier turn must not wave this one through.\n  const open = dialog?.id ?? null;\n  const spokenFor = open !== null && (open === claimedMenu || open === failed) ? open : null;\n  return useMemo(() => {\n    void registryRevision;\n    return toolPromptClaim({ dialog, entries, activeTools, statuses }, spokenFor, sessionId ?? undefined);\n  }, [dialog, entries, activeTools, statuses, spokenFor, sessionId, registryRevision]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,gBAA4C;CAC1D,MAAM,YAAY,SAAS,gBAAgB,UAAU,MAAM,QAAQ;CACnE,MAAM,mBAAmB,qBAAqB;CAC9C,MAAM,SAAS,kBAAkB,UAAU,MAAM,MAAM;CACvD,MAAM,UAAU,kBAAkB,UAAU,MAAM,OAAO;CACzD,MAAM,cAAc,kBAAkB,UAAU,MAAM,WAAW;CACjE,MAAM,WAAW,kBAAkB,UAAU,MAAM,QAAQ;CAC3D,MAAM,cAAc,SAAS,YAAY,UAAU,MAAM,SAAS,YAAY,IAAI;CAClF,MAAM,SAAS,SAAS,kBAAkB,UAAU,MAAM,cAAc;CAGxE,MAAM,OAAO,QAAQ,MAAM;CAC3B,MAAM,YAAY,SAAS,SAAS,SAAS,eAAe,SAAS,UAAU,OAAO;CACtF,OAAO,cAAc;EAEnB,OAAO,gBAAgB;GAAE;GAAQ;GAAS;GAAa;EAAS,GAAG,WAAW,aAAa,KAAA,CAAS;CACtG,GAAG;EAAC;EAAQ;EAAS;EAAa;EAAU;EAAW;EAAW;CAAgB,CAAC;AACrF"}