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K,QACH,OAGF,MAAM,OAAE,EAAA,UAAQ,EAAA,mBAAW,GAAuB,QAClD,QAAU,KAEV,EAAY,QACZ,EAAe,QAGX,EACF,OAAO,eAAe,SAAU,eAAgB,GAEhD,QAAQ,eAAe,SAAU,eAErC,CC/GA,MAAM,QAAU,WAAW,QAAQ,yBACnC,IAAgC,IAA5B,SAAS,eACX,IACE,0BAA0B,QAC5B,OAAS,GACP,QAAQ,MAAM,gDAAiD,EACjE,Q","file":"/npm/@mcp-b/global@6.2.0/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.48.0.\n * Original file: /npm/@mcp-b/global@6.2.0/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import { IframeChildTransport, TabServerTransport } from '@mcp-b/transports';\nimport { installWebMCP } from '@mcp-b/webmcp-polyfill';\nimport { BrowserMcpServer, isBrowserMcpServer } from '@mcp-b/webmcp-ts-sdk';\nimport type { Transport } from '@modelcontextprotocol/server';\nimport type { WebModelContextInitOptions } from './types.js';\n\ninterface RuntimeState {\n  server: BrowserMcpServer;\n  transport: Transport;\n  previousDescriptor: PropertyDescriptor | undefined;\n}\n\nlet runtime: RuntimeState | null = null;\n\nfunction createTransport(config: WebModelContextInitOptions['transport']): Transport {\n  const inIframe = window.parent !== window;\n\n  if (inIframe && config?.iframeServer !== false) {\n    return new IframeChildTransport(config?.iframeServer || { allowedOrigins: ['*'] });\n  }\n\n  if (config?.tabServer === false) {\n    throw new Error('tabServer transport is disabled and iframe transport was not selected');\n  }\n\n  return new TabServerTransport(config?.tabServer || { allowedOrigins: ['*'] });\n}\n\n/** Installs the global bridge on `document.modelContext`. */\nexport function initializeWebModelContext(options?: WebModelContextInitOptions): void {\n  if (!globalThis.window || !globalThis.document || globalThis.isSecureContext === false) {\n    return;\n  }\n\n  if (runtime) {\n    return;\n  }\n\n  // Cross-bundle guard: another bundle in this window already installed the bridge.\n  if (isBrowserMcpServer(document.modelContext)) {\n    return;\n  }\n\n  // Preserve native/core contexts and add declarative support when it is missing.\n  installWebMCP();\n  // Capture the upstream context before installing MCP-B extensions.\n  const native = document.modelContext;\n  if (!native) {\n    throw new Error('modelContext is not available');\n  }\n\n  // Some browser hosts expose a frozen native context through non-configurable\n  // own properties. It is already usable and cannot legally be wrapped.\n  const previousDescriptor = Object.getOwnPropertyDescriptor(document, 'modelContext');\n  if (previousDescriptor ? !previousDescriptor.configurable : !Object.isExtensible(document)) {\n    return;\n  }\n\n  // Resolve transport before replacing the document context.\n  const transport = createTransport(options?.transport);\n\n  // Create the MCP server with native mirroring.\n  const hostname = window.location.hostname || 'localhost';\n  const server = new BrowserMcpServer({ name: `${hostname}-webmcp`, version: '1.0.0' }, { native });\n\n  try {\n    Object.defineProperty(document, 'modelContext', {\n      configurable: true,\n      enumerable: true,\n      writable: false,\n      value: server,\n    });\n    runtime = { server, transport, previousDescriptor };\n  } catch (error) {\n    void server.close();\n    void transport.close();\n    throw error;\n  }\n\n  void (async () => {\n    try {\n      await server.syncNativeTools();\n    } catch (error) {\n      console.warn('[WebModelContext] Native WebMCP tool synchronization failed:', error);\n    }\n\n    if (runtime?.server !== server) {\n      return;\n    }\n\n    try {\n      await server.connect(transport);\n    } catch (error) {\n      console.error('[WebModelContext] Failed to connect MCP transport:', error);\n      if (runtime?.server === server) {\n        cleanupWebModelContext();\n      }\n    }\n  })();\n}\n\nexport function cleanupWebModelContext(): void {\n  if (!runtime) {\n    return;\n  }\n\n  const { server, transport, previousDescriptor } = runtime;\n  runtime = null;\n\n  void server.close();\n  void transport.close();\n\n  // The polyfill and its declarative layer remain installed for the lifetime of the document.\n  if (previousDescriptor) {\n    Object.defineProperty(document, 'modelContext', previousDescriptor);\n  } else {\n    Reflect.deleteProperty(document, 'modelContext');\n  }\n}\n","import { cleanupWebModelContext, initializeWebModelContext } from './global.js';\n\nexport { cleanupWebModelContext, initializeWebModelContext };\nexport type { WebMCP } from '@mcp-b/webmcp-polyfill';\n\nexport type { TransportConfiguration, WebModelContextInitOptions } from './types.js';\n\nconst options = globalThis.window?.__webModelContextOptions;\nif (options?.autoInitialize !== false) {\n  try {\n    initializeWebModelContext(options);\n  } catch (error) {\n    console.error('[WebModelContext] Auto-initialization failed:', error);\n  }\n}\n"]}