@hcu-lab.me/mcp-device 1.0.10 → 1.0.12

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 (491) hide show
  1. package/PRIVACY.md +21 -0
  2. package/README.md +57 -2
  3. package/SECURITY.md +67 -0
  4. package/config/revoked-approvals.json +1 -0
  5. package/control-plane/config/mcp-servers.example.toml +52 -0
  6. package/control-plane/config/mcp-servers.toml +52 -0
  7. package/control-plane/contracts/device-public-contract-v1.json +733 -0
  8. package/control-plane/scripts/GATEWAY-LICENSE.txt +7 -0
  9. package/control-plane/scripts/account-http.mjs +220 -0
  10. package/control-plane/scripts/account-store.mjs +368 -0
  11. package/control-plane/scripts/admin.mjs +68 -0
  12. package/control-plane/scripts/auth-session.mjs +411 -0
  13. package/control-plane/scripts/authenticated-mcp-wrapper.mjs +1281 -0
  14. package/control-plane/scripts/benchmark-command.mjs +9 -0
  15. package/control-plane/scripts/benchmark-mcp-catalog.mjs +174 -0
  16. package/control-plane/scripts/catalog-budget.mjs +87 -0
  17. package/control-plane/scripts/check-device-public-contract.mjs +20 -0
  18. package/control-plane/scripts/custom-tools/index.mjs +221 -0
  19. package/control-plane/scripts/custom-tools/path-utils.mjs +117 -0
  20. package/control-plane/scripts/custom-tools/response-utils.mjs +34 -0
  21. package/control-plane/scripts/dashboard-http.mjs +598 -0
  22. package/control-plane/scripts/device-access-policy.mjs +205 -0
  23. package/control-plane/scripts/device-admin.mjs +43 -0
  24. package/control-plane/scripts/device-audit.mjs +63 -0
  25. package/control-plane/scripts/device-broker.mjs +1461 -0
  26. package/control-plane/scripts/device-execution-tool-definitions.mjs +217 -0
  27. package/control-plane/scripts/device-inventory.mjs +128 -0
  28. package/control-plane/scripts/device-pairing-http.mjs +109 -0
  29. package/control-plane/scripts/device-pairing-store.mjs +245 -0
  30. package/control-plane/scripts/device-public-contract.mjs +165 -0
  31. package/control-plane/scripts/device-release.mjs +95 -0
  32. package/control-plane/scripts/device-secure-transport.mjs +128 -0
  33. package/control-plane/scripts/device-store.mjs +283 -0
  34. package/control-plane/scripts/device-usage.mjs +657 -0
  35. package/control-plane/scripts/embedded-device.mjs +149 -0
  36. package/control-plane/scripts/enduser-ui.mjs +45 -0
  37. package/control-plane/scripts/external-tool-broker.mjs +179 -0
  38. package/control-plane/scripts/oauth-authorization-server.mjs +589 -0
  39. package/control-plane/scripts/operator-dashboard-http.mjs +81 -0
  40. package/control-plane/scripts/project-inspection.mjs +227 -0
  41. package/control-plane/scripts/projects/project-id.mjs +69 -0
  42. package/control-plane/scripts/projects/trusted-roots-projects.mjs +375 -0
  43. package/control-plane/scripts/prompts/index.mjs +60 -0
  44. package/control-plane/scripts/remote-process-sessions.mjs +78 -0
  45. package/control-plane/scripts/remote-tool-result.mjs +9 -0
  46. package/control-plane/scripts/resources/index.mjs +166 -0
  47. package/control-plane/scripts/runtime-profile.mjs +54 -0
  48. package/control-plane/scripts/shell-tool-descriptor.mjs +17 -0
  49. package/control-plane/scripts/skill-source-safety.mjs +46 -0
  50. package/control-plane/scripts/skills/README.md +70 -0
  51. package/control-plane/scripts/skills/_upstream_licenses/anthropic-THIRD_PARTY_NOTICES.md +405 -0
  52. package/control-plane/scripts/skills/_upstream_licenses/hallmark-LICENSE.txt +21 -0
  53. package/control-plane/scripts/skills/_upstream_licenses/ponytail-LICENSE.txt +21 -0
  54. package/control-plane/scripts/skills/_upstream_licenses/stitch-skills-LICENSE.txt +201 -0
  55. package/control-plane/scripts/skills/_upstream_licenses/superpowers-LICENSE.txt +21 -0
  56. package/control-plane/scripts/skills/algorithmic-art/LICENSE.txt +202 -0
  57. package/control-plane/scripts/skills/algorithmic-art/SKILL.md +405 -0
  58. package/control-plane/scripts/skills/algorithmic-art/templates/generator_template.js +223 -0
  59. package/control-plane/scripts/skills/algorithmic-art/templates/viewer.html +599 -0
  60. package/control-plane/scripts/skills/brainstorming/SKILL.md +285 -0
  61. package/control-plane/scripts/skills/brainstorming/scripts/frame-template.html +213 -0
  62. package/control-plane/scripts/skills/brainstorming/scripts/helper.js +167 -0
  63. package/control-plane/scripts/skills/brainstorming/scripts/server.cjs +723 -0
  64. package/control-plane/scripts/skills/brainstorming/scripts/start-server.sh +209 -0
  65. package/control-plane/scripts/skills/brainstorming/scripts/stop-server.sh +120 -0
  66. package/control-plane/scripts/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
  67. package/control-plane/scripts/skills/brainstorming/visual-companion.md +299 -0
  68. package/control-plane/scripts/skills/brand-guidelines/LICENSE.txt +202 -0
  69. package/control-plane/scripts/skills/brand-guidelines/SKILL.md +73 -0
  70. package/control-plane/scripts/skills/claude-api/LICENSE.txt +202 -0
  71. package/control-plane/scripts/skills/claude-api/SKILL.md +570 -0
  72. package/control-plane/scripts/skills/claude-api/csharp/claude-api/README.md +362 -0
  73. package/control-plane/scripts/skills/claude-api/csharp/claude-api/batches.md +14 -0
  74. package/control-plane/scripts/skills/claude-api/csharp/claude-api/files-api.md +25 -0
  75. package/control-plane/scripts/skills/claude-api/csharp/claude-api/streaming.md +28 -0
  76. package/control-plane/scripts/skills/claude-api/csharp/claude-api/tool-use.md +164 -0
  77. package/control-plane/scripts/skills/claude-api/curl/examples.md +256 -0
  78. package/control-plane/scripts/skills/claude-api/curl/managed-agents.md +371 -0
  79. package/control-plane/scripts/skills/claude-api/go/claude-api/README.md +188 -0
  80. package/control-plane/scripts/skills/claude-api/go/claude-api/files-api.md +23 -0
  81. package/control-plane/scripts/skills/claude-api/go/claude-api/streaming.md +43 -0
  82. package/control-plane/scripts/skills/claude-api/go/claude-api/tool-use.md +220 -0
  83. package/control-plane/scripts/skills/claude-api/go/managed-agents/README.md +564 -0
  84. package/control-plane/scripts/skills/claude-api/java/claude-api/README.md +238 -0
  85. package/control-plane/scripts/skills/claude-api/java/claude-api/files-api.md +27 -0
  86. package/control-plane/scripts/skills/claude-api/java/claude-api/streaming.md +24 -0
  87. package/control-plane/scripts/skills/claude-api/java/claude-api/tool-use.md +228 -0
  88. package/control-plane/scripts/skills/claude-api/java/managed-agents/README.md +443 -0
  89. package/control-plane/scripts/skills/claude-api/php/claude-api/README.md +174 -0
  90. package/control-plane/scripts/skills/claude-api/php/claude-api/batches.md +15 -0
  91. package/control-plane/scripts/skills/claude-api/php/claude-api/files-api.md +13 -0
  92. package/control-plane/scripts/skills/claude-api/php/claude-api/streaming.md +27 -0
  93. package/control-plane/scripts/skills/claude-api/php/claude-api/tool-use.md +253 -0
  94. package/control-plane/scripts/skills/claude-api/php/managed-agents/README.md +443 -0
  95. package/control-plane/scripts/skills/claude-api/python/claude-api/README.md +565 -0
  96. package/control-plane/scripts/skills/claude-api/python/claude-api/batches.md +198 -0
  97. package/control-plane/scripts/skills/claude-api/python/claude-api/files-api.md +170 -0
  98. package/control-plane/scripts/skills/claude-api/python/claude-api/sdk-upgrade.md +286 -0
  99. package/control-plane/scripts/skills/claude-api/python/claude-api/streaming.md +179 -0
  100. package/control-plane/scripts/skills/claude-api/python/claude-api/tool-use.md +627 -0
  101. package/control-plane/scripts/skills/claude-api/python/managed-agents/README.md +335 -0
  102. package/control-plane/scripts/skills/claude-api/ruby/claude-api/README.md +134 -0
  103. package/control-plane/scripts/skills/claude-api/ruby/claude-api/streaming.md +16 -0
  104. package/control-plane/scripts/skills/claude-api/ruby/claude-api/tool-use.md +41 -0
  105. package/control-plane/scripts/skills/claude-api/ruby/managed-agents/README.md +394 -0
  106. package/control-plane/scripts/skills/claude-api/shared/admin-api.md +179 -0
  107. package/control-plane/scripts/skills/claude-api/shared/agent-design.md +101 -0
  108. package/control-plane/scripts/skills/claude-api/shared/anthropic-cli.md +269 -0
  109. package/control-plane/scripts/skills/claude-api/shared/claude-platform-on-aws.md +59 -0
  110. package/control-plane/scripts/skills/claude-api/shared/cost-optimization.md +233 -0
  111. package/control-plane/scripts/skills/claude-api/shared/error-codes.md +262 -0
  112. package/control-plane/scripts/skills/claude-api/shared/live-sources.md +166 -0
  113. package/control-plane/scripts/skills/claude-api/shared/managed-agents-api-reference.md +455 -0
  114. package/control-plane/scripts/skills/claude-api/shared/managed-agents-client-patterns.md +220 -0
  115. package/control-plane/scripts/skills/claude-api/shared/managed-agents-core.md +359 -0
  116. package/control-plane/scripts/skills/claude-api/shared/managed-agents-environments.md +226 -0
  117. package/control-plane/scripts/skills/claude-api/shared/managed-agents-events.md +290 -0
  118. package/control-plane/scripts/skills/claude-api/shared/managed-agents-memory.md +201 -0
  119. package/control-plane/scripts/skills/claude-api/shared/managed-agents-multiagent.md +260 -0
  120. package/control-plane/scripts/skills/claude-api/shared/managed-agents-onboarding.md +82 -0
  121. package/control-plane/scripts/skills/claude-api/shared/managed-agents-outcomes.md +108 -0
  122. package/control-plane/scripts/skills/claude-api/shared/managed-agents-overview.md +77 -0
  123. package/control-plane/scripts/skills/claude-api/shared/managed-agents-scheduled-deployments.md +156 -0
  124. package/control-plane/scripts/skills/claude-api/shared/managed-agents-self-hosted-sandboxes.md +282 -0
  125. package/control-plane/scripts/skills/claude-api/shared/managed-agents-tools.md +504 -0
  126. package/control-plane/scripts/skills/claude-api/shared/managed-agents-webhooks.md +143 -0
  127. package/control-plane/scripts/skills/claude-api/shared/model-migration.md +1872 -0
  128. package/control-plane/scripts/skills/claude-api/shared/models.md +142 -0
  129. package/control-plane/scripts/skills/claude-api/shared/platform-availability.md +52 -0
  130. package/control-plane/scripts/skills/claude-api/shared/prompt-audit.md +223 -0
  131. package/control-plane/scripts/skills/claude-api/shared/prompt-caching.md +292 -0
  132. package/control-plane/scripts/skills/claude-api/shared/token-counting.md +56 -0
  133. package/control-plane/scripts/skills/claude-api/shared/tool-use-concepts.md +526 -0
  134. package/control-plane/scripts/skills/claude-api/typescript/claude-api/README.md +405 -0
  135. package/control-plane/scripts/skills/claude-api/typescript/claude-api/batches.md +106 -0
  136. package/control-plane/scripts/skills/claude-api/typescript/claude-api/files-api.md +98 -0
  137. package/control-plane/scripts/skills/claude-api/typescript/claude-api/streaming.md +178 -0
  138. package/control-plane/scripts/skills/claude-api/typescript/claude-api/tool-use.md +586 -0
  139. package/control-plane/scripts/skills/claude-api/typescript/managed-agents/README.md +359 -0
  140. package/control-plane/scripts/skills/dispatching-parallel-agents/SKILL.md +167 -0
  141. package/control-plane/scripts/skills/enhance-prompt/README.md +34 -0
  142. package/control-plane/scripts/skills/enhance-prompt/SKILL.md +204 -0
  143. package/control-plane/scripts/skills/enhance-prompt/references/KEYWORDS.md +114 -0
  144. package/control-plane/scripts/skills/executing-plans/SKILL.md +371 -0
  145. package/control-plane/scripts/skills/executing-plans/scripts/task-done +52 -0
  146. package/control-plane/scripts/skills/executing-plans/scripts/task-start +28 -0
  147. package/control-plane/scripts/skills/extract-design-md/SKILL.md +358 -0
  148. package/control-plane/scripts/skills/extract-design-md/examples/DESIGN.md +210 -0
  149. package/control-plane/scripts/skills/extract-design-md/references/angular.md +122 -0
  150. package/control-plane/scripts/skills/extract-design-md/references/plain-css.md +161 -0
  151. package/control-plane/scripts/skills/extract-design-md/references/react-tailwind.md +157 -0
  152. package/control-plane/scripts/skills/extract-design-md/references/svelte.md +101 -0
  153. package/control-plane/scripts/skills/extract-design-md/references/vue.md +107 -0
  154. package/control-plane/scripts/skills/finishing-a-development-branch/SKILL.md +225 -0
  155. package/control-plane/scripts/skills/frontend-design/LICENSE.txt +177 -0
  156. package/control-plane/scripts/skills/frontend-design/SKILL.md +71 -0
  157. package/control-plane/scripts/skills/hallmark/SKILL.md +558 -0
  158. package/control-plane/scripts/skills/hallmark/references/anti-patterns.md +418 -0
  159. package/control-plane/scripts/skills/hallmark/references/assets.md +406 -0
  160. package/control-plane/scripts/skills/hallmark/references/color.md +95 -0
  161. package/control-plane/scripts/skills/hallmark/references/component-cookbook.md +263 -0
  162. package/control-plane/scripts/skills/hallmark/references/components/c1-outlined-chip.md +12 -0
  163. package/control-plane/scripts/skills/hallmark/references/components/c2-inline-form-as-cta.md +16 -0
  164. package/control-plane/scripts/skills/hallmark/references/components/c3-typographic-link.md +8 -0
  165. package/control-plane/scripts/skills/hallmark/references/components/c4-sticky-bottom-bar.md +16 -0
  166. package/control-plane/scripts/skills/hallmark/references/components/f1-bento-grid.md +20 -0
  167. package/control-plane/scripts/skills/hallmark/references/components/f2-sticky-scroll-stack.md +20 -0
  168. package/control-plane/scripts/skills/hallmark/references/components/f3-tabular-spec-sheet.md +11 -0
  169. package/control-plane/scripts/skills/hallmark/references/components/f4-step-sequence.md +11 -0
  170. package/control-plane/scripts/skills/hallmark/references/components/f5-annotated-screenshot.md +11 -0
  171. package/control-plane/scripts/skills/hallmark/references/components/f6-product-card-grid.md +41 -0
  172. package/control-plane/scripts/skills/hallmark/references/components/ft1-mast-headed.md +13 -0
  173. package/control-plane/scripts/skills/hallmark/references/components/ft2-inline-rule-single-line.md +10 -0
  174. package/control-plane/scripts/skills/hallmark/references/components/ft3-index-style-category-list.md +12 -0
  175. package/control-plane/scripts/skills/hallmark/references/components/ft4-dense-typographic.md +10 -0
  176. package/control-plane/scripts/skills/hallmark/references/components/ft5-statement.md +21 -0
  177. package/control-plane/scripts/skills/hallmark/references/components/ft6-letter-close.md +19 -0
  178. package/control-plane/scripts/skills/hallmark/references/components/ft7-newsletter-first.md +27 -0
  179. package/control-plane/scripts/skills/hallmark/references/components/ft8-marquee-scroll.md +25 -0
  180. package/control-plane/scripts/skills/hallmark/references/components/h1-marquee.md +15 -0
  181. package/control-plane/scripts/skills/hallmark/references/components/h2-split-diptych.md +15 -0
  182. package/control-plane/scripts/skills/hallmark/references/components/h3-quote-led.md +11 -0
  183. package/control-plane/scripts/skills/hallmark/references/components/h4-stat-led.md +14 -0
  184. package/control-plane/scripts/skills/hallmark/references/components/h5-letter-hero.md +11 -0
  185. package/control-plane/scripts/skills/hallmark/references/components/h6-photographic-fold.md +16 -0
  186. package/control-plane/scripts/skills/hallmark/references/components/h7-demo-video-clipped-by-viewport-edge.md +27 -0
  187. package/control-plane/scripts/skills/hallmark/references/components/h8-mockup-split-browser-framed.md +23 -0
  188. package/control-plane/scripts/skills/hallmark/references/components/h9-custom-illustration-centerpiece.md +27 -0
  189. package/control-plane/scripts/skills/hallmark/references/components/n1-wordmark-2-links.md +12 -0
  190. package/control-plane/scripts/skills/hallmark/references/components/n10-floating-on-scroll-morph.md +19 -0
  191. package/control-plane/scripts/skills/hallmark/references/components/n11-mega-menu.md +40 -0
  192. package/control-plane/scripts/skills/hallmark/references/components/n12-banner-retract.md +34 -0
  193. package/control-plane/scripts/skills/hallmark/references/components/n13-inline-cmdk-pill.md +39 -0
  194. package/control-plane/scripts/skills/hallmark/references/components/n1b-saas-three-section.md +35 -0
  195. package/control-plane/scripts/skills/hallmark/references/components/n2-floating-chip.md +14 -0
  196. package/control-plane/scripts/skills/hallmark/references/components/n3-side-rail.md +14 -0
  197. package/control-plane/scripts/skills/hallmark/references/components/n4-hidden-behind-k.md +9 -0
  198. package/control-plane/scripts/skills/hallmark/references/components/n5-floating-pill.md +28 -0
  199. package/control-plane/scripts/skills/hallmark/references/components/n6-newspaper-masthead.md +24 -0
  200. package/control-plane/scripts/skills/hallmark/references/components/n7-brutal-slab.md +22 -0
  201. package/control-plane/scripts/skills/hallmark/references/components/n8-terminal-command.md +21 -0
  202. package/control-plane/scripts/skills/hallmark/references/components/n9-edge-aligned-minimal.md +17 -0
  203. package/control-plane/scripts/skills/hallmark/references/components/s1-left-margin-numbered.md +15 -0
  204. package/control-plane/scripts/skills/hallmark/references/components/s2-hanging.md +13 -0
  205. package/control-plane/scripts/skills/hallmark/references/components/s3-sticky-pinned.md +19 -0
  206. package/control-plane/scripts/skills/hallmark/references/components/s4-inline-no-break.md +11 -0
  207. package/control-plane/scripts/skills/hallmark/references/components/s5-bottom-anchored.md +13 -0
  208. package/control-plane/scripts/skills/hallmark/references/components/t1-pull-quote-with-marginalia.md +12 -0
  209. package/control-plane/scripts/skills/hallmark/references/components/t2-logo-wall-hairline.md +19 -0
  210. package/control-plane/scripts/skills/hallmark/references/components/t3-single-huge-quote.md +11 -0
  211. package/control-plane/scripts/skills/hallmark/references/components/t4-numbered-stat-strip.md +14 -0
  212. package/control-plane/scripts/skills/hallmark/references/contract.md +25 -0
  213. package/control-plane/scripts/skills/hallmark/references/copy.md +182 -0
  214. package/control-plane/scripts/skills/hallmark/references/custom-craft.md +626 -0
  215. package/control-plane/scripts/skills/hallmark/references/custom-theme.md +367 -0
  216. package/control-plane/scripts/skills/hallmark/references/design-md.md +116 -0
  217. package/control-plane/scripts/skills/hallmark/references/export-formats.md +329 -0
  218. package/control-plane/scripts/skills/hallmark/references/floating-nav.md +89 -0
  219. package/control-plane/scripts/skills/hallmark/references/genres/atmospheric.md +69 -0
  220. package/control-plane/scripts/skills/hallmark/references/genres/editorial.md +72 -0
  221. package/control-plane/scripts/skills/hallmark/references/genres/modern-minimal.md +71 -0
  222. package/control-plane/scripts/skills/hallmark/references/genres/playful.md +70 -0
  223. package/control-plane/scripts/skills/hallmark/references/hero-enrichment.md +475 -0
  224. package/control-plane/scripts/skills/hallmark/references/imagery-kit.md +170 -0
  225. package/control-plane/scripts/skills/hallmark/references/interaction-and-states.md +208 -0
  226. package/control-plane/scripts/skills/hallmark/references/layout-and-space.md +112 -0
  227. package/control-plane/scripts/skills/hallmark/references/macrostructures/01-bento-grid.md +35 -0
  228. package/control-plane/scripts/skills/hallmark/references/macrostructures/02-long-document.md +34 -0
  229. package/control-plane/scripts/skills/hallmark/references/macrostructures/03-marquee-hero.md +31 -0
  230. package/control-plane/scripts/skills/hallmark/references/macrostructures/04-stat-led.md +34 -0
  231. package/control-plane/scripts/skills/hallmark/references/macrostructures/05-workbench.md +32 -0
  232. package/control-plane/scripts/skills/hallmark/references/macrostructures/06-conversational-faq.md +33 -0
  233. package/control-plane/scripts/skills/hallmark/references/macrostructures/07-manifesto.md +32 -0
  234. package/control-plane/scripts/skills/hallmark/references/macrostructures/08-photographic.md +34 -0
  235. package/control-plane/scripts/skills/hallmark/references/macrostructures/09-quote-led.md +32 -0
  236. package/control-plane/scripts/skills/hallmark/references/macrostructures/10-specimen.md +32 -0
  237. package/control-plane/scripts/skills/hallmark/references/macrostructures/11-catalogue.md +23 -0
  238. package/control-plane/scripts/skills/hallmark/references/macrostructures/12-letter.md +23 -0
  239. package/control-plane/scripts/skills/hallmark/references/macrostructures/13-index-first.md +23 -0
  240. package/control-plane/scripts/skills/hallmark/references/macrostructures/14-narrative-workflow.md +23 -0
  241. package/control-plane/scripts/skills/hallmark/references/macrostructures/15-split-studio.md +23 -0
  242. package/control-plane/scripts/skills/hallmark/references/macrostructures/16-feature-stack.md +23 -0
  243. package/control-plane/scripts/skills/hallmark/references/macrostructures/17-type-specimen.md +23 -0
  244. package/control-plane/scripts/skills/hallmark/references/macrostructures/18-portfolio-grid.md +23 -0
  245. package/control-plane/scripts/skills/hallmark/references/macrostructures/19-map-diagram.md +23 -0
  246. package/control-plane/scripts/skills/hallmark/references/macrostructures/20-ecosystem-index.md +23 -0
  247. package/control-plane/scripts/skills/hallmark/references/macrostructures/21-component-playground.md +23 -0
  248. package/control-plane/scripts/skills/hallmark/references/macrostructures.md +89 -0
  249. package/control-plane/scripts/skills/hallmark/references/microinteractions.md +258 -0
  250. package/control-plane/scripts/skills/hallmark/references/motion.md +109 -0
  251. package/control-plane/scripts/skills/hallmark/references/preview-examples.md +49 -0
  252. package/control-plane/scripts/skills/hallmark/references/responsive.md +138 -0
  253. package/control-plane/scripts/skills/hallmark/references/slop-test.md +192 -0
  254. package/control-plane/scripts/skills/hallmark/references/structure.md +160 -0
  255. package/control-plane/scripts/skills/hallmark/references/study.md +509 -0
  256. package/control-plane/scripts/skills/hallmark/references/themes/carnival.md +301 -0
  257. package/control-plane/scripts/skills/hallmark/references/themes/cobalt.md +146 -0
  258. package/control-plane/scripts/skills/hallmark/references/themes/grid.md +161 -0
  259. package/control-plane/scripts/skills/hallmark/references/themes/hum.md +403 -0
  260. package/control-plane/scripts/skills/hallmark/references/themes/lumen.md +478 -0
  261. package/control-plane/scripts/skills/hallmark/references/typography.md +243 -0
  262. package/control-plane/scripts/skills/hallmark/references/upstream/recipes.md +186 -0
  263. package/control-plane/scripts/skills/hallmark/references/upstream/study-examples.md +176 -0
  264. package/control-plane/scripts/skills/hallmark/references/upstream/tokens.css +1221 -0
  265. package/control-plane/scripts/skills/hallmark/references/verbs/audit.md +25 -0
  266. package/control-plane/scripts/skills/hallmark/references/verbs/redesign.md +269 -0
  267. package/control-plane/scripts/skills/human-comms/SKILL.md +29 -0
  268. package/control-plane/scripts/skills/index.mjs +432 -0
  269. package/control-plane/scripts/skills/internal-comms/LICENSE.txt +202 -0
  270. package/control-plane/scripts/skills/internal-comms/SKILL.md +32 -0
  271. package/control-plane/scripts/skills/internal-comms/examples/3p-updates.md +47 -0
  272. package/control-plane/scripts/skills/internal-comms/examples/company-newsletter.md +65 -0
  273. package/control-plane/scripts/skills/internal-comms/examples/faq-answers.md +30 -0
  274. package/control-plane/scripts/skills/internal-comms/examples/general-comms.md +16 -0
  275. package/control-plane/scripts/skills/mcp-adapter.mjs +94 -0
  276. package/control-plane/scripts/skills/mcp-builder/LICENSE.txt +202 -0
  277. package/control-plane/scripts/skills/mcp-builder/SKILL.md +236 -0
  278. package/control-plane/scripts/skills/mcp-builder/reference/evaluation.md +602 -0
  279. package/control-plane/scripts/skills/mcp-builder/reference/mcp_best_practices.md +249 -0
  280. package/control-plane/scripts/skills/mcp-builder/reference/node_mcp_server.md +970 -0
  281. package/control-plane/scripts/skills/mcp-builder/reference/python_mcp_server.md +719 -0
  282. package/control-plane/scripts/skills/mcp-builder/scripts/connections.py +151 -0
  283. package/control-plane/scripts/skills/mcp-builder/scripts/evaluation.py +373 -0
  284. package/control-plane/scripts/skills/mcp-builder/scripts/example_evaluation.xml +22 -0
  285. package/control-plane/scripts/skills/mcp-builder/scripts/requirements.txt +2 -0
  286. package/control-plane/scripts/skills/ponytail/SKILL.md +120 -0
  287. package/control-plane/scripts/skills/ponytail-audit/SKILL.md +41 -0
  288. package/control-plane/scripts/skills/ponytail-debt/SKILL.md +44 -0
  289. package/control-plane/scripts/skills/ponytail-gain/SKILL.md +50 -0
  290. package/control-plane/scripts/skills/ponytail-help/SKILL.md +71 -0
  291. package/control-plane/scripts/skills/ponytail-review/SKILL.md +57 -0
  292. package/control-plane/scripts/skills/receiving-code-review/SKILL.md +205 -0
  293. package/control-plane/scripts/skills/requesting-code-review/SKILL.md +95 -0
  294. package/control-plane/scripts/skills/requesting-code-review/code-reviewer.md +198 -0
  295. package/control-plane/scripts/skills/skill-creator/LICENSE.txt +202 -0
  296. package/control-plane/scripts/skills/skill-creator/SKILL.md +485 -0
  297. package/control-plane/scripts/skills/skill-creator/agents/analyzer.md +274 -0
  298. package/control-plane/scripts/skills/skill-creator/agents/comparator.md +202 -0
  299. package/control-plane/scripts/skills/skill-creator/agents/grader.md +223 -0
  300. package/control-plane/scripts/skills/skill-creator/assets/eval_review.html +146 -0
  301. package/control-plane/scripts/skills/skill-creator/eval-viewer/generate_review.py +471 -0
  302. package/control-plane/scripts/skills/skill-creator/eval-viewer/viewer.html +1325 -0
  303. package/control-plane/scripts/skills/skill-creator/references/schemas.md +430 -0
  304. package/control-plane/scripts/skills/skill-creator/scripts/__init__.py +0 -0
  305. package/control-plane/scripts/skills/skill-creator/scripts/aggregate_benchmark.py +401 -0
  306. package/control-plane/scripts/skills/skill-creator/scripts/generate_report.py +326 -0
  307. package/control-plane/scripts/skills/skill-creator/scripts/improve_description.py +247 -0
  308. package/control-plane/scripts/skills/skill-creator/scripts/package_skill.py +136 -0
  309. package/control-plane/scripts/skills/skill-creator/scripts/quick_validate.py +103 -0
  310. package/control-plane/scripts/skills/skill-creator/scripts/run_eval.py +310 -0
  311. package/control-plane/scripts/skills/skill-creator/scripts/run_loop.py +328 -0
  312. package/control-plane/scripts/skills/skill-creator/scripts/utils.py +47 -0
  313. package/control-plane/scripts/skills/slack-gif-creator/LICENSE.txt +202 -0
  314. package/control-plane/scripts/skills/slack-gif-creator/SKILL.md +254 -0
  315. package/control-plane/scripts/skills/slack-gif-creator/core/easing.py +234 -0
  316. package/control-plane/scripts/skills/slack-gif-creator/core/frame_composer.py +176 -0
  317. package/control-plane/scripts/skills/slack-gif-creator/core/gif_builder.py +269 -0
  318. package/control-plane/scripts/skills/slack-gif-creator/core/validators.py +136 -0
  319. package/control-plane/scripts/skills/slack-gif-creator/requirements.txt +4 -0
  320. package/control-plane/scripts/skills/sources.json +401 -0
  321. package/control-plane/scripts/skills/sources.lock.json +416 -0
  322. package/control-plane/scripts/skills/subagent-driven-development/SKILL.md +570 -0
  323. package/control-plane/scripts/skills/subagent-driven-development/implementer-prompt.md +154 -0
  324. package/control-plane/scripts/skills/subagent-driven-development/re-review-prompt.md +115 -0
  325. package/control-plane/scripts/skills/subagent-driven-development/scripts/review-package +53 -0
  326. package/control-plane/scripts/skills/subagent-driven-development/scripts/sdd-workspace +82 -0
  327. package/control-plane/scripts/skills/subagent-driven-development/scripts/task-brief +43 -0
  328. package/control-plane/scripts/skills/subagent-driven-development/task-reviewer-prompt.md +207 -0
  329. package/control-plane/scripts/skills/systematic-debugging/CREATION-LOG.md +119 -0
  330. package/control-plane/scripts/skills/systematic-debugging/SKILL.md +283 -0
  331. package/control-plane/scripts/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
  332. package/control-plane/scripts/skills/systematic-debugging/condition-based-waiting.md +115 -0
  333. package/control-plane/scripts/skills/systematic-debugging/defense-in-depth.md +122 -0
  334. package/control-plane/scripts/skills/systematic-debugging/find-polluter.sh +72 -0
  335. package/control-plane/scripts/skills/systematic-debugging/root-cause-tracing.md +169 -0
  336. package/control-plane/scripts/skills/systematic-debugging/test-academic.md +14 -0
  337. package/control-plane/scripts/skills/systematic-debugging/test-pressure-1.md +58 -0
  338. package/control-plane/scripts/skills/systematic-debugging/test-pressure-2.md +68 -0
  339. package/control-plane/scripts/skills/systematic-debugging/test-pressure-3.md +69 -0
  340. package/control-plane/scripts/skills/test-driven-development/SKILL.md +330 -0
  341. package/control-plane/scripts/skills/test-driven-development/writing-good-tests.md +198 -0
  342. package/control-plane/scripts/skills/theme-factory/LICENSE.txt +202 -0
  343. package/control-plane/scripts/skills/theme-factory/SKILL.md +59 -0
  344. package/control-plane/scripts/skills/theme-factory/theme-showcase.pdf +0 -0
  345. package/control-plane/scripts/skills/theme-factory/themes/arctic-frost.md +19 -0
  346. package/control-plane/scripts/skills/theme-factory/themes/botanical-garden.md +19 -0
  347. package/control-plane/scripts/skills/theme-factory/themes/desert-rose.md +19 -0
  348. package/control-plane/scripts/skills/theme-factory/themes/forest-canopy.md +19 -0
  349. package/control-plane/scripts/skills/theme-factory/themes/golden-hour.md +19 -0
  350. package/control-plane/scripts/skills/theme-factory/themes/midnight-galaxy.md +19 -0
  351. package/control-plane/scripts/skills/theme-factory/themes/modern-minimalist.md +19 -0
  352. package/control-plane/scripts/skills/theme-factory/themes/ocean-depths.md +19 -0
  353. package/control-plane/scripts/skills/theme-factory/themes/sunset-boulevard.md +19 -0
  354. package/control-plane/scripts/skills/theme-factory/themes/tech-innovation.md +19 -0
  355. package/control-plane/scripts/skills/using-git-worktrees/SKILL.md +167 -0
  356. package/control-plane/scripts/skills/verification-before-completion/SKILL.md +120 -0
  357. package/control-plane/scripts/skills/web-artifacts-builder/LICENSE.txt +202 -0
  358. package/control-plane/scripts/skills/web-artifacts-builder/SKILL.md +74 -0
  359. package/control-plane/scripts/skills/web-artifacts-builder/scripts/bundle-artifact.sh +54 -0
  360. package/control-plane/scripts/skills/web-artifacts-builder/scripts/init-artifact.sh +322 -0
  361. package/control-plane/scripts/skills/web-artifacts-builder/scripts/shadcn-components.tar.gz +0 -0
  362. package/control-plane/scripts/skills/webapp-testing/LICENSE.txt +202 -0
  363. package/control-plane/scripts/skills/webapp-testing/SKILL.md +96 -0
  364. package/control-plane/scripts/skills/webapp-testing/examples/console_logging.py +35 -0
  365. package/control-plane/scripts/skills/webapp-testing/examples/element_discovery.py +40 -0
  366. package/control-plane/scripts/skills/webapp-testing/examples/static_html_automation.py +33 -0
  367. package/control-plane/scripts/skills/webapp-testing/scripts/with_server.py +106 -0
  368. package/control-plane/scripts/skills/writing-plans/SKILL.md +192 -0
  369. package/control-plane/scripts/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
  370. package/control-plane/scripts/skills/writing-skills/SKILL.md +681 -0
  371. package/control-plane/scripts/skills/writing-skills/anthropic-best-practices.md +1150 -0
  372. package/control-plane/scripts/skills/writing-skills/examples/CLAUDE_MD_TESTING.md +189 -0
  373. package/control-plane/scripts/skills/writing-skills/graphviz-conventions.dot +172 -0
  374. package/control-plane/scripts/skills/writing-skills/persuasion-principles.md +187 -0
  375. package/control-plane/scripts/skills/writing-skills/render-graphs.js +169 -0
  376. package/control-plane/scripts/skills/writing-skills/testing-skills-with-subagents.md +384 -0
  377. package/control-plane/scripts/smoke-mcp-schemas.mjs +30 -0
  378. package/control-plane/scripts/surface-config.mjs +45 -0
  379. package/control-plane/scripts/sync-skills.mjs +370 -0
  380. package/control-plane/scripts/tool-metrics.mjs +74 -0
  381. package/control-plane/scripts/tool-risk.mjs +156 -0
  382. package/control-plane/scripts/tool-surface-stability.mjs +38 -0
  383. package/control-plane/scripts/upstreams/catalog-cache.mjs +28 -0
  384. package/control-plane/scripts/upstreams/config.mjs +158 -0
  385. package/control-plane/scripts/upstreams/diagnostics.mjs +21 -0
  386. package/control-plane/scripts/upstreams/http-client.mjs +67 -0
  387. package/control-plane/scripts/upstreams/manager.mjs +535 -0
  388. package/control-plane/scripts/upstreams/names.mjs +55 -0
  389. package/control-plane/scripts/upstreams/presets.mjs +60 -0
  390. package/control-plane/scripts/upstreams/resource-uri.mjs +29 -0
  391. package/control-plane/scripts/upstreams/stdio-client.mjs +73 -0
  392. package/control-plane/scripts/workspace-registry.mjs +147 -0
  393. package/dist/context/authorization.d.ts +5 -0
  394. package/dist/context/authorization.js +70 -0
  395. package/dist/context/capture.d.ts +46 -0
  396. package/dist/context/capture.js +187 -0
  397. package/dist/context/cli.d.ts +47 -0
  398. package/dist/context/cli.js +287 -0
  399. package/dist/context/device-adapter.d.ts +102 -0
  400. package/dist/context/device-adapter.js +79 -0
  401. package/dist/context/gateway.d.ts +354 -0
  402. package/dist/context/gateway.js +50 -0
  403. package/dist/context/graph.d.ts +63 -0
  404. package/dist/context/graph.js +214 -0
  405. package/dist/context/importer.d.ts +8 -0
  406. package/dist/context/importer.js +69 -0
  407. package/dist/context/indexer.d.ts +14 -0
  408. package/dist/context/indexer.js +57 -0
  409. package/dist/context/migrations/index.d.ts +4 -0
  410. package/dist/context/migrations/index.js +87 -0
  411. package/dist/context/redact.d.ts +15 -0
  412. package/dist/context/redact.js +43 -0
  413. package/dist/context/repositories.d.ts +9 -0
  414. package/dist/context/repositories.js +45 -0
  415. package/dist/context/search.d.ts +63 -0
  416. package/dist/context/search.js +207 -0
  417. package/dist/context/service.d.ts +278 -0
  418. package/dist/context/service.js +160 -0
  419. package/dist/context/store.d.ts +134 -0
  420. package/dist/context/store.js +722 -0
  421. package/dist/context/text.d.ts +4 -0
  422. package/dist/context/text.js +14 -0
  423. package/dist/context/tool-contract.d.ts +534 -0
  424. package/dist/context/tool-contract.js +45 -0
  425. package/dist/device/core.d.ts +29 -0
  426. package/dist/device/core.js +66 -0
  427. package/dist/device/device.d.ts +5 -1
  428. package/dist/device/device.js +87 -39
  429. package/dist/device/gateway-channel.d.ts +8 -1
  430. package/dist/device/gateway-channel.js +51 -3
  431. package/dist/device/gateway-tool-adapter.d.ts +9 -0
  432. package/dist/device/gateway-tool-adapter.js +20 -1
  433. package/dist/device/official-trust.d.ts +12 -0
  434. package/dist/device/official-trust.js +25 -1
  435. package/dist/device/runtime-owner.js +9 -1
  436. package/dist/distribution.d.ts +4 -0
  437. package/dist/distribution.js +8 -0
  438. package/dist/log-palace/cli.d.ts +7 -0
  439. package/dist/log-palace/cli.js +89 -0
  440. package/dist/log-palace/formats.d.ts +26 -0
  441. package/dist/log-palace/formats.js +126 -0
  442. package/dist/log-palace/store.d.ts +129 -0
  443. package/dist/log-palace/store.js +856 -0
  444. package/dist/mcp-device.js +27 -5
  445. package/dist/npm-scripts/remote.js +1 -0
  446. package/dist/platform/activity-journal.d.ts +16 -0
  447. package/dist/platform/activity-journal.js +68 -0
  448. package/dist/platform/cli.d.ts +1 -0
  449. package/dist/platform/cli.js +300 -0
  450. package/dist/platform/coordination-lock.d.ts +45 -0
  451. package/dist/platform/coordination-lock.js +233 -0
  452. package/dist/platform/device-runtime.d.ts +16 -0
  453. package/dist/platform/device-runtime.js +83 -0
  454. package/dist/platform/knowledge-contract.d.ts +46 -0
  455. package/dist/platform/knowledge-contract.js +1 -0
  456. package/dist/platform/knowledge-mcp.d.ts +29 -0
  457. package/dist/platform/knowledge-mcp.js +95 -0
  458. package/dist/platform/knowledge-router.d.ts +64 -0
  459. package/dist/platform/knowledge-router.js +320 -0
  460. package/dist/platform/plugin-child.d.ts +1 -0
  461. package/dist/platform/plugin-child.js +115 -0
  462. package/dist/platform/plugin-contract.d.ts +76 -0
  463. package/dist/platform/plugin-contract.js +53 -0
  464. package/dist/platform/plugin-driver.d.ts +8 -0
  465. package/dist/platform/plugin-driver.js +443 -0
  466. package/dist/platform/plugin-host.d.ts +88 -0
  467. package/dist/platform/plugin-host.js +817 -0
  468. package/dist/platform/plugin-policy.d.ts +3 -0
  469. package/dist/platform/plugin-policy.js +29 -0
  470. package/dist/platform/plugin-services.d.ts +14 -0
  471. package/dist/platform/plugin-services.js +32 -0
  472. package/dist/platform/process-identity.d.ts +9 -0
  473. package/dist/platform/process-identity.js +68 -0
  474. package/dist/platform/runtime-lease.d.ts +4 -0
  475. package/dist/platform/runtime-lease.js +58 -0
  476. package/dist/platform/runtime-root.d.ts +9 -0
  477. package/dist/platform/runtime-root.js +61 -0
  478. package/dist/platform/state-backup.d.ts +92 -0
  479. package/dist/platform/state-backup.js +399 -0
  480. package/dist/plugins/reference/plugin.d.ts +3 -0
  481. package/dist/plugins/reference/plugin.js +13 -0
  482. package/dist/server.js +5 -1
  483. package/dist/terminal-manager.d.ts +7 -0
  484. package/dist/terminal-manager.js +10 -0
  485. package/dist/tool-dispatcher.js +5 -1
  486. package/dist/tools/improved-process-tools.js +4 -0
  487. package/dist/types.d.ts +1 -0
  488. package/dist/version.d.ts +1 -1
  489. package/dist/version.js +1 -1
  490. package/package.json +29 -6
  491. package/skills/mcp-device-context/SKILL.md +40 -0
@@ -0,0 +1,589 @@
1
+ import crypto from 'node:crypto';
2
+ import cors from 'cors';
3
+ import express from 'express';
4
+ import { rateLimit } from 'express-rate-limit';
5
+ import {
6
+ OAuthClientMetadataSchema,
7
+ OAuthTokenRevocationRequestSchema
8
+ } from '@modelcontextprotocol/core';
9
+ import { mcpAuthMetadataRouter } from '@modelcontextprotocol/express';
10
+ import { OAuthError, OAuthErrorCode } from '@modelcontextprotocol/server';
11
+
12
+ const DEFAULT_CLIENT_SECRET_EXPIRY_SECONDS = 30 * 24 * 60 * 60;
13
+ const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]', '::1']);
14
+ const OAUTH_RATE_LIMIT_WINDOW_MS = 15 * 60 * 1000;
15
+
16
+ function oauthError(code, message, errorUri) {
17
+ return new OAuthError(code, message, errorUri);
18
+ }
19
+
20
+ function oauthErrorStatus(error) {
21
+ if (!(error instanceof OAuthError)) return 500;
22
+ if (error.code === OAuthErrorCode.ServerError) return 500;
23
+ if (error.code === OAuthErrorCode.TemporarilyUnavailable) return 503;
24
+ if (error.code === OAuthErrorCode.TooManyRequests) return 429;
25
+ return 400;
26
+ }
27
+
28
+ function sendOAuthError(res, error) {
29
+ const normalized = error instanceof OAuthError
30
+ ? error
31
+ : oauthError(OAuthErrorCode.ServerError, 'Internal Server Error');
32
+ res.status(oauthErrorStatus(normalized)).json(normalized.toResponseObject());
33
+ }
34
+
35
+ function allowedMethods(allowed) {
36
+ return (req, res, next) => {
37
+ if (allowed.includes(req.method)) {
38
+ next();
39
+ return;
40
+ }
41
+
42
+ const error = oauthError(
43
+ OAuthErrorCode.MethodNotAllowed,
44
+ `The method ${req.method} is not allowed for this endpoint`
45
+ );
46
+ res.status(405).set('Allow', allowed.join(', ')).json(error.toResponseObject());
47
+ };
48
+ }
49
+
50
+ function asString(value, name, { optional = false } = {}) {
51
+ if (value === undefined || value === null || value === '') {
52
+ if (optional) return undefined;
53
+ throw oauthError(OAuthErrorCode.InvalidRequest, `${name} is required`);
54
+ }
55
+ if (typeof value !== 'string') {
56
+ throw oauthError(OAuthErrorCode.InvalidRequest, `${name} must be a string`);
57
+ }
58
+ return value;
59
+ }
60
+
61
+ function asOptionalUrl(value, name) {
62
+ const text = asString(value, name, { optional: true });
63
+ if (text === undefined) return undefined;
64
+ try {
65
+ return new URL(text);
66
+ } catch {
67
+ throw oauthError(OAuthErrorCode.InvalidRequest, `${name} must be a valid URL`);
68
+ }
69
+ }
70
+
71
+ function requestParams(req) {
72
+ return req.method === 'POST' ? req.body : req.query;
73
+ }
74
+
75
+ export function redirectUriMatches(requested, registered) {
76
+ if (requested === registered) return true;
77
+
78
+ let reqUrl;
79
+ let registeredUrl;
80
+ try {
81
+ reqUrl = new URL(requested);
82
+ registeredUrl = new URL(registered);
83
+ } catch {
84
+ return false;
85
+ }
86
+
87
+ if (!LOOPBACK_HOSTS.has(reqUrl.hostname) || !LOOPBACK_HOSTS.has(registeredUrl.hostname)) {
88
+ return false;
89
+ }
90
+
91
+ return reqUrl.protocol === registeredUrl.protocol
92
+ && reqUrl.hostname === registeredUrl.hostname
93
+ && reqUrl.pathname === registeredUrl.pathname
94
+ && reqUrl.search === registeredUrl.search;
95
+ }
96
+
97
+ function addIssuerToCallback(res, redirectUri, issuer) {
98
+ const callback = new URL(redirectUri);
99
+ const originalRedirect = res.redirect.bind(res);
100
+
101
+ const withIssuer = value => {
102
+ let target;
103
+ try {
104
+ target = new URL(String(value));
105
+ } catch {
106
+ return value;
107
+ }
108
+
109
+ if (
110
+ target.origin === callback.origin
111
+ && target.pathname === callback.pathname
112
+ && !target.searchParams.has('iss')
113
+ ) {
114
+ target.searchParams.set('iss', issuer);
115
+ return target.href;
116
+ }
117
+
118
+ return value;
119
+ };
120
+
121
+ res.redirect = (statusOrUrl, maybeUrl) => {
122
+ if (typeof statusOrUrl === 'number') {
123
+ return originalRedirect(statusOrUrl, withIssuer(maybeUrl));
124
+ }
125
+ if (typeof maybeUrl === 'number') {
126
+ return originalRedirect(withIssuer(statusOrUrl), maybeUrl);
127
+ }
128
+ return originalRedirect(withIssuer(statusOrUrl));
129
+ };
130
+
131
+ return res;
132
+ }
133
+
134
+ function errorRedirect(redirectUri, error, state, issuer) {
135
+ const target = new URL(redirectUri);
136
+ target.searchParams.set('error', error.code);
137
+ target.searchParams.set('error_description', error.message);
138
+ if (error.errorUri) target.searchParams.set('error_uri', error.errorUri);
139
+ if (state) target.searchParams.set('state', state);
140
+ if (issuer) target.searchParams.set('iss', issuer);
141
+ return target.href;
142
+ }
143
+
144
+ function makeRateLimit({ windowMs, max, message, config }) {
145
+ if (config === false) return null;
146
+ return rateLimit({
147
+ windowMs,
148
+ max,
149
+ standardHeaders: true,
150
+ legacyHeaders: false,
151
+ message: oauthError(OAuthErrorCode.TooManyRequests, message).toResponseObject(),
152
+ ...config
153
+ });
154
+ }
155
+
156
+ function authorizationHandler({ provider, issuerUrl, rateLimit: rateLimitConfig }) {
157
+ const issuer = issuerUrl?.href;
158
+ const router = express.Router();
159
+ router.use(allowedMethods(['GET', 'POST']));
160
+ router.use(express.urlencoded({ extended: false }));
161
+
162
+ const limiter = makeRateLimit({
163
+ windowMs: OAUTH_RATE_LIMIT_WINDOW_MS,
164
+ max: 100,
165
+ message: 'You have exceeded the rate limit for authorization requests',
166
+ config: rateLimitConfig
167
+ });
168
+ if (limiter) router.use(limiter);
169
+
170
+ router.all('/', async (req, res) => {
171
+ res.setHeader('Cache-Control', 'no-store');
172
+
173
+ const params = requestParams(req);
174
+ let client;
175
+ let redirectUri;
176
+
177
+ try {
178
+ const clientId = asString(params.client_id, 'client_id');
179
+ redirectUri = asString(params.redirect_uri, 'redirect_uri', { optional: true });
180
+ client = await provider.clientsStore.getClient(clientId);
181
+
182
+ if (!client) {
183
+ throw oauthError(OAuthErrorCode.InvalidClient, 'Invalid client_id');
184
+ }
185
+
186
+ const registeredRedirects = Array.isArray(client.redirect_uris) ? client.redirect_uris : [];
187
+ if (redirectUri !== undefined) {
188
+ if (!registeredRedirects.some(registered => redirectUriMatches(redirectUri, registered))) {
189
+ throw oauthError(OAuthErrorCode.InvalidRequest, 'Unregistered redirect_uri');
190
+ }
191
+ } else if (registeredRedirects.length === 1) {
192
+ [redirectUri] = registeredRedirects;
193
+ } else {
194
+ throw oauthError(
195
+ OAuthErrorCode.InvalidRequest,
196
+ 'redirect_uri must be specified when client has multiple registered URIs'
197
+ );
198
+ }
199
+ } catch (error) {
200
+ sendOAuthError(res, error);
201
+ return;
202
+ }
203
+
204
+ let state;
205
+ try {
206
+ const responseType = asString(params.response_type, 'response_type');
207
+ if (responseType !== 'code') {
208
+ throw oauthError(
209
+ OAuthErrorCode.UnsupportedResponseType,
210
+ 'Only response_type=code is supported'
211
+ );
212
+ }
213
+
214
+ const codeChallenge = asString(params.code_challenge, 'code_challenge');
215
+ const codeChallengeMethod = asString(params.code_challenge_method, 'code_challenge_method');
216
+ if (codeChallengeMethod !== 'S256') {
217
+ throw oauthError(
218
+ OAuthErrorCode.InvalidRequest,
219
+ 'code_challenge_method must be S256'
220
+ );
221
+ }
222
+
223
+ const scope = asString(params.scope, 'scope', { optional: true });
224
+ state = asString(params.state, 'state', { optional: true });
225
+ const resource = asOptionalUrl(params.resource, 'resource');
226
+ const scopes = scope ? scope.split(' ').filter(Boolean) : [];
227
+
228
+ await provider.authorize(client, {
229
+ state,
230
+ scopes,
231
+ redirectUri,
232
+ codeChallenge,
233
+ resource,
234
+ issuer
235
+ }, issuer ? addIssuerToCallback(res, redirectUri, issuer) : res);
236
+ } catch (error) {
237
+ const normalized = error instanceof OAuthError
238
+ ? error
239
+ : oauthError(OAuthErrorCode.ServerError, 'Internal Server Error');
240
+ res.redirect(302, errorRedirect(redirectUri, normalized, state, issuer));
241
+ }
242
+ });
243
+
244
+ return router;
245
+ }
246
+
247
+ function safeSecretEqual(provided, expected) {
248
+ const a = Buffer.from(String(provided || ''), 'utf8');
249
+ const b = Buffer.from(String(expected || ''), 'utf8');
250
+ return a.length === b.length && crypto.timingSafeEqual(a, b);
251
+ }
252
+
253
+ function authenticateClient({ clientsStore }) {
254
+ return async (req, res, next) => {
255
+ try {
256
+ const clientId = asString(req.body?.client_id, 'client_id');
257
+ const clientSecret = asString(req.body?.client_secret, 'client_secret', { optional: true });
258
+ const client = await clientsStore.getClient(clientId);
259
+ if (!client) throw oauthError(OAuthErrorCode.InvalidClient, 'Invalid client_id');
260
+
261
+ if (client.client_secret) {
262
+ if (!clientSecret) {
263
+ throw oauthError(OAuthErrorCode.InvalidClient, 'Client secret is required');
264
+ }
265
+ if (!safeSecretEqual(clientSecret, client.client_secret)) {
266
+ throw oauthError(OAuthErrorCode.InvalidClient, 'Invalid client_secret');
267
+ }
268
+ if (
269
+ client.client_secret_expires_at
270
+ && client.client_secret_expires_at < Math.floor(Date.now() / 1000)
271
+ ) {
272
+ throw oauthError(OAuthErrorCode.InvalidClient, 'Client secret has expired');
273
+ }
274
+ }
275
+
276
+ req.oauthClient = client;
277
+ next();
278
+ } catch (error) {
279
+ sendOAuthError(res, error);
280
+ }
281
+ };
282
+ }
283
+
284
+ function validPkceVerifier(value) {
285
+ return typeof value === 'string'
286
+ && value.length >= 43
287
+ && value.length <= 128
288
+ && /^[A-Za-z0-9._~-]+$/.test(value);
289
+ }
290
+
291
+ function pkceChallenge(verifier) {
292
+ return crypto.createHash('sha256').update(verifier, 'ascii').digest('base64url');
293
+ }
294
+
295
+ function pkceMatches(verifier, expectedChallenge) {
296
+ if (!validPkceVerifier(verifier) || typeof expectedChallenge !== 'string') return false;
297
+ return safeSecretEqual(pkceChallenge(verifier), expectedChallenge);
298
+ }
299
+
300
+ function tokenHandler({ provider, rateLimit: rateLimitConfig }) {
301
+ const router = express.Router();
302
+ router.use(cors());
303
+ router.use(allowedMethods(['POST']));
304
+ router.use(express.urlencoded({ extended: false }));
305
+
306
+ const limiter = makeRateLimit({
307
+ windowMs: OAUTH_RATE_LIMIT_WINDOW_MS,
308
+ max: 50,
309
+ message: 'You have exceeded the rate limit for token requests',
310
+ config: rateLimitConfig
311
+ });
312
+ if (limiter) router.use(limiter);
313
+
314
+ router.use(authenticateClient({ clientsStore: provider.clientsStore }));
315
+
316
+ router.post('/', async (req, res) => {
317
+ res.setHeader('Cache-Control', 'no-store');
318
+
319
+ try {
320
+ const grantType = asString(req.body?.grant_type, 'grant_type');
321
+ const client = req.oauthClient;
322
+ if (!client) throw oauthError(OAuthErrorCode.ServerError, 'Internal Server Error');
323
+
324
+ if (grantType === 'authorization_code') {
325
+ const code = asString(req.body?.code, 'code');
326
+ const codeVerifier = asString(req.body?.code_verifier, 'code_verifier');
327
+ const redirectUri = asString(req.body?.redirect_uri, 'redirect_uri', { optional: true });
328
+ const resource = asOptionalUrl(req.body?.resource, 'resource');
329
+
330
+ const expectedChallenge = await provider.challengeForAuthorizationCode(client, code);
331
+ if (!pkceMatches(codeVerifier, expectedChallenge)) {
332
+ throw oauthError(
333
+ OAuthErrorCode.InvalidGrant,
334
+ 'code_verifier does not match the challenge'
335
+ );
336
+ }
337
+
338
+ const tokens = await provider.exchangeAuthorizationCode(
339
+ client,
340
+ code,
341
+ undefined,
342
+ redirectUri,
343
+ resource
344
+ );
345
+ res.status(200).json(tokens);
346
+ return;
347
+ }
348
+
349
+ if (grantType === 'refresh_token') {
350
+ const refreshToken = asString(req.body?.refresh_token, 'refresh_token');
351
+ const scope = asString(req.body?.scope, 'scope', { optional: true });
352
+ const resource = asOptionalUrl(req.body?.resource, 'resource');
353
+ const scopes = scope ? scope.split(' ').filter(Boolean) : undefined;
354
+
355
+ const tokens = await provider.exchangeRefreshToken(
356
+ client,
357
+ refreshToken,
358
+ scopes,
359
+ resource
360
+ );
361
+ res.status(200).json(tokens);
362
+ return;
363
+ }
364
+
365
+ throw oauthError(
366
+ OAuthErrorCode.UnsupportedGrantType,
367
+ 'The grant type is not supported by this authorization server.'
368
+ );
369
+ } catch (error) {
370
+ sendOAuthError(res, error);
371
+ }
372
+ });
373
+
374
+ return router;
375
+ }
376
+
377
+ function clientRegistrationHandler({
378
+ clientsStore,
379
+ clientSecretExpirySeconds = DEFAULT_CLIENT_SECRET_EXPIRY_SECONDS,
380
+ rateLimit: rateLimitConfig,
381
+ clientIdGeneration = true
382
+ }) {
383
+ if (typeof clientsStore?.registerClient !== 'function') {
384
+ throw new Error('Client registration store does not support registering clients');
385
+ }
386
+
387
+ const router = express.Router();
388
+ router.use(cors());
389
+ router.use(allowedMethods(['POST']));
390
+ router.use(express.json());
391
+
392
+ const limiter = makeRateLimit({
393
+ windowMs: 60 * 60 * 1000,
394
+ max: 20,
395
+ message: 'You have exceeded the rate limit for client registration requests',
396
+ config: rateLimitConfig
397
+ });
398
+ if (limiter) router.use(limiter);
399
+
400
+ router.post('/', async (req, res) => {
401
+ res.setHeader('Cache-Control', 'no-store');
402
+
403
+ try {
404
+ const parsed = OAuthClientMetadataSchema.safeParse(req.body);
405
+ if (!parsed.success) {
406
+ throw oauthError(OAuthErrorCode.InvalidClientMetadata, parsed.error.message);
407
+ }
408
+
409
+ const clientMetadata = parsed.data;
410
+ const isPublicClient = clientMetadata.token_endpoint_auth_method === 'none';
411
+ const clientIdIssuedAt = Math.floor(Date.now() / 1000);
412
+ const secretExpiryTime = clientSecretExpirySeconds > 0
413
+ ? clientIdIssuedAt + clientSecretExpirySeconds
414
+ : 0;
415
+
416
+ let clientInfo = {
417
+ ...clientMetadata,
418
+ client_secret: isPublicClient ? undefined : crypto.randomBytes(32).toString('hex'),
419
+ client_secret_expires_at: isPublicClient ? undefined : secretExpiryTime
420
+ };
421
+
422
+ if (clientIdGeneration) {
423
+ clientInfo = {
424
+ ...clientInfo,
425
+ client_id: crypto.randomUUID(),
426
+ client_id_issued_at: clientIdIssuedAt
427
+ };
428
+ }
429
+
430
+ clientInfo = await clientsStore.registerClient(clientInfo);
431
+ res.status(201).json(clientInfo);
432
+ } catch (error) {
433
+ sendOAuthError(res, error);
434
+ }
435
+ });
436
+
437
+ return router;
438
+ }
439
+
440
+ function revocationHandler({ provider, rateLimit: rateLimitConfig }) {
441
+ if (typeof provider.revokeToken !== 'function') {
442
+ throw new Error('Auth provider does not support revoking tokens');
443
+ }
444
+
445
+ const router = express.Router();
446
+ router.use(cors());
447
+ router.use(allowedMethods(['POST']));
448
+ router.use(express.urlencoded({ extended: false }));
449
+
450
+ const limiter = makeRateLimit({
451
+ windowMs: OAUTH_RATE_LIMIT_WINDOW_MS,
452
+ max: 50,
453
+ message: 'You have exceeded the rate limit for token revocation requests',
454
+ config: rateLimitConfig
455
+ });
456
+ if (limiter) router.use(limiter);
457
+
458
+ router.use(authenticateClient({ clientsStore: provider.clientsStore }));
459
+
460
+ router.post('/', async (req, res) => {
461
+ res.setHeader('Cache-Control', 'no-store');
462
+
463
+ try {
464
+ const parsed = OAuthTokenRevocationRequestSchema.safeParse(req.body);
465
+ if (!parsed.success) {
466
+ throw oauthError(OAuthErrorCode.InvalidRequest, parsed.error.message);
467
+ }
468
+ await provider.revokeToken(req.oauthClient, parsed.data);
469
+ res.status(200).json({});
470
+ } catch (error) {
471
+ sendOAuthError(res, error);
472
+ }
473
+ });
474
+
475
+ return router;
476
+ }
477
+
478
+ function insecureIssuerAllowed(options) {
479
+ if (options.dangerouslyAllowInsecureIssuerUrl === true) return true;
480
+ const value = String(process.env.MCP_DANGEROUSLY_ALLOW_INSECURE_ISSUER_URL || '').toLowerCase();
481
+ return value === 'true' || value === '1';
482
+ }
483
+
484
+ function validateIssuerUrl(issuerUrl, options) {
485
+ if (!(issuerUrl instanceof URL)) throw new Error('issuerUrl must be a URL');
486
+ const allowInsecure = insecureIssuerAllowed(options);
487
+ if (
488
+ issuerUrl.protocol !== 'https:'
489
+ && !LOOPBACK_HOSTS.has(issuerUrl.hostname)
490
+ && !allowInsecure
491
+ ) {
492
+ throw new Error('Issuer URL must be HTTPS');
493
+ }
494
+ if (issuerUrl.hash) throw new Error(`Issuer URL must not have a fragment: ${issuerUrl}`);
495
+ if (issuerUrl.search) throw new Error(`Issuer URL must not have a query string: ${issuerUrl}`);
496
+ }
497
+
498
+ export function createOAuthAuthorizationServerMetadata(options) {
499
+ const { provider, issuerUrl } = options;
500
+ validateIssuerUrl(issuerUrl, options);
501
+
502
+ const baseUrl = options.baseUrl || issuerUrl;
503
+ const registrationEndpoint = typeof provider.clientsStore?.registerClient === 'function'
504
+ ? '/register'
505
+ : undefined;
506
+ const revocationEndpoint = typeof provider.revokeToken === 'function'
507
+ ? '/revoke'
508
+ : undefined;
509
+
510
+ return {
511
+ issuer: issuerUrl.href,
512
+ service_documentation: options.serviceDocumentationUrl?.href,
513
+ authorization_endpoint: new URL('/authorize', baseUrl).href,
514
+ response_types_supported: ['code'],
515
+ code_challenge_methods_supported: ['S256'],
516
+ token_endpoint: new URL('/token', baseUrl).href,
517
+ token_endpoint_auth_methods_supported: ['client_secret_post', 'none'],
518
+ grant_types_supported: ['authorization_code', 'refresh_token'],
519
+ scopes_supported: options.scopesSupported,
520
+ revocation_endpoint: revocationEndpoint
521
+ ? new URL(revocationEndpoint, baseUrl).href
522
+ : undefined,
523
+ revocation_endpoint_auth_methods_supported: revocationEndpoint
524
+ ? ['client_secret_post']
525
+ : undefined,
526
+ registration_endpoint: registrationEndpoint
527
+ ? new URL(registrationEndpoint, baseUrl).href
528
+ : undefined,
529
+ authorization_response_iss_parameter_supported:
530
+ provider.authorizationResponseIssParameterSupported ?? true
531
+ };
532
+ }
533
+
534
+ export function createOAuthAuthorizationServerRouter(options) {
535
+ if (!options?.provider) throw new Error('provider is required');
536
+ if (!(options.issuerUrl instanceof URL)) throw new Error('issuerUrl must be a URL');
537
+ if (!(options.resourceServerUrl instanceof URL)) throw new Error('resourceServerUrl must be a URL');
538
+
539
+ const oauthMetadata = createOAuthAuthorizationServerMetadata(options);
540
+ const router = express.Router();
541
+
542
+ router.use(
543
+ new URL(oauthMetadata.authorization_endpoint).pathname,
544
+ authorizationHandler({
545
+ provider: options.provider,
546
+ issuerUrl: options.issuerUrl,
547
+ ...options.authorizationOptions
548
+ })
549
+ );
550
+
551
+ router.use(
552
+ new URL(oauthMetadata.token_endpoint).pathname,
553
+ tokenHandler({
554
+ provider: options.provider,
555
+ ...options.tokenOptions
556
+ })
557
+ );
558
+
559
+ router.use(mcpAuthMetadataRouter({
560
+ oauthMetadata,
561
+ resourceServerUrl: options.resourceServerUrl,
562
+ serviceDocumentationUrl: options.serviceDocumentationUrl,
563
+ scopesSupported: options.scopesSupported,
564
+ resourceName: options.resourceName,
565
+ dangerouslyAllowInsecureIssuerUrl: insecureIssuerAllowed(options)
566
+ }));
567
+
568
+ if (oauthMetadata.registration_endpoint) {
569
+ router.use(
570
+ new URL(oauthMetadata.registration_endpoint).pathname,
571
+ clientRegistrationHandler({
572
+ clientsStore: options.provider.clientsStore,
573
+ ...options.clientRegistrationOptions
574
+ })
575
+ );
576
+ }
577
+
578
+ if (oauthMetadata.revocation_endpoint) {
579
+ router.use(
580
+ new URL(oauthMetadata.revocation_endpoint).pathname,
581
+ revocationHandler({
582
+ provider: options.provider,
583
+ ...options.revocationOptions
584
+ })
585
+ );
586
+ }
587
+
588
+ return router;
589
+ }
@@ -0,0 +1,81 @@
1
+ import express from 'express';
2
+ import { escapeHtml } from './enduser-ui.mjs';
3
+
4
+ const LOOPBACK_HOST = '127.0.0.1';
5
+ const AUTO_REFRESH_MS = 3500;
6
+
7
+ function number(value) { return Number(value || 0).toLocaleString('en-US'); }
8
+ function bytes(value) {
9
+ const n = Math.max(0, Number(value) || 0);
10
+ if (n < 1024) return `${number(n)} B`;
11
+ if (n < 1024 * 1024) return `${(n / 1024).toFixed(n >= 10 * 1024 ? 0 : 1)} KiB`;
12
+ return `${(n / (1024 * 1024)).toFixed(n >= 10 * 1024 * 1024 ? 0 : 1)} MiB`;
13
+ }
14
+
15
+ function deviceRows(devices, usageStore, accountId) {
16
+ if (!devices.length) return '<tr><td colspan="4" class="muted">No devices.</td></tr>';
17
+ return devices.map(device => {
18
+ const status = device.online ? 'online' : 'offline';
19
+ const tools = usageStore.getDeviceToolUsage(accountId, device.deviceId);
20
+ const totalCalls = tools.reduce((sum, item) => sum + Number(item.calls || 0), 0);
21
+ const top = tools.slice(0, 4).map(item => `${escapeHtml(item.tool)} (${number(item.calls)})`).join(', ') || 'no attributed calls';
22
+ return `<tr><td><span class="dot ${status}"></span><strong>${escapeHtml(device.deviceName)}</strong> <span class="muted">${escapeHtml(device.platform || 'unknown')} / ${escapeHtml(device.arch || 'unknown')}</span><small>${escapeHtml(device.deviceId)}</small></td><td>${status}</td><td>${number(totalCalls)}</td><td>${top}</td></tr>`;
23
+ }).join('');
24
+ }
25
+
26
+ function accountSection(account, usageStore, deviceBroker) {
27
+ const usage = usageStore.getAccountUsage(account.accountId);
28
+ const devices = deviceBroker.listDevices({ accountId: account.accountId }).filter(device => !device.revoked);
29
+ const input = Number(usage.totals.inputBytes || 0);
30
+ const output = Number(usage.totals.outputBytes || 0);
31
+ const estimatedTokens = Math.ceil((input + output) / 4);
32
+ const topTools = usage.topTools.slice(0, 5).map(item => `${escapeHtml(item.tool)} (${number(item.calls)})`).join(', ') || 'none';
33
+ return `<section class="account-card"><header><div><h2>${escapeHtml(account.email || account.accountId)}</h2><small>${escapeHtml(account.accountId)}</small></div><div class="state">${account.revokedAt ? 'revoked' : 'active'}</div></header><div class="summary"><span><b>${number(devices.length)}</b> devices</span><span><b>${number(usage.totals.toolCalls)}</b> calls</span><span><b>${number(usage.totals.succeeded)}</b> success</span><span><b>${number(usage.totals.failed)}</b> fail</span><span><b>${bytes(input)}</b> input</span><span><b>${bytes(output)}</b> output</span><span><b>~${number(estimatedTokens)}</b> Estimated tokens</span></div><p class="tools"><strong>Top tools:</strong> ${topTools}</p><table><thead><tr><th>Device</th><th>Status</th><th>Calls</th><th>Recent/top tools</th></tr></thead><tbody>${deviceRows(devices, usageStore, account.accountId)}</tbody></table></section>`;
34
+ }
35
+
36
+ function dashboardContent(accountStore, usageStore, deviceBroker) {
37
+ const accounts = accountStore.listAccounts().filter(account => account.role === 'user');
38
+ return {
39
+ accountCount: accounts.length,
40
+ html: accounts.map(account => accountSection(account, usageStore, deviceBroker)).join('') || '<p class="muted">No user accounts.</p>'
41
+ };
42
+ }
43
+
44
+ function page(accountStore, usageStore, deviceBroker, { basePath = '' } = {}) {
45
+ const content = dashboardContent(accountStore, usageStore, deviceBroker);
46
+ return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Operator account usage</title><style>:root{color-scheme:dark;--bg:#080a0d;--panel:#0d1117;--line:#252b34;--text:#e6edf3;--muted:#8b949e;--good:#3fb950;--warn:#d29922;--bad:#f85149}*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--text);font:13px ui-monospace,SFMono-Regular,Consolas,monospace}main{width:min(1500px,96vw);margin:22px auto 50px}.top{display:flex;justify-content:space-between;align-items:center;border-bottom:1px solid var(--line);padding-bottom:12px}.top h1{font-size:18px;margin:0}.muted,small,em{color:var(--muted)}button{background:#161b22;color:var(--text);border:1px solid var(--line);padding:6px 9px;font:inherit;cursor:pointer}.account-card{margin-top:16px;border:1px solid var(--line);background:var(--panel);padding:14px}.account-card header{display:flex;justify-content:space-between;gap:12px}.account-card h2{font-size:15px;margin:0 0 4px}.state{color:var(--muted)}.summary{display:flex;flex-wrap:wrap;gap:12px 20px;margin:12px 0}.summary b{font-size:16px}.tools{margin:8px 0 12px;color:var(--muted)}table{width:100%;border-collapse:collapse}th,td{text-align:left;padding:8px;border-top:1px solid var(--line);vertical-align:top}th{font-size:11px;color:var(--muted);font-weight:500}.dot{display:inline-block;width:7px;height:7px;border-radius:50%;margin-right:7px}.online{background:var(--good)}.offline{background:var(--warn)}td small{display:block;margin-top:3px}@media(max-width:850px){.account-card{overflow-x:auto}table{min-width:680px}}</style></head><body><main><header class="top"><div><h1>Operator account usage</h1><small>${basePath ? 'Authenticated administrator overview' : 'Loopback-only read-only overview'} · <span id="account-count">${number(content.accountCount)}</span> user accounts</small></div><button id="auto" type="button">Auto refresh: on</button></header><div id="operator-content">${content.html}</div></main><script>(()=>{const KEY='operatorAutoRefresh';const button=document.getElementById('auto');const content=document.getElementById('operator-content');const count=document.getElementById('account-count');let enabled=localStorage.getItem(KEY)!=='off';let timer;let inFlight=false;const paint=()=>button.textContent='Auto refresh: '+(enabled?'on':'off');const refresh=async()=>{if(!enabled||document.hidden||inFlight)return;const selection=String(window.getSelection?.()||'').trim();if(selection)return schedule();inFlight=true;try{const response=await fetch('${basePath}/state',{cache:'no-store'});if(response.ok){const payload=await response.json();content.innerHTML=payload.content;count.textContent=payload.accountCount;}}catch{}finally{inFlight=false;schedule();}};const schedule=()=>{clearTimeout(timer);if(enabled&&!document.hidden)timer=setTimeout(refresh,${AUTO_REFRESH_MS});};button.addEventListener('click',()=>{enabled=!enabled;localStorage.setItem(KEY,enabled?'on':'off');paint();schedule();});document.addEventListener('visibilitychange',()=>{if(!document.hidden)refresh();else clearTimeout(timer);});paint();schedule();})();</script></body></html>`;
47
+ }
48
+
49
+ /** Mount the operator view on the one application; anonymous/normal-user sessions cannot see other accounts. */
50
+ export function installOperatorDashboardRoutes(app, { accountStore, usageStore, deviceBroker, accountFromRequest } = {}) {
51
+ if (!app || !accountStore || !usageStore || !deviceBroker || typeof accountFromRequest !== 'function') {
52
+ throw new Error('Operator routes require stores, broker and account authentication.');
53
+ }
54
+ const authorize = (req, res, next) => {
55
+ const account = accountFromRequest(req);
56
+ if (!account) return res.redirect(302, '/login?return_to=' + encodeURIComponent('/operator'));
57
+ if (account.role !== 'admin') return res.status(403).json({ error: 'ADMIN_REQUIRED' });
58
+ next();
59
+ };
60
+ app.get('/operator', authorize, (_req, res) => res.status(200).type('html').send(page(accountStore, usageStore, deviceBroker, { basePath: '/operator' })));
61
+ app.get('/operator/state', authorize, (_req, res) => {
62
+ const content = dashboardContent(accountStore, usageStore, deviceBroker);
63
+ res.set('Cache-Control', 'no-store');
64
+ res.status(200).json({ content: content.html, accountCount: content.accountCount });
65
+ });
66
+ }
67
+
68
+ export async function startOperatorDashboard({ accountStore, usageStore, deviceBroker, port } = {}) {
69
+ if (!accountStore || !usageStore || !deviceBroker) throw new Error('accountStore, usageStore, and deviceBroker are required.');
70
+ const app = express();
71
+ app.get('/', (_req, res) => res.status(200).type('html').send(page(accountStore, usageStore, deviceBroker)));
72
+ app.get('/state', (_req, res) => {
73
+ const content = dashboardContent(accountStore, usageStore, deviceBroker);
74
+ res.set('Cache-Control', 'no-store');
75
+ res.status(200).json({ content: content.html, accountCount: content.accountCount });
76
+ });
77
+ return new Promise((resolve, reject) => {
78
+ const server = app.listen(Number(port), LOOPBACK_HOST, () => resolve(server));
79
+ server.once('error', reject);
80
+ });
81
+ }