@mcp-b/react-components 0.14.2 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/dist/AgentActivity-BNUNrP9O.d.ts +36 -0
  2. package/dist/{AgentChat-DQkqt82e.d.ts → AgentChat-CrlpbvQJ.d.ts} +58 -6
  3. package/dist/{CodeBlock-DUh9WOGo.d.ts → CodeBlock-BRajW4QU.d.ts} +1 -1
  4. package/dist/{CodeBlock-BUFXG8HW.js → CodeBlock-BmB4Xaqq.js} +15 -4
  5. package/dist/{FileTree-mpEIcfzA.js → FileTree-CkVbIMWV.js} +82 -89
  6. package/dist/Message-BkMdE3bS.js +375 -0
  7. package/dist/{ModelSelector-CPCpFAUt.js → ModelSelector-SlJNgwKY.js} +2 -2
  8. package/dist/{PromptInput-ClNqBiIw.d.ts → PromptInput-BWTuXMOD.d.ts} +123 -5
  9. package/dist/ResponsiveSidebarShell-Dd9DCcBT.d.ts +67 -0
  10. package/dist/{Select-Dl_vF_Bt.d.ts → Select-BeEsefzh.d.ts} +12 -2
  11. package/dist/{ThinkChat-BPcehdbP.js → ThinkChat-CzC-zNGA.js} +24 -36
  12. package/dist/{ThinkChatActivity-BmwuIigx.d.ts → ThinkChatActivity-BFQnb2ct.d.ts} +3 -10
  13. package/dist/ThinkChatActivitySummary-BPmu9a-c.d.ts +39 -0
  14. package/dist/{ThinkChatToolParts-CDEjqS6A.d.ts → ThinkChatToolParts-CSzVwMXf.d.ts} +13 -3
  15. package/dist/ThinkExecutionRun-ChhWhOoU.d.ts +30 -0
  16. package/dist/Toggle-CAAlNl-M.d.ts +69 -0
  17. package/dist/ToggleGroup-8hPv-b69.d.ts +73 -0
  18. package/dist/Workspace-D39LxGvP.d.ts +62 -0
  19. package/dist/WorkspaceFile-DOZkPwzu.d.ts +106 -0
  20. package/dist/WorkspaceFileView-rSN_yT0L.js +744 -0
  21. package/dist/WorkspaceLink-DIPbXrUM.js +337 -0
  22. package/dist/WorkspaceLink-DK1DWMHe.d.ts +89 -0
  23. package/dist/components/Activity.d.ts +27 -1
  24. package/dist/components/Activity.js +33 -15
  25. package/dist/components/AgentActivity.d.ts +2 -0
  26. package/dist/components/AgentActivity.js +45 -0
  27. package/dist/components/AgentActivityPreview.d.ts +46 -0
  28. package/dist/components/AgentActivityPreview.js +94 -0
  29. package/dist/components/AgentAttention.d.ts +73 -0
  30. package/dist/components/AgentAttention.js +85 -0
  31. package/dist/components/AgentChat.d.ts +2 -2
  32. package/dist/components/AgentChat.js +224 -200
  33. package/dist/components/AgentChatMessageEditor.d.ts +29 -0
  34. package/dist/components/AgentChatMessageEditor.js +92 -0
  35. package/dist/components/AgentChatTurnError.d.ts +17 -0
  36. package/dist/components/AgentChatTurnError.js +40 -0
  37. package/dist/components/AgentConnection.d.ts +12 -17
  38. package/dist/components/AgentConnection.js +99 -91
  39. package/dist/components/AppFrame.d.ts +24 -0
  40. package/dist/components/AppFrame.js +25 -0
  41. package/dist/components/AppTopBar.d.ts +71 -0
  42. package/dist/components/AppTopBar.js +82 -0
  43. package/dist/components/Artifact.js +1 -1
  44. package/dist/components/BrowserLiveView.js +1 -1
  45. package/dist/components/BrowserReplay.js +1 -1
  46. package/dist/components/BrowserRunPanel.js +1 -1
  47. package/dist/components/Card.d.ts +3 -0
  48. package/dist/components/Card.js +2 -1
  49. package/dist/components/ChainOfThought.d.ts +1 -1
  50. package/dist/components/ChainOfThought.js +1 -1
  51. package/dist/components/ChatGptSignInScreen.js +2 -2
  52. package/dist/components/Checkbox.js +5 -13
  53. package/dist/components/CheckboxGroup.d.ts +58 -2
  54. package/dist/components/CheckboxGroup.js +59 -1
  55. package/dist/components/CodeBlock.d.ts +1 -1
  56. package/dist/components/CodeBlock.js +1 -1
  57. package/dist/components/CodexModelSelector.js +1 -1
  58. package/dist/components/Commit.js +2 -2
  59. package/dist/components/ContextMenu.js +1 -1
  60. package/dist/components/Conversation.js +1 -1
  61. package/dist/components/DescriptionList.d.ts +12 -0
  62. package/dist/components/DescriptionList.js +11 -0
  63. package/dist/components/DescriptionListParts.d.ts +37 -0
  64. package/dist/components/DescriptionListParts.js +35 -0
  65. package/dist/components/EnvironmentVariables.js +2 -2
  66. package/dist/components/Fieldset.d.ts +13 -1
  67. package/dist/components/Fieldset.js +11 -2
  68. package/dist/components/FileTree.js +1 -1
  69. package/dist/components/IconButton.d.ts +33 -0
  70. package/dist/components/IconButton.js +27 -0
  71. package/dist/components/McpConnectionRequest.d.ts +44 -0
  72. package/dist/components/McpConnectionRequest.js +122 -0
  73. package/dist/components/McpServerPicker.d.ts +48 -23
  74. package/dist/components/McpServerPicker.js +238 -189
  75. package/dist/components/Menubar.js +1 -1
  76. package/dist/components/Message.d.ts +1 -0
  77. package/dist/components/Message.js +1 -285
  78. package/dist/components/MessageScroller.js +1 -1
  79. package/dist/components/ModelSelector.js +1 -1
  80. package/dist/components/Pricing.d.ts +37 -0
  81. package/dist/components/Pricing.js +17 -0
  82. package/dist/components/PricingBillingToggle.d.ts +23 -0
  83. package/dist/components/PricingBillingToggle.js +86 -0
  84. package/dist/components/PricingConfirmationDialog.d.ts +25 -0
  85. package/dist/components/PricingConfirmationDialog.js +57 -0
  86. package/dist/components/PricingFAQ.d.ts +18 -0
  87. package/dist/components/PricingFAQ.js +27 -0
  88. package/dist/components/PricingPage.d.ts +2 -38
  89. package/dist/components/PricingPage.js +39 -359
  90. package/dist/components/PricingPlanCard.d.ts +22 -0
  91. package/dist/components/PricingPlanCard.js +109 -0
  92. package/dist/components/PricingUsageCalculator.d.ts +22 -0
  93. package/dist/components/PricingUsageCalculator.js +96 -0
  94. package/dist/components/PromptInput.d.ts +2 -2
  95. package/dist/components/PromptInput.js +210 -15
  96. package/dist/components/Queue.js +1 -1
  97. package/dist/components/Reasoning.d.ts +2 -1
  98. package/dist/components/Reasoning.js +14 -29
  99. package/dist/components/ResizableSidePanel.d.ts +57 -0
  100. package/dist/components/ResizableSidePanel.js +151 -0
  101. package/dist/components/ResponsiveSidebarShell.d.ts +2 -0
  102. package/dist/components/ResponsiveSidebarShell.js +129 -0
  103. package/dist/components/Select.d.ts +2 -2
  104. package/dist/components/Select.js +11 -2
  105. package/dist/components/Slider.d.ts +13 -1
  106. package/dist/components/Slider.js +11 -0
  107. package/dist/components/Sources.js +1 -1
  108. package/dist/components/Stepper.d.ts +4 -0
  109. package/dist/components/Stepper.js +5 -3
  110. package/dist/components/SubagentRun.d.ts +18 -19
  111. package/dist/components/SubagentRun.js +25 -18
  112. package/dist/components/SubagentRunIndicator.d.ts +22 -0
  113. package/dist/components/SubagentRunIndicator.js +33 -0
  114. package/dist/components/SubagentRunList.d.ts +25 -0
  115. package/dist/components/SubagentRunList.js +26 -0
  116. package/dist/components/SubagentRunSelector.d.ts +47 -0
  117. package/dist/components/SubagentRunSelector.js +55 -0
  118. package/dist/components/Task.js +1 -1
  119. package/dist/components/Terminal.js +2 -2
  120. package/dist/components/TestResults.js +1 -1
  121. package/dist/components/Textarea.d.ts +21 -0
  122. package/dist/components/Textarea.js +19 -0
  123. package/dist/components/ThemeModeControl.d.ts +24 -0
  124. package/dist/components/ThemeModeControl.js +52 -0
  125. package/dist/components/ThemeProvider.d.ts +38 -0
  126. package/dist/components/ThemeProvider.js +80 -0
  127. package/dist/components/ThinkChat.d.ts +29 -6
  128. package/dist/components/ThinkChat.js +7 -4
  129. package/dist/components/ThinkChatActivity.d.ts +3 -2
  130. package/dist/components/ThinkChatActivity.js +12 -318
  131. package/dist/components/ThinkChatActivitySummary.d.ts +2 -0
  132. package/dist/components/ThinkChatActivitySummary.js +421 -0
  133. package/dist/components/ThinkChatToolPanels.d.ts +7 -5
  134. package/dist/components/ThinkChatToolPanels.js +70 -8
  135. package/dist/components/ThinkChatToolParts.d.ts +2 -2
  136. package/dist/components/ThinkChatToolParts.js +36 -10
  137. package/dist/components/ThinkExecutionDetail.d.ts +20 -0
  138. package/dist/components/ThinkExecutionDetail.js +80 -0
  139. package/dist/components/ThinkExecutionRun.d.ts +2 -0
  140. package/dist/components/ThinkExecutionRun.js +72 -0
  141. package/dist/components/ThinkExecutionStatus.d.ts +22 -0
  142. package/dist/components/ThinkExecutionStatus.js +36 -0
  143. package/dist/components/ThinkExecutionWorkbench.d.ts +7 -0
  144. package/dist/components/ThinkExecutionWorkbench.js +69 -225
  145. package/dist/components/ThinkFullApp.d.ts +58 -14
  146. package/dist/components/ThinkFullApp.js +129 -160
  147. package/dist/components/ThinkFullAppViewSwitch.d.ts +31 -0
  148. package/dist/components/ThinkFullAppViewSwitch.js +34 -0
  149. package/dist/components/ThinkRoutine.d.ts +36 -0
  150. package/dist/components/ThinkRoutine.js +15 -0
  151. package/dist/components/ThinkRoutineBrowser.d.ts +25 -0
  152. package/dist/components/ThinkRoutineBrowser.js +156 -0
  153. package/dist/components/ThinkRoutineDetail.d.ts +24 -0
  154. package/dist/components/ThinkRoutineDetail.js +102 -0
  155. package/dist/components/ThinkRoutineForm.d.ts +32 -0
  156. package/dist/components/ThinkRoutineForm.js +151 -0
  157. package/dist/components/ThinkRoutineLibrary.d.ts +74 -0
  158. package/dist/components/ThinkRoutineLibrary.js +178 -0
  159. package/dist/components/ThinkRoutineRuns.d.ts +24 -0
  160. package/dist/components/ThinkRoutineRuns.js +68 -0
  161. package/dist/components/ThinkThreadPicker.d.ts +18 -1
  162. package/dist/components/ThinkThreadPicker.js +51 -5
  163. package/dist/components/ThinkThreadShell.d.ts +12 -9
  164. package/dist/components/ThinkThreadShell.js +17 -137
  165. package/dist/components/Toggle.d.ts +1 -68
  166. package/dist/components/ToggleGroup.d.ts +1 -72
  167. package/dist/components/Tooltip.d.ts +3 -1
  168. package/dist/components/Tooltip.js +4 -2
  169. package/dist/components/WebPreview.js +1 -1
  170. package/dist/components/Workspace.d.ts +2 -0
  171. package/dist/components/Workspace.js +424 -0
  172. package/dist/components/WorkspaceBrowser.d.ts +32 -0
  173. package/dist/components/WorkspaceBrowser.js +103 -0
  174. package/dist/components/WorkspaceExplorer.d.ts +12 -79
  175. package/dist/components/WorkspaceExplorer.js +116 -330
  176. package/dist/components/WorkspaceFile.d.ts +2 -0
  177. package/dist/components/WorkspaceFile.js +195 -0
  178. package/dist/components/WorkspaceFileView.d.ts +26 -0
  179. package/dist/components/WorkspaceFileView.js +2 -0
  180. package/dist/components/WorkspaceHeader.d.ts +35 -0
  181. package/dist/components/WorkspaceHeader.js +51 -0
  182. package/dist/components/WorkspaceLink.d.ts +2 -0
  183. package/dist/components/WorkspaceLink.js +2 -0
  184. package/dist/components/icons.d.ts +2 -2
  185. package/dist/components/icons.js +2 -2
  186. package/dist/{copy-button-DUMLYdsk.js → copy-button-Dejn5heL.js} +1 -1
  187. package/dist/icons-CpfUer49.js +85 -0
  188. package/dist/{icons-CUCz_Sft.d.ts → icons-GQd1xF4e.d.ts} +51 -1
  189. package/dist/styles/activity-header.css +75 -0
  190. package/dist/styles/activity.css +49 -63
  191. package/dist/styles/agent-activity-preview-overlay.css +80 -0
  192. package/dist/styles/agent-activity-preview.css +235 -0
  193. package/dist/styles/agent-attention.css +122 -0
  194. package/dist/styles/agent-chat.css +133 -4
  195. package/dist/styles/app-frame.css +15 -0
  196. package/dist/styles/app-top-bar.css +100 -0
  197. package/dist/styles/avatar.css +0 -1
  198. package/dist/styles/browser-control-overlay.css +184 -0
  199. package/dist/styles/card.css +21 -0
  200. package/dist/styles/checkbox-group.css +69 -0
  201. package/dist/styles/description-list.css +50 -0
  202. package/dist/styles/fieldset.css +11 -0
  203. package/dist/styles/index.css +14 -2
  204. package/dist/styles/mcp-connection-request.css +60 -0
  205. package/dist/styles/mcp-server-picker.css +95 -68
  206. package/dist/styles/message.css +4 -43
  207. package/dist/styles/pricing-page.css +21 -27
  208. package/dist/styles/prompt-input.css +225 -32
  209. package/dist/styles/reasoning.css +1 -55
  210. package/dist/styles/recipes.css +23 -15
  211. package/dist/styles/resizable-side-panel.css +66 -0
  212. package/dist/styles/responsive-sidebar-shell.css +169 -0
  213. package/dist/styles/select.css +10 -0
  214. package/dist/styles/stepper.css +13 -0
  215. package/dist/styles/streamdown.css +0 -4
  216. package/dist/styles/subagent-run.css +55 -38
  217. package/dist/styles/textarea.css +20 -0
  218. package/dist/styles/theme-mode-control.css +72 -0
  219. package/dist/styles/think-execution-status.css +49 -0
  220. package/dist/styles/think-execution-workbench.css +8 -72
  221. package/dist/styles/think-full-app.css +104 -131
  222. package/dist/styles/think-routine-library.css +491 -0
  223. package/dist/styles/think-thread-picker.css +47 -3
  224. package/dist/styles/toggle-group.css +7 -0
  225. package/dist/styles/workspace-explorer.css +511 -64
  226. package/dist/utils/mcp-server-catalog.d.ts +82 -78
  227. package/dist/utils/mcp-server-catalog.js +64 -41
  228. package/dist/utils/structured-code.d.ts +1 -1
  229. package/dist/utils/theme.d.ts +22 -0
  230. package/dist/utils/theme.js +55 -0
  231. package/package.json +34 -28
  232. package/dist/icons-Ba9THQKz.js +0 -64
  233. package/dist/styles/think-resize-handle.css +0 -33
  234. package/dist/styles/think-thread-shell.css +0 -219
@@ -1,7 +1,6 @@
1
- import { MCPServer } from "agents";
1
+ import { MCPServer, MCPServersState } from "agents";
2
2
 
3
3
  //#region src/utils/mcp-server-catalog.d.ts
4
- type McpServerPickerStatus = MCPServer["state"] | "needs-auth";
5
4
  interface McpServerCardIcon {
6
5
  src: string;
7
6
  }
@@ -9,7 +8,7 @@ interface McpServerSetupLink {
9
8
  label: string;
10
9
  url: string;
11
10
  }
12
- type McpServerSetupAuthFieldName = "bearerToken" | "clientId" | "clientSecret" | "redirectUrl" | "scope";
11
+ type McpServerSetupAuthFieldName = "bearerToken" | "clientId" | "clientSecret" | "redirectUrl";
13
12
  interface McpServerSetupAuthField {
14
13
  name: McpServerSetupAuthFieldName;
15
14
  label: string;
@@ -28,16 +27,41 @@ interface McpServerManualSetup {
28
27
  links: readonly McpServerSetupLink[];
29
28
  }
30
29
  interface McpServerCard {
30
+ /**
31
+ * Stable MCP registration ID owned by the host.
32
+ *
33
+ * Pass the normalized ID to Agents in the options argument to
34
+ * `addMcpServer(name, url, { id })`. Hosts that omit a stable ID must use this
35
+ * value as the upstream registration name so the generated entry can still
36
+ * be matched without guessing by URL alone.
37
+ */
31
38
  id: string;
32
39
  name: string;
33
40
  url: string;
34
41
  description?: string;
35
42
  category?: string;
36
43
  icon?: string | McpServerCardIcon;
37
- status?: McpServerPickerStatus;
38
- statusLabel?: string;
39
44
  manualSetup?: McpServerManualSetup;
40
45
  }
46
+ /**
47
+ * Read the complete state emitted by the pinned Agents runtime.
48
+ *
49
+ * Agents 0.17.4 can return `not-connected` from `getMcpServers()` even though
50
+ * that value is missing from its exported `MCPServer["state"]` declaration.
51
+ * Keep the unavoidable compatibility assertion at this one SDK boundary.
52
+ */
53
+ declare function getMcpServerRuntimeState(server: MCPServer): MCPServer["state"] | "not-connected";
54
+ /**
55
+ * Match a host-owned stable registration identity to an upstream Agents entry.
56
+ *
57
+ * `normalizeServerId` deliberately stays in the host. Importing it from the
58
+ * optional `agents` runtime also loads Worker-only `cloudflare:` modules (and
59
+ * the `agents/mcp/client` subpath loads the full MCP client). This browser UI
60
+ * therefore compares the already-normalized ID supplied by the host, then uses
61
+ * Agents' registration `(name, canonical URL)` identity only to recognize a
62
+ * legacy/generated ID.
63
+ */
64
+ declare function getMcpServerEntry(server: McpServerCard, mcp: MCPServersState | undefined): [serverId: string, server: MCPServer] | undefined;
41
65
  declare const MCP_SERVER_SETUP_AUTH: {
42
66
  readonly bearer: {
43
67
  readonly type: "bearer";
@@ -63,10 +87,6 @@ declare const MCP_SERVER_SETUP_AUTH: {
63
87
  readonly label: "Redirect URL";
64
88
  readonly inputType: "url";
65
89
  readonly placeholder: "Registered OAuth callback URL";
66
- }, {
67
- readonly name: "scope";
68
- readonly label: "Scope";
69
- readonly placeholder: "Space-separated scopes";
70
90
  }];
71
91
  };
72
92
  readonly manualOAuthClientSecret: {
@@ -88,10 +108,6 @@ declare const MCP_SERVER_SETUP_AUTH: {
88
108
  readonly label: "Redirect URL";
89
109
  readonly inputType: "url";
90
110
  readonly placeholder: "Registered OAuth callback URL";
91
- }, {
92
- readonly name: "scope";
93
- readonly label: "Scope";
94
- readonly placeholder: "Space-separated scopes";
95
111
  }];
96
112
  };
97
113
  readonly none: {
@@ -101,7 +117,7 @@ declare const MCP_SERVER_SETUP_AUTH: {
101
117
  };
102
118
  };
103
119
  declare const CUSTOM_MCP_SERVER_CARD: {
104
- readonly id: "localMcp";
120
+ readonly id: "localmcp";
105
121
  readonly name: "Custom MCP";
106
122
  readonly url: "";
107
123
  readonly description: "Connect any Streamable HTTP MCP server";
@@ -377,10 +393,6 @@ declare const MANUAL_MCP_SERVER_CARDS: readonly [{
377
393
  readonly label: "Redirect URL";
378
394
  readonly inputType: "url";
379
395
  readonly placeholder: "Registered OAuth callback URL";
380
- }, {
381
- readonly name: "scope";
382
- readonly label: "Scope";
383
- readonly placeholder: "Space-separated scopes";
384
396
  }];
385
397
  };
386
398
  readonly description: "Create an Asana MCP app, configure its redirect URL and workspace distribution, then connect with the app client ID and secret.";
@@ -405,24 +417,26 @@ declare const MANUAL_MCP_SERVER_CARDS: readonly [{
405
417
  readonly manualSetup: {
406
418
  readonly auth: {
407
419
  readonly type: "manual_oauth_client";
408
- readonly label: "OAuth client ID";
420
+ readonly label: "OAuth client ID + secret";
409
421
  readonly fields: readonly [{
410
422
  readonly name: "clientId";
411
423
  readonly label: "OAuth client ID";
412
424
  readonly placeholder: "Client ID";
413
425
  readonly required: true;
426
+ }, {
427
+ readonly name: "clientSecret";
428
+ readonly label: "OAuth client secret";
429
+ readonly inputType: "password";
430
+ readonly placeholder: "Client secret";
431
+ readonly required: true;
414
432
  }, {
415
433
  readonly name: "redirectUrl";
416
434
  readonly label: "Redirect URL";
417
435
  readonly inputType: "url";
418
436
  readonly placeholder: "Registered OAuth callback URL";
419
- }, {
420
- readonly name: "scope";
421
- readonly label: "Scope";
422
- readonly placeholder: "Space-separated scopes";
423
437
  }];
424
438
  };
425
- readonly description: "Enable Gmail and Gmail MCP APIs, configure OAuth consent, add Gmail read/compose scopes, and create a web OAuth client.";
439
+ readonly description: "Enable Gmail and Gmail MCP APIs, configure OAuth consent, and create a web OAuth client.";
426
440
  readonly links: readonly [{
427
441
  readonly label: "Setup guide";
428
442
  readonly url: "https://developers.google.com/workspace/gmail/api/guides/configure-mcp-server";
@@ -447,24 +461,26 @@ declare const MANUAL_MCP_SERVER_CARDS: readonly [{
447
461
  readonly manualSetup: {
448
462
  readonly auth: {
449
463
  readonly type: "manual_oauth_client";
450
- readonly label: "OAuth client ID";
464
+ readonly label: "OAuth client ID + secret";
451
465
  readonly fields: readonly [{
452
466
  readonly name: "clientId";
453
467
  readonly label: "OAuth client ID";
454
468
  readonly placeholder: "Client ID";
455
469
  readonly required: true;
470
+ }, {
471
+ readonly name: "clientSecret";
472
+ readonly label: "OAuth client secret";
473
+ readonly inputType: "password";
474
+ readonly placeholder: "Client secret";
475
+ readonly required: true;
456
476
  }, {
457
477
  readonly name: "redirectUrl";
458
478
  readonly label: "Redirect URL";
459
479
  readonly inputType: "url";
460
480
  readonly placeholder: "Registered OAuth callback URL";
461
- }, {
462
- readonly name: "scope";
463
- readonly label: "Scope";
464
- readonly placeholder: "Space-separated scopes";
465
481
  }];
466
482
  };
467
- readonly description: "Enable Calendar and Calendar MCP APIs, configure OAuth consent, add calendar read/freebusy scopes, and create a web OAuth client.";
483
+ readonly description: "Enable Calendar and Calendar MCP APIs, configure OAuth consent, and create a web OAuth client.";
468
484
  readonly links: readonly [{
469
485
  readonly label: "Setup guide";
470
486
  readonly url: "https://developers.google.com/workspace/calendar/api/guides/configure-mcp-server";
@@ -489,24 +505,26 @@ declare const MANUAL_MCP_SERVER_CARDS: readonly [{
489
505
  readonly manualSetup: {
490
506
  readonly auth: {
491
507
  readonly type: "manual_oauth_client";
492
- readonly label: "OAuth client ID";
508
+ readonly label: "OAuth client ID + secret";
493
509
  readonly fields: readonly [{
494
510
  readonly name: "clientId";
495
511
  readonly label: "OAuth client ID";
496
512
  readonly placeholder: "Client ID";
497
513
  readonly required: true;
514
+ }, {
515
+ readonly name: "clientSecret";
516
+ readonly label: "OAuth client secret";
517
+ readonly inputType: "password";
518
+ readonly placeholder: "Client secret";
519
+ readonly required: true;
498
520
  }, {
499
521
  readonly name: "redirectUrl";
500
522
  readonly label: "Redirect URL";
501
523
  readonly inputType: "url";
502
524
  readonly placeholder: "Registered OAuth callback URL";
503
- }, {
504
- readonly name: "scope";
505
- readonly label: "Scope";
506
- readonly placeholder: "Space-separated scopes";
507
525
  }];
508
526
  };
509
- readonly description: "Enable Chat and Chat MCP APIs, configure a Chat app, add Chat read/send scopes, and create a web OAuth client.";
527
+ readonly description: "Enable Chat and Chat MCP APIs, configure a Chat app, and create a web OAuth client.";
510
528
  readonly links: readonly [{
511
529
  readonly label: "Setup guide";
512
530
  readonly url: "https://developers.google.com/workspace/chat/api/guides/configure-mcp-server";
@@ -531,24 +549,26 @@ declare const MANUAL_MCP_SERVER_CARDS: readonly [{
531
549
  readonly manualSetup: {
532
550
  readonly auth: {
533
551
  readonly type: "manual_oauth_client";
534
- readonly label: "OAuth client ID";
552
+ readonly label: "OAuth client ID + secret";
535
553
  readonly fields: readonly [{
536
554
  readonly name: "clientId";
537
555
  readonly label: "OAuth client ID";
538
556
  readonly placeholder: "Client ID";
539
557
  readonly required: true;
558
+ }, {
559
+ readonly name: "clientSecret";
560
+ readonly label: "OAuth client secret";
561
+ readonly inputType: "password";
562
+ readonly placeholder: "Client secret";
563
+ readonly required: true;
540
564
  }, {
541
565
  readonly name: "redirectUrl";
542
566
  readonly label: "Redirect URL";
543
567
  readonly inputType: "url";
544
568
  readonly placeholder: "Registered OAuth callback URL";
545
- }, {
546
- readonly name: "scope";
547
- readonly label: "Scope";
548
- readonly placeholder: "Space-separated scopes";
549
569
  }];
550
570
  };
551
- readonly description: "Enable Drive and Drive MCP APIs, configure OAuth consent, add Drive read/file scopes, and create a web OAuth client.";
571
+ readonly description: "Enable Drive and Drive MCP APIs, configure OAuth consent, and create a web OAuth client.";
552
572
  readonly links: readonly [{
553
573
  readonly label: "Setup guide";
554
574
  readonly url: "https://developers.google.com/workspace/drive/api/guides/configure-mcp-server";
@@ -573,24 +593,26 @@ declare const MANUAL_MCP_SERVER_CARDS: readonly [{
573
593
  readonly manualSetup: {
574
594
  readonly auth: {
575
595
  readonly type: "manual_oauth_client";
576
- readonly label: "OAuth client ID";
596
+ readonly label: "OAuth client ID + secret";
577
597
  readonly fields: readonly [{
578
598
  readonly name: "clientId";
579
599
  readonly label: "OAuth client ID";
580
600
  readonly placeholder: "Client ID";
581
601
  readonly required: true;
602
+ }, {
603
+ readonly name: "clientSecret";
604
+ readonly label: "OAuth client secret";
605
+ readonly inputType: "password";
606
+ readonly placeholder: "Client secret";
607
+ readonly required: true;
582
608
  }, {
583
609
  readonly name: "redirectUrl";
584
610
  readonly label: "Redirect URL";
585
611
  readonly inputType: "url";
586
612
  readonly placeholder: "Registered OAuth callback URL";
587
- }, {
588
- readonly name: "scope";
589
- readonly label: "Scope";
590
- readonly placeholder: "Space-separated scopes";
591
613
  }];
592
614
  };
593
- readonly description: "Enable People API, configure OAuth consent, add contacts/profile/directory scopes, and create a web OAuth client.";
615
+ readonly description: "Enable People API, configure OAuth consent, and create a web OAuth client.";
594
616
  readonly links: readonly [{
595
617
  readonly label: "Setup guide";
596
618
  readonly url: "https://developers.google.com/people/v1/configure-mcp-server";
@@ -615,24 +637,26 @@ declare const MANUAL_MCP_SERVER_CARDS: readonly [{
615
637
  readonly manualSetup: {
616
638
  readonly auth: {
617
639
  readonly type: "manual_oauth_client";
618
- readonly label: "OAuth client ID";
640
+ readonly label: "OAuth client ID + secret";
619
641
  readonly fields: readonly [{
620
642
  readonly name: "clientId";
621
643
  readonly label: "OAuth client ID";
622
644
  readonly placeholder: "Client ID";
623
645
  readonly required: true;
646
+ }, {
647
+ readonly name: "clientSecret";
648
+ readonly label: "OAuth client secret";
649
+ readonly inputType: "password";
650
+ readonly placeholder: "Client secret";
651
+ readonly required: true;
624
652
  }, {
625
653
  readonly name: "redirectUrl";
626
654
  readonly label: "Redirect URL";
627
655
  readonly inputType: "url";
628
656
  readonly placeholder: "Registered OAuth callback URL";
629
- }, {
630
- readonly name: "scope";
631
- readonly label: "Scope";
632
- readonly placeholder: "Space-separated scopes";
633
657
  }];
634
658
  };
635
- readonly description: "Enable the Workspace MCP service plus Gmail, Drive, Calendar, and Chat APIs, then configure OAuth consent and readonly search scopes.";
659
+ readonly description: "Enable the Workspace MCP service plus Gmail, Drive, Calendar, and Chat APIs, then configure OAuth consent and create a web OAuth client.";
636
660
  readonly links: readonly [{
637
661
  readonly label: "Setup guide";
638
662
  readonly url: "https://developers.google.com/workspace/guides/universal-search-mcp";
@@ -730,10 +754,6 @@ declare const MANUAL_MCP_SERVER_CARDS: readonly [{
730
754
  readonly label: "Redirect URL";
731
755
  readonly inputType: "url";
732
756
  readonly placeholder: "Registered OAuth callback URL";
733
- }, {
734
- readonly name: "scope";
735
- readonly label: "Scope";
736
- readonly placeholder: "Space-separated scopes";
737
757
  }];
738
758
  };
739
759
  readonly description: "Create a HubSpot MCP Auth App, configure the redirect URL, and connect with OAuth credentials from a PKCE-capable client.";
@@ -766,10 +786,6 @@ declare const MANUAL_MCP_SERVER_CARDS: readonly [{
766
786
  readonly label: "Redirect URL";
767
787
  readonly inputType: "url";
768
788
  readonly placeholder: "Registered OAuth callback URL";
769
- }, {
770
- readonly name: "scope";
771
- readonly label: "Scope";
772
- readonly placeholder: "Space-separated scopes";
773
789
  }];
774
790
  };
775
791
  readonly description: "Provision the preview tenant resource, register the client, grant delegated MCP permissions, and connect with Microsoft Entra OAuth.";
@@ -821,13 +837,9 @@ declare const MANUAL_MCP_SERVER_CARDS: readonly [{
821
837
  readonly label: "Redirect URL";
822
838
  readonly inputType: "url";
823
839
  readonly placeholder: "Registered OAuth callback URL";
824
- }, {
825
- readonly name: "scope";
826
- readonly label: "Scope";
827
- readonly placeholder: "Space-separated scopes";
828
840
  }];
829
841
  };
830
- readonly description: "Create a Salesforce External Client App with mcp_api and refresh_token scopes, require PKCE, activate the hosted server, and connect with the consumer key.";
842
+ readonly description: "Create a Salesforce External Client App, require PKCE, activate the hosted server, and connect with the consumer key.";
831
843
  readonly links: readonly [{
832
844
  readonly label: "Client connection";
833
845
  readonly url: "https://developer.salesforce.com/docs/platform/hosted-mcp-servers/guide/client-connection-overview.html";
@@ -866,13 +878,9 @@ declare const MANUAL_MCP_SERVER_CARDS: readonly [{
866
878
  readonly label: "Redirect URL";
867
879
  readonly inputType: "url";
868
880
  readonly placeholder: "Registered OAuth callback URL";
869
- }, {
870
- readonly name: "scope";
871
- readonly label: "Scope";
872
- readonly placeholder: "Space-separated scopes";
873
881
  }];
874
882
  };
875
- readonly description: "Create or reuse a Slack app, enable MCP access, add user scopes and redirect URLs, then connect with the app client ID and secret.";
883
+ readonly description: "Create or reuse a Slack app, enable MCP access, configure redirect URLs, then connect with the app client ID and secret.";
876
884
  readonly links: readonly [{
877
885
  readonly label: "Slack apps";
878
886
  readonly url: "https://api.slack.com/apps";
@@ -911,13 +919,9 @@ declare const MANUAL_MCP_SERVER_CARDS: readonly [{
911
919
  readonly label: "Redirect URL";
912
920
  readonly inputType: "url";
913
921
  readonly placeholder: "Registered OAuth callback URL";
914
- }, {
915
- readonly name: "scope";
916
- readonly label: "Scope";
917
- readonly placeholder: "Space-separated scopes";
918
922
  }];
919
923
  };
920
- readonly description: "Create a Zoom Marketplace General app, add the MCP product scopes, configure the client redirect URL, and connect with OAuth credentials.";
924
+ readonly description: "Create a Zoom Marketplace General app, enable the MCP product, configure the client redirect URL, and connect with OAuth credentials.";
921
925
  readonly links: readonly [{
922
926
  readonly label: "Setup guide";
923
927
  readonly url: "https://developers.zoom.us/docs/mcp/servers/connect-to-zoom-mcp-servers/";
@@ -932,4 +936,4 @@ declare const MANUAL_MCP_SERVER_CARDS: readonly [{
932
936
  }];
933
937
  declare const DEFAULT_MCP_SERVER_CARDS: readonly McpServerCard[];
934
938
  //#endregion
935
- export { CUSTOM_MCP_SERVER_CARD, DCR_MCP_SERVER_CARDS, DEFAULT_MCP_SERVER_CARDS, MANUAL_MCP_SERVER_CARDS, MCP_SERVER_SETUP_AUTH, McpServerCard, McpServerCardIcon, McpServerManualSetup, McpServerPickerStatus, McpServerSetupAuth, McpServerSetupAuthField, McpServerSetupAuthFieldName, McpServerSetupLink, getMcpServerIconSrc, inferMcpServerFaviconUrl };
939
+ export { CUSTOM_MCP_SERVER_CARD, DCR_MCP_SERVER_CARDS, DEFAULT_MCP_SERVER_CARDS, MANUAL_MCP_SERVER_CARDS, MCP_SERVER_SETUP_AUTH, McpServerCard, McpServerCardIcon, McpServerManualSetup, McpServerSetupAuth, McpServerSetupAuthField, McpServerSetupAuthFieldName, McpServerSetupLink, getMcpServerEntry, getMcpServerIconSrc, getMcpServerRuntimeState, inferMcpServerFaviconUrl };
@@ -1,4 +1,40 @@
1
1
  //#region src/utils/mcp-server-catalog.ts
2
+ /**
3
+ * Read the complete state emitted by the pinned Agents runtime.
4
+ *
5
+ * Agents 0.17.4 can return `not-connected` from `getMcpServers()` even though
6
+ * that value is missing from its exported `MCPServer["state"]` declaration.
7
+ * Keep the unavoidable compatibility assertion at this one SDK boundary.
8
+ */
9
+ function getMcpServerRuntimeState(server) {
10
+ return server.state;
11
+ }
12
+ /**
13
+ * Match a host-owned stable registration identity to an upstream Agents entry.
14
+ *
15
+ * `normalizeServerId` deliberately stays in the host. Importing it from the
16
+ * optional `agents` runtime also loads Worker-only `cloudflare:` modules (and
17
+ * the `agents/mcp/client` subpath loads the full MCP client). This browser UI
18
+ * therefore compares the already-normalized ID supplied by the host, then uses
19
+ * Agents' registration `(name, canonical URL)` identity only to recognize a
20
+ * legacy/generated ID.
21
+ */
22
+ function getMcpServerEntry(server, mcp) {
23
+ if (!mcp || !server.url) return void 0;
24
+ const serverUrl = normalizeMcpServerUrl(server.url);
25
+ if (!serverUrl) return void 0;
26
+ const entryById = mcp.servers[server.id];
27
+ if (entryById) return normalizeMcpServerUrl(entryById.server_url) === serverUrl ? [server.id, entryById] : void 0;
28
+ const entriesByRegistration = Object.entries(mcp.servers).filter(([, entry]) => entry.name === server.id && normalizeMcpServerUrl(entry.server_url) === serverUrl);
29
+ return entriesByRegistration.length === 1 ? entriesByRegistration[0] : void 0;
30
+ }
31
+ function normalizeMcpServerUrl(url) {
32
+ try {
33
+ return new URL(url).href;
34
+ } catch {
35
+ return;
36
+ }
37
+ }
2
38
  const DCR_CATEGORY = "Auto";
3
39
  const MANUAL_CATEGORY = "Manual";
4
40
  const MCP_SERVER_SETUP_AUTH = {
@@ -16,25 +52,17 @@ const MCP_SERVER_SETUP_AUTH = {
16
52
  manualOAuthClient: {
17
53
  type: "manual_oauth_client",
18
54
  label: "OAuth client ID",
19
- fields: [
20
- {
21
- name: "clientId",
22
- label: "OAuth client ID",
23
- placeholder: "Client ID",
24
- required: true
25
- },
26
- {
27
- name: "redirectUrl",
28
- label: "Redirect URL",
29
- inputType: "url",
30
- placeholder: "Registered OAuth callback URL"
31
- },
32
- {
33
- name: "scope",
34
- label: "Scope",
35
- placeholder: "Space-separated scopes"
36
- }
37
- ]
55
+ fields: [{
56
+ name: "clientId",
57
+ label: "OAuth client ID",
58
+ placeholder: "Client ID",
59
+ required: true
60
+ }, {
61
+ name: "redirectUrl",
62
+ label: "Redirect URL",
63
+ inputType: "url",
64
+ placeholder: "Registered OAuth callback URL"
65
+ }]
38
66
  },
39
67
  manualOAuthClientSecret: {
40
68
  type: "manual_oauth_client",
@@ -58,11 +86,6 @@ const MCP_SERVER_SETUP_AUTH = {
58
86
  label: "Redirect URL",
59
87
  inputType: "url",
60
88
  placeholder: "Registered OAuth callback URL"
61
- },
62
- {
63
- name: "scope",
64
- label: "Scope",
65
- placeholder: "Space-separated scopes"
66
89
  }
67
90
  ]
68
91
  },
@@ -73,7 +96,7 @@ const MCP_SERVER_SETUP_AUTH = {
73
96
  }
74
97
  };
75
98
  const CUSTOM_MCP_SERVER_CARD = {
76
- id: "localMcp",
99
+ id: "localmcp",
77
100
  name: "Custom MCP",
78
101
  url: "",
79
102
  description: "Connect any Streamable HTTP MCP server",
@@ -402,8 +425,8 @@ const MANUAL_MCP_SERVER_CARDS = [
402
425
  category: MANUAL_CATEGORY,
403
426
  icon: "https://cdn.simpleicons.org/gmail/EA4335",
404
427
  manualSetup: {
405
- auth: MCP_SERVER_SETUP_AUTH.manualOAuthClient,
406
- description: "Enable Gmail and Gmail MCP APIs, configure OAuth consent, add Gmail read/compose scopes, and create a web OAuth client.",
428
+ auth: MCP_SERVER_SETUP_AUTH.manualOAuthClientSecret,
429
+ description: "Enable Gmail and Gmail MCP APIs, configure OAuth consent, and create a web OAuth client.",
407
430
  links: [
408
431
  {
409
432
  label: "Setup guide",
@@ -432,8 +455,8 @@ const MANUAL_MCP_SERVER_CARDS = [
432
455
  category: MANUAL_CATEGORY,
433
456
  icon: "https://cdn.simpleicons.org/googlecalendar/4285F4",
434
457
  manualSetup: {
435
- auth: MCP_SERVER_SETUP_AUTH.manualOAuthClient,
436
- description: "Enable Calendar and Calendar MCP APIs, configure OAuth consent, add calendar read/freebusy scopes, and create a web OAuth client.",
458
+ auth: MCP_SERVER_SETUP_AUTH.manualOAuthClientSecret,
459
+ description: "Enable Calendar and Calendar MCP APIs, configure OAuth consent, and create a web OAuth client.",
437
460
  links: [
438
461
  {
439
462
  label: "Setup guide",
@@ -462,8 +485,8 @@ const MANUAL_MCP_SERVER_CARDS = [
462
485
  category: MANUAL_CATEGORY,
463
486
  icon: "https://cdn.simpleicons.org/googlechat/00AC47",
464
487
  manualSetup: {
465
- auth: MCP_SERVER_SETUP_AUTH.manualOAuthClient,
466
- description: "Enable Chat and Chat MCP APIs, configure a Chat app, add Chat read/send scopes, and create a web OAuth client.",
488
+ auth: MCP_SERVER_SETUP_AUTH.manualOAuthClientSecret,
489
+ description: "Enable Chat and Chat MCP APIs, configure a Chat app, and create a web OAuth client.",
467
490
  links: [
468
491
  {
469
492
  label: "Setup guide",
@@ -492,8 +515,8 @@ const MANUAL_MCP_SERVER_CARDS = [
492
515
  category: MANUAL_CATEGORY,
493
516
  icon: "https://cdn.simpleicons.org/googledrive/4285F4",
494
517
  manualSetup: {
495
- auth: MCP_SERVER_SETUP_AUTH.manualOAuthClient,
496
- description: "Enable Drive and Drive MCP APIs, configure OAuth consent, add Drive read/file scopes, and create a web OAuth client.",
518
+ auth: MCP_SERVER_SETUP_AUTH.manualOAuthClientSecret,
519
+ description: "Enable Drive and Drive MCP APIs, configure OAuth consent, and create a web OAuth client.",
497
520
  links: [
498
521
  {
499
522
  label: "Setup guide",
@@ -522,8 +545,8 @@ const MANUAL_MCP_SERVER_CARDS = [
522
545
  category: MANUAL_CATEGORY,
523
546
  icon: "https://cdn.simpleicons.org/google/4285F4",
524
547
  manualSetup: {
525
- auth: MCP_SERVER_SETUP_AUTH.manualOAuthClient,
526
- description: "Enable People API, configure OAuth consent, add contacts/profile/directory scopes, and create a web OAuth client.",
548
+ auth: MCP_SERVER_SETUP_AUTH.manualOAuthClientSecret,
549
+ description: "Enable People API, configure OAuth consent, and create a web OAuth client.",
527
550
  links: [
528
551
  {
529
552
  label: "Setup guide",
@@ -552,8 +575,8 @@ const MANUAL_MCP_SERVER_CARDS = [
552
575
  category: MANUAL_CATEGORY,
553
576
  icon: "https://cdn.simpleicons.org/google/4285F4",
554
577
  manualSetup: {
555
- auth: MCP_SERVER_SETUP_AUTH.manualOAuthClient,
556
- description: "Enable the Workspace MCP service plus Gmail, Drive, Calendar, and Chat APIs, then configure OAuth consent and readonly search scopes.",
578
+ auth: MCP_SERVER_SETUP_AUTH.manualOAuthClientSecret,
579
+ description: "Enable the Workspace MCP service plus Gmail, Drive, Calendar, and Chat APIs, then configure OAuth consent and create a web OAuth client.",
557
580
  links: [
558
581
  {
559
582
  label: "Setup guide",
@@ -675,7 +698,7 @@ const MANUAL_MCP_SERVER_CARDS = [
675
698
  icon: "https://www.salesforce.com/favicon.ico",
676
699
  manualSetup: {
677
700
  auth: MCP_SERVER_SETUP_AUTH.manualOAuthClient,
678
- description: "Create a Salesforce External Client App with mcp_api and refresh_token scopes, require PKCE, activate the hosted server, and connect with the consumer key.",
701
+ description: "Create a Salesforce External Client App, require PKCE, activate the hosted server, and connect with the consumer key.",
679
702
  links: [
680
703
  {
681
704
  label: "Client connection",
@@ -701,7 +724,7 @@ const MANUAL_MCP_SERVER_CARDS = [
701
724
  icon: "https://slack.com/favicon.ico",
702
725
  manualSetup: {
703
726
  auth: MCP_SERVER_SETUP_AUTH.manualOAuthClientSecret,
704
- description: "Create or reuse a Slack app, enable MCP access, add user scopes and redirect URLs, then connect with the app client ID and secret.",
727
+ description: "Create or reuse a Slack app, enable MCP access, configure redirect URLs, then connect with the app client ID and secret.",
705
728
  links: [
706
729
  {
707
730
  label: "Slack apps",
@@ -727,7 +750,7 @@ const MANUAL_MCP_SERVER_CARDS = [
727
750
  icon: "https://cdn.simpleicons.org/zoom/0B5CFF",
728
751
  manualSetup: {
729
752
  auth: MCP_SERVER_SETUP_AUTH.manualOAuthClientSecret,
730
- description: "Create a Zoom Marketplace General app, add the MCP product scopes, configure the client redirect URL, and connect with OAuth credentials.",
753
+ description: "Create a Zoom Marketplace General app, enable the MCP product, configure the client redirect URL, and connect with OAuth credentials.",
731
754
  links: [
732
755
  {
733
756
  label: "Setup guide",
@@ -751,4 +774,4 @@ const DEFAULT_MCP_SERVER_CARDS = [
751
774
  ...MANUAL_MCP_SERVER_CARDS
752
775
  ];
753
776
  //#endregion
754
- export { CUSTOM_MCP_SERVER_CARD, DCR_MCP_SERVER_CARDS, DEFAULT_MCP_SERVER_CARDS, MANUAL_MCP_SERVER_CARDS, MCP_SERVER_SETUP_AUTH, getMcpServerIconSrc, inferMcpServerFaviconUrl };
777
+ export { CUSTOM_MCP_SERVER_CARD, DCR_MCP_SERVER_CARDS, DEFAULT_MCP_SERVER_CARDS, MANUAL_MCP_SERVER_CARDS, MCP_SERVER_SETUP_AUTH, getMcpServerEntry, getMcpServerIconSrc, getMcpServerRuntimeState, inferMcpServerFaviconUrl };
@@ -1,4 +1,4 @@
1
- import { A as CodeBlockLanguage } from "../CodeBlock-DUh9WOGo.js";
1
+ import { A as CodeBlockLanguage } from "../CodeBlock-BRajW4QU.js";
2
2
 
3
3
  //#region src/utils/structured-code.d.ts
4
4
  interface StructuredCodeDisplay {
@@ -0,0 +1,22 @@
1
+ //#region src/utils/theme.d.ts
2
+ declare const THEME_STORAGE_KEY = "mcp-b-theme";
3
+ declare const themePreferences: readonly ["system", "light", "dark"];
4
+ type ThemePreference = (typeof themePreferences)[number];
5
+ type ResolvedTheme = Exclude<ThemePreference, "system">;
6
+ declare function isThemePreference(value: unknown): value is ThemePreference;
7
+ declare function resolveThemePreference(preference: ThemePreference, targetWindow?: Pick<Window, "matchMedia">): ResolvedTheme;
8
+ declare function readThemePreference(storageKey?: string, targetStorage?: Storage): ThemePreference;
9
+ declare function writeThemePreference(preference: ThemePreference, storageKey?: string, targetStorage?: Storage): void;
10
+ /**
11
+ * Applies an explicit preference without resolving System into an attribute.
12
+ * Leaving data-theme absent lets CSS respond to operating-system changes by itself.
13
+ */
14
+ declare function applyThemePreference(preference: ThemePreference, targetDocument?: Document): ResolvedTheme;
15
+ /**
16
+ * Generates a CSP-compatible inline head script body that restores a saved
17
+ * preference before styles render. Supply the returned string as text content
18
+ * of a nonce-bearing script immediately after the color-scheme meta element.
19
+ */
20
+ declare function getThemeInitializationScript(storageKey?: string): string;
21
+ //#endregion
22
+ export { ResolvedTheme, THEME_STORAGE_KEY, ThemePreference, applyThemePreference, getThemeInitializationScript, isThemePreference, readThemePreference, resolveThemePreference, themePreferences, writeThemePreference };
@@ -0,0 +1,55 @@
1
+ //#region src/utils/theme.ts
2
+ const THEME_STORAGE_KEY = "mcp-b-theme";
3
+ const themePreferences = [
4
+ "system",
5
+ "light",
6
+ "dark"
7
+ ];
8
+ function isThemePreference(value) {
9
+ return typeof value === "string" && themePreferences.includes(value);
10
+ }
11
+ function resolveThemePreference(preference, targetWindow) {
12
+ if (preference !== "system") return preference;
13
+ return (targetWindow ?? (typeof window === "undefined" ? void 0 : window))?.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
14
+ }
15
+ function readThemePreference(storageKey = THEME_STORAGE_KEY, targetStorage) {
16
+ try {
17
+ const storedPreference = (targetStorage ?? localStorage).getItem(storageKey);
18
+ return isThemePreference(storedPreference) ? storedPreference : "system";
19
+ } catch {
20
+ return "system";
21
+ }
22
+ }
23
+ function writeThemePreference(preference, storageKey = THEME_STORAGE_KEY, targetStorage) {
24
+ try {
25
+ const storage = targetStorage ?? localStorage;
26
+ if (preference === "system") storage.removeItem(storageKey);
27
+ else storage.setItem(storageKey, preference);
28
+ } catch {}
29
+ }
30
+ /**
31
+ * Applies an explicit preference without resolving System into an attribute.
32
+ * Leaving data-theme absent lets CSS respond to operating-system changes by itself.
33
+ */
34
+ function applyThemePreference(preference, targetDocument = document) {
35
+ if (preference === "system") delete targetDocument.documentElement.dataset.theme;
36
+ else targetDocument.documentElement.dataset.theme = preference;
37
+ let colorSchemeMeta = targetDocument.querySelector("meta[name=\"color-scheme\"]");
38
+ if (!colorSchemeMeta) {
39
+ colorSchemeMeta = targetDocument.createElement("meta");
40
+ colorSchemeMeta.name = "color-scheme";
41
+ targetDocument.head.prepend(colorSchemeMeta);
42
+ }
43
+ colorSchemeMeta.content = preference === "system" ? "light dark" : preference;
44
+ return resolveThemePreference(preference, targetDocument.defaultView ?? window);
45
+ }
46
+ /**
47
+ * Generates a CSP-compatible inline head script body that restores a saved
48
+ * preference before styles render. Supply the returned string as text content
49
+ * of a nonce-bearing script immediately after the color-scheme meta element.
50
+ */
51
+ function getThemeInitializationScript(storageKey = THEME_STORAGE_KEY) {
52
+ return `{try{const k=${JSON.stringify(storageKey).replaceAll("<", "\\u003c")};const v=localStorage.getItem(k);const d=document.documentElement;const m=document.querySelector('meta[name="color-scheme"]');if(v==="light"||v==="dark"){d.dataset.theme=v;if(m)m.content=v}else{delete d.dataset.theme;if(m)m.content="light dark"}}catch{}}`;
53
+ }
54
+ //#endregion
55
+ export { THEME_STORAGE_KEY, applyThemePreference, getThemeInitializationScript, isThemePreference, readThemePreference, resolveThemePreference, themePreferences, writeThemePreference };