shadow-claw 1.32.0 → 1.33.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.
- package/.well-known/mcp/server-card.json +1 -1
- package/.well-known/mcp.json +1 -1
- package/dist/electron/main.cjs +1 -1
- package/dist/lib/components/index.js +26 -26
- package/dist/lib/components/settings/shadow-claw-accounts.js +1 -1
- package/dist/lib/components/settings/shadow-claw-channel-config.js +1 -1
- package/dist/lib/components/settings/shadow-claw-control-plane.js +1 -1
- package/dist/lib/components/settings/shadow-claw-git.js +1 -1
- package/dist/lib/components/settings/shadow-claw-integrations.js +1 -1
- package/dist/lib/components/settings/shadow-claw-llm.js +1 -1
- package/dist/lib/components/settings/shadow-claw-mcp-remote.js +1 -1
- package/dist/lib/components/settings/shadow-claw-networking.js +1 -1
- package/dist/lib/components/settings/shadow-claw-notifications.js +1 -1
- package/dist/lib/components/settings/shadow-claw-peerjs.js +1 -1
- package/dist/lib/components/settings/shadow-claw-storage.js +1 -1
- package/dist/lib/components/settings/shadow-claw-task-server.js +1 -1
- package/dist/lib/components/settings/shadow-claw-webvm.js +1 -1
- package/dist/lib/components/shadow-claw-a2ui.js +1 -1
- package/dist/lib/components/shadow-claw-accounts.js +1 -1
- package/dist/lib/components/shadow-claw-channel-config.js +1 -1
- package/dist/lib/components/shadow-claw-channels.js +1 -1
- package/dist/lib/components/shadow-claw-chat.js +1 -1
- package/dist/lib/components/shadow-claw-control-plane.js +1 -1
- package/dist/lib/components/shadow-claw-conversations.js +1 -1
- package/dist/lib/components/shadow-claw-file-viewer.js +1 -1
- package/dist/lib/components/shadow-claw-files.js +1 -1
- package/dist/lib/components/shadow-claw-git.js +1 -1
- package/dist/lib/components/shadow-claw-integrations.js +1 -1
- package/dist/lib/components/shadow-claw-llm.js +1 -1
- package/dist/lib/components/shadow-claw-mcp-remote.js +1 -1
- package/dist/lib/components/shadow-claw-networking.js +1 -1
- package/dist/lib/components/shadow-claw-notifications.js +1 -1
- package/dist/lib/components/shadow-claw-page-header.js +1 -1
- package/dist/lib/components/shadow-claw-pages.js +1 -1
- package/dist/lib/components/shadow-claw-peerjs.js +1 -1
- package/dist/lib/components/shadow-claw-settings.js +1 -1
- package/dist/lib/components/shadow-claw-storage.js +1 -1
- package/dist/lib/components/shadow-claw-task-server.js +1 -1
- package/dist/lib/components/shadow-claw-tasks.js +1 -1
- package/dist/lib/components/shadow-claw-terminal.js +1 -1
- package/dist/lib/components/shadow-claw-tools.js +1 -1
- package/dist/lib/components/shadow-claw-webvm.js +1 -1
- package/dist/lib/components/shadow-claw.js +1 -1
- package/dist/lib/{config-DjZ9QWc4.js → config-BcFbkaQv.js} +21 -4
- package/dist/lib/config-BcFbkaQv.js.map +1 -0
- package/dist/lib/{configurePeerJs-DD3G3Pms.js → configurePeerJs-CBMPHbwa.js} +3 -3
- package/dist/lib/{configurePeerJs-DD3G3Pms.js.map → configurePeerJs-CBMPHbwa.js.map} +1 -1
- package/dist/lib/{connections-BURqMIUv.js → connections-PZrUDf49.js} +2 -2
- package/dist/lib/{connections-BURqMIUv.js.map → connections-PZrUDf49.js.map} +1 -1
- package/dist/lib/{downloadGroupFile-B8J4up2a.js → downloadGroupFile-DSRUa9Au.js} +2 -2
- package/dist/lib/{downloadGroupFile-B8J4up2a.js.map → downloadGroupFile-DSRUa9Au.js.map} +1 -1
- package/dist/lib/{file-viewer-DoHM75Jz.js → file-viewer-11VVOpJv.js} +5 -5
- package/dist/lib/{file-viewer-DoHM75Jz.js.map → file-viewer-11VVOpJv.js.map} +1 -1
- package/dist/lib/{getGroupDir-QrN2aTo8.js → getGroupDir-BxKMYPPm.js} +3 -3
- package/dist/lib/{getGroupDir-QrN2aTo8.js.map → getGroupDir-BxKMYPPm.js.map} +1 -1
- package/dist/lib/{git-Brr7JIbs.js → git-BppibnJW.js} +3 -3
- package/dist/lib/{git-Brr7JIbs.js.map → git-BppibnJW.js.map} +1 -1
- package/dist/lib/{iframe-sanitizer-Bujgq14T.js → iframe-sanitizer-Dp8EYffI.js} +2 -2
- package/dist/lib/{iframe-sanitizer-Bujgq14T.js.map → iframe-sanitizer-Dp8EYffI.js.map} +1 -1
- package/dist/lib/index.js +27 -27
- package/dist/lib/{initChatSplitResize-BjiWoqC_.js → initChatSplitResize-CE_kWaLf.js} +2 -2
- package/dist/lib/{initChatSplitResize-BjiWoqC_.js.map → initChatSplitResize-CE_kWaLf.js.map} +1 -1
- package/dist/lib/{initControlPlane-3TUdhRBM.js → initControlPlane-BRIIOzoH.js} +18 -17
- package/dist/lib/{initControlPlane-3TUdhRBM.js.map → initControlPlane-BRIIOzoH.js.map} +1 -1
- package/dist/lib/{markdown-BFUTPQoO.js → markdown-Cq4sVwUT.js} +4 -4
- package/dist/lib/{markdown-BFUTPQoO.js.map → markdown-Cq4sVwUT.js.map} +1 -1
- package/dist/lib/{mcp-reconnect-BxJ77WSb.js → mcp-reconnect-CoHDMjmY.js} +2 -2
- package/dist/lib/{mcp-reconnect-BxJ77WSb.js.map → mcp-reconnect-CoHDMjmY.js.map} +1 -1
- package/dist/lib/{memoryStorage-D3FBwO9T.js → memoryStorage-DcFWrn_y.js} +2 -2
- package/dist/lib/{memoryStorage-D3FBwO9T.js.map → memoryStorage-DcFWrn_y.js.map} +1 -1
- package/dist/lib/{orchestrator-DW5l2bbW.js → orchestrator-C3TgDZvq.js} +81 -18
- package/dist/lib/{orchestrator-DW5l2bbW.js.map → orchestrator-C3TgDZvq.js.map} +1 -1
- package/dist/lib/{orchestrator-DLnCmeTZ.js → orchestrator-Ce9_lmL2.js} +12 -12
- package/dist/lib/{orchestrator-DLnCmeTZ.js.map → orchestrator-Ce9_lmL2.js.map} +1 -1
- package/dist/lib/{peerjs-BXlMuIQn.js → peerjs-PTYQ7yEG.js} +6 -6
- package/dist/lib/{peerjs-BXlMuIQn.js.map → peerjs-PTYQ7yEG.js.map} +1 -1
- package/dist/lib/{push-client-B419nn-i.js → push-client-DDV5Rcg6.js} +3 -3
- package/dist/lib/{push-client-B419nn-i.js.map → push-client-DDV5Rcg6.js.map} +1 -1
- package/dist/lib/{readGroupFileBytes-CSA7u-nJ.js → readGroupFileBytes-7C8G-yps.js} +2 -2
- package/dist/lib/{readGroupFileBytes-CSA7u-nJ.js.map → readGroupFileBytes-7C8G-yps.js.map} +1 -1
- package/dist/lib/{shadow-claw-DmMO4vVG.js → shadow-claw-WrWoPqFx.js} +10 -10
- package/dist/lib/{shadow-claw-DmMO4vVG.js.map → shadow-claw-WrWoPqFx.js.map} +1 -1
- package/dist/lib/{shadow-claw-a2ui-2I5nffIn.js → shadow-claw-a2ui-CcmJNXQP.js} +2 -2
- package/dist/lib/{shadow-claw-a2ui-2I5nffIn.js.map → shadow-claw-a2ui-CcmJNXQP.js.map} +1 -1
- package/dist/lib/{shadow-claw-accounts-DMb0y4ca.js → shadow-claw-accounts-CcB2429E.js} +3 -3
- package/dist/lib/{shadow-claw-accounts-DMb0y4ca.js.map → shadow-claw-accounts-CcB2429E.js.map} +1 -1
- package/dist/lib/{shadow-claw-channel-config-BhxHf6wZ.js → shadow-claw-channel-config-C4v0h8oa.js} +3 -3
- package/dist/lib/{shadow-claw-channel-config-BhxHf6wZ.js.map → shadow-claw-channel-config-C4v0h8oa.js.map} +1 -1
- package/dist/lib/{shadow-claw-channels-B5vzE9Z2.js → shadow-claw-channels-CyV88k9T.js} +3 -3
- package/dist/lib/{shadow-claw-channels-B5vzE9Z2.js.map → shadow-claw-channels-CyV88k9T.js.map} +1 -1
- package/dist/lib/{shadow-claw-chat-BsYnJ4-G.js → shadow-claw-chat-DSYtuZod.js} +11 -11
- package/dist/lib/{shadow-claw-chat-BsYnJ4-G.js.map → shadow-claw-chat-DSYtuZod.js.map} +1 -1
- package/dist/lib/{shadow-claw-control-plane-DqcgQsun.js → shadow-claw-control-plane-DBSGuDT1.js} +7 -7
- package/dist/lib/{shadow-claw-control-plane-DqcgQsun.js.map → shadow-claw-control-plane-DBSGuDT1.js.map} +1 -1
- package/dist/lib/{shadow-claw-conversations-B9Pn58g3.js → shadow-claw-conversations-Cp8pK4PM.js} +5 -5
- package/dist/lib/{shadow-claw-conversations-B9Pn58g3.js.map → shadow-claw-conversations-Cp8pK4PM.js.map} +1 -1
- package/dist/lib/{shadow-claw-file-viewer-DL6c4oPK.js → shadow-claw-file-viewer-B8G8yo48.js} +8 -8
- package/dist/lib/{shadow-claw-file-viewer-DL6c4oPK.js.map → shadow-claw-file-viewer-B8G8yo48.js.map} +1 -1
- package/dist/lib/{shadow-claw-files-C_ksPb8W.js → shadow-claw-files-D1COKzuC.js} +9 -9
- package/dist/lib/{shadow-claw-files-C_ksPb8W.js.map → shadow-claw-files-D1COKzuC.js.map} +1 -1
- package/dist/lib/{shadow-claw-git-jwsY7L1N.js → shadow-claw-git-60tWU4Ee.js} +6 -6
- package/dist/lib/{shadow-claw-git-jwsY7L1N.js.map → shadow-claw-git-60tWU4Ee.js.map} +1 -1
- package/dist/lib/{shadow-claw-integrations-yT7j07TM.js → shadow-claw-integrations-Bw1cG1ze.js} +4 -4
- package/dist/lib/{shadow-claw-integrations-yT7j07TM.js.map → shadow-claw-integrations-Bw1cG1ze.js.map} +1 -1
- package/dist/lib/{shadow-claw-llm-CEPJh1Jh.js → shadow-claw-llm-By5CvsFJ.js} +6 -6
- package/dist/lib/{shadow-claw-llm-CEPJh1Jh.js.map → shadow-claw-llm-By5CvsFJ.js.map} +1 -1
- package/dist/lib/{shadow-claw-mcp-remote-DGDWjByQ.js → shadow-claw-mcp-remote-BaNODd1v.js} +4 -4
- package/dist/lib/{shadow-claw-mcp-remote-DGDWjByQ.js.map → shadow-claw-mcp-remote-BaNODd1v.js.map} +1 -1
- package/dist/lib/{shadow-claw-networking-Bi4yvc73.js → shadow-claw-networking-DtZ5bsTz.js} +2 -2
- package/dist/lib/{shadow-claw-networking-Bi4yvc73.js.map → shadow-claw-networking-DtZ5bsTz.js.map} +1 -1
- package/dist/lib/{shadow-claw-notifications-C-JgGqQx.js → shadow-claw-notifications-C3VEba_A.js} +3 -3
- package/dist/lib/{shadow-claw-notifications-C-JgGqQx.js.map → shadow-claw-notifications-C3VEba_A.js.map} +1 -1
- package/dist/lib/{shadow-claw-page-header-DrAcWCZ9.js → shadow-claw-page-header-BLowJopA.js} +2 -2
- package/dist/lib/{shadow-claw-page-header-DrAcWCZ9.js.map → shadow-claw-page-header-BLowJopA.js.map} +1 -1
- package/dist/lib/{shadow-claw-pages-OEOClgA8.js → shadow-claw-pages-CpeUV-hw.js} +9 -9
- package/dist/lib/{shadow-claw-pages-OEOClgA8.js.map → shadow-claw-pages-CpeUV-hw.js.map} +1 -1
- package/dist/lib/{shadow-claw-peerjs-DmC2CV-9.js → shadow-claw-peerjs-DYAzJbTy.js} +3 -3
- package/dist/lib/{shadow-claw-peerjs-DmC2CV-9.js.map → shadow-claw-peerjs-DYAzJbTy.js.map} +1 -1
- package/dist/lib/{shadow-claw-settings-xAtFog0T.js → shadow-claw-settings-ByxwW3WK.js} +9 -9
- package/dist/lib/{shadow-claw-settings-xAtFog0T.js.map → shadow-claw-settings-ByxwW3WK.js.map} +1 -1
- package/dist/lib/{shadow-claw-storage-B4UHl-po.js → shadow-claw-storage-CsSPYVDJ.js} +5 -5
- package/dist/lib/{shadow-claw-storage-B4UHl-po.js.map → shadow-claw-storage-CsSPYVDJ.js.map} +1 -1
- package/dist/lib/{shadow-claw-task-server-B0eWzg57.js → shadow-claw-task-server-De2WCEw4.js} +2 -2
- package/dist/lib/{shadow-claw-task-server-B0eWzg57.js.map → shadow-claw-task-server-De2WCEw4.js.map} +1 -1
- package/dist/lib/{shadow-claw-tasks-HHU_8Gyg.js → shadow-claw-tasks-zHWT4GaE.js} +7 -7
- package/dist/lib/{shadow-claw-tasks-HHU_8Gyg.js.map → shadow-claw-tasks-zHWT4GaE.js.map} +1 -1
- package/dist/lib/{shadow-claw-terminal-CdC2G6Zz.js → shadow-claw-terminal-Bpawfv4N.js} +2 -2
- package/dist/lib/{shadow-claw-terminal-CdC2G6Zz.js.map → shadow-claw-terminal-Bpawfv4N.js.map} +1 -1
- package/dist/lib/{shadow-claw-tools-2AICxVXA.js → shadow-claw-tools-BbKdWcps.js} +7 -7
- package/dist/lib/{shadow-claw-tools-2AICxVXA.js.map → shadow-claw-tools-BbKdWcps.js.map} +1 -1
- package/dist/lib/{shadow-claw-webvm-Cy-Ia2vs.js → shadow-claw-webvm-DLqK0AxW.js} +3 -3
- package/dist/lib/{shadow-claw-webvm-Cy-Ia2vs.js.map → shadow-claw-webvm-DLqK0AxW.js.map} +1 -1
- package/dist/lib/subsystems/mcp/webmcp.d.ts +37 -0
- package/dist/lib/subsystems/providers/model-registry.d.ts +4 -1
- package/dist/lib/subsystems/providers/providers.d.ts +10 -0
- package/dist/lib/{syncWebMcpRegistration-CaAPPg2V.js → syncWebMcpRegistration-mlbbvcdm.js} +5 -5
- package/dist/lib/{syncWebMcpRegistration-CaAPPg2V.js.map → syncWebMcpRegistration-mlbbvcdm.js.map} +1 -1
- package/dist/lib/{tools-f1WPNDSS.js → tools-Bb2ujM2E.js} +4 -4
- package/dist/lib/{tools-f1WPNDSS.js.map → tools-Bb2ujM2E.js.map} +1 -1
- package/dist/lib/utils/index.js +1 -1
- package/dist/lib/utils/utils.js +1 -1
- package/dist/lib/{utils-B99XP70b.js → utils-mpsYPfS7.js} +3 -3
- package/dist/lib/{utils-B99XP70b.js.map → utils-mpsYPfS7.js.map} +1 -1
- package/dist/lib/webmcp-BVR2lBVo.js +1544 -0
- package/dist/lib/webmcp-BVR2lBVo.js.map +1 -0
- package/dist/public/.well-known/mcp/server-card.json +1 -1
- package/dist/public/.well-known/mcp.json +1 -1
- package/dist/public/agent.worker.js +44 -44
- package/dist/public/config-BqecTktB.js +1 -0
- package/dist/public/{configurePeerJs--JGpJVti.js → configurePeerJs-BPKfWuEt.js} +1 -1
- package/dist/public/{connections-6575KDGE.js → connections-C_3tYsmX.js} +1 -1
- package/dist/public/{custom-element-security-Da_6HQ6X.js → custom-element-security-DXwU3Lae.js} +1 -1
- package/dist/public/docs/example/article/index.html +2 -2
- package/dist/public/docs/publishing/index.html +2 -2
- package/dist/public/docs/skill-creator/index.html +2 -2
- package/dist/public/docs/subsystems/tools.md +4 -3
- package/dist/public/docs/subsystems/webmcp.md +58 -13
- package/dist/public/{downloadGroupFile-Dj-AMNsd.js → downloadGroupFile-DTyf5DIC.js} +1 -1
- package/dist/public/{e2e-bridge-CbYqdMp-.js → e2e-bridge-DXwWCQKw.js} +1 -1
- package/dist/public/{file-viewer-vHJ5Zsgk.js → file-viewer-ConEyDDG.js} +1 -1
- package/dist/public/{getGroupDir-BwprrdrQ.js → getGroupDir-ZfZsiq6d.js} +1 -1
- package/dist/public/{git-8F7wvoUB.js → git-BtBaLC1-.js} +2 -2
- package/dist/public/{iframe-sanitizer-viROQkRn.js → iframe-sanitizer-Corkvo_d.js} +1 -1
- package/dist/public/index.html +2 -2
- package/dist/public/index.js +1 -1
- package/dist/public/{initChatSplitResize-BA18wLQQ.js → initChatSplitResize-CUc-TEmT.js} +1 -1
- package/dist/public/{initControlPlane-C5v0FtJE.js → initControlPlane-B_uYS8a4.js} +1 -1
- package/dist/public/main/index.html +2 -2
- package/dist/public/main/memory/index.html +2 -2
- package/dist/public/{markdown-eFKxxpVP.js → markdown-Cfa6GuJs.js} +1 -1
- package/dist/public/{mcp-reconnect-CBHuaYdF.js → mcp-reconnect-CUOkdPEz.js} +1 -1
- package/dist/public/{memoryStorage-C1llaYus.js → memoryStorage-Bh8fjmip.js} +1 -1
- package/dist/public/{orchestrator-DNr2HDI2.js → orchestrator-BcSzrg6E.js} +2 -2
- package/dist/public/{orchestrator-BeJfwtvz.js → orchestrator-Bi5OdVZD.js} +11 -11
- package/dist/public/{peerjs-mG30TAJ_.js → peerjs-CzCXG-NW.js} +1 -1
- package/dist/public/{push-client-C2zMT3Sf.js → push-client-Cr3Ruahp.js} +1 -1
- package/dist/public/service-worker.js +1 -1
- package/dist/public/{shadow-claw-Ble6l0Iw.js → shadow-claw-CzUYuuOa.js} +2 -2
- package/dist/public/{shadow-claw-accounts-D1y-zbMs.js → shadow-claw-accounts-BgIHB_aP.js} +1 -1
- package/dist/public/{shadow-claw-channels-D_xfBoWp.js → shadow-claw-channels-Ce_trJ5D.js} +1 -1
- package/dist/public/{shadow-claw-chat-D_Lbi5oH.js → shadow-claw-chat-CdECLLwL.js} +1 -1
- package/dist/public/{shadow-claw-control-plane-CrnA5lM0.js → shadow-claw-control-plane-DM62UmOz.js} +2 -2
- package/dist/public/{shadow-claw-conversations-BN-hFmN1.js → shadow-claw-conversations-AM5g3C00.js} +1 -1
- package/dist/public/{shadow-claw-file-viewer-BKEpzpbx.js → shadow-claw-file-viewer-BP7gWS5g.js} +1 -1
- package/dist/public/{shadow-claw-files-DDZMk5AA.js → shadow-claw-files-RPPGszcK.js} +1 -1
- package/dist/public/{shadow-claw-git-CqOO97Re.js → shadow-claw-git-BsHEvLrb.js} +2 -2
- package/dist/public/{shadow-claw-integrations-CRGL78Fy.js → shadow-claw-integrations-B0vbcOqg.js} +1 -1
- package/dist/public/{shadow-claw-llm-DoGxEHQL.js → shadow-claw-llm-FNNamrc_.js} +2 -2
- package/dist/public/{shadow-claw-mcp-remote-DyGnK4S_.js → shadow-claw-mcp-remote-7mDgniQu.js} +1 -1
- package/dist/public/{shadow-claw-networking-DJeCdb7e.js → shadow-claw-networking-CGsetaLp.js} +1 -1
- package/dist/public/{shadow-claw-notifications-hSKJeMXb.js → shadow-claw-notifications-pnwRcR-4.js} +1 -1
- package/dist/public/{shadow-claw-page-header-DA-FG08G.js → shadow-claw-page-header-BUy15Poz.js} +1 -1
- package/dist/public/{shadow-claw-pages-DTS98Zbi.js → shadow-claw-pages-ILAjGWNk.js} +1 -1
- package/dist/public/{shadow-claw-settings-5w0ce8SP.js → shadow-claw-settings-Bx5IgVqN.js} +3 -3
- package/dist/public/{shadow-claw-storage-DqlVt27X.js → shadow-claw-storage-PAtNykaF.js} +1 -1
- package/dist/public/{shadow-claw-task-server-ByZwKI6S.js → shadow-claw-task-server-Cbbi_2OO.js} +1 -1
- package/dist/public/{shadow-claw-tasks-Dc4G4zBu.js → shadow-claw-tasks-B-jKYWZJ.js} +1 -1
- package/dist/public/{shadow-claw-terminal-DvusP7wg.js → shadow-claw-terminal-BRejND-Z.js} +1 -1
- package/dist/public/{shadow-claw-tools-BEsid8q-.js → shadow-claw-tools-DNQe3oa-.js} +1 -1
- package/dist/public/{shadow-claw-webvm-BWlIeK78.js → shadow-claw-webvm-BFuwRifU.js} +1 -1
- package/dist/public/{syncWebMcpRegistration-CqVCB6m8.js → syncWebMcpRegistration-FxKAPwaz.js} +1 -1
- package/dist/public/theme-init.js +1 -1
- package/dist/public/{tools-Cp1gequ8.js → tools-BwQKGsro.js} +1 -1
- package/dist/public/transformers-js.worker.js +1 -1
- package/dist/public/webmcp-C28PAlfy.js +1 -0
- package/dist/server.js +1 -1
- package/package.json +3 -3
- package/src/core/utils/initControlPlane.test.ts +122 -1
- package/src/core/utils/initControlPlane.ts +12 -8
- package/src/subsystems/mcp/webmcp.test.ts +253 -1
- package/src/subsystems/mcp/webmcp.ts +147 -4
- package/src/subsystems/providers/model-registry.test.ts +139 -0
- package/src/subsystems/providers/model-registry.ts +54 -2
- package/src/subsystems/providers/providers.test.ts +329 -0
- package/src/subsystems/providers/providers.ts +135 -11
- package/dist/lib/config-DjZ9QWc4.js.map +0 -1
- package/dist/lib/webmcp-BC8_WafM.js +0 -1710
- package/dist/lib/webmcp-BC8_WafM.js.map +0 -1
- package/dist/public/config-Bnwx4EfS.js +0 -1
- package/dist/public/webmcp-DBONjQWd.js +0 -2
|
@@ -1,1710 +0,0 @@
|
|
|
1
|
-
import { n as __exportAll } from "./rolldown-runtime-DZ8SGSJo.js";
|
|
2
|
-
import { o as DEFAULT_GROUP_ID } from "./config-DjZ9QWc4.js";
|
|
3
|
-
import { t as TOOL_DEFINITIONS } from "./tools-DKzPWc0q.js";
|
|
4
|
-
import "./tools-C3Kft940.js";
|
|
5
|
-
|
|
6
|
-
//#region node_modules/@cfworker/json-schema/dist/esm/deep-compare-strict.js
|
|
7
|
-
function deepCompareStrict(a, b) {
|
|
8
|
-
const typeofa = typeof a;
|
|
9
|
-
if (typeofa !== typeof b) return false;
|
|
10
|
-
if (Array.isArray(a)) {
|
|
11
|
-
if (!Array.isArray(b)) return false;
|
|
12
|
-
const length = a.length;
|
|
13
|
-
if (length !== b.length) return false;
|
|
14
|
-
for (let i = 0; i < length; i++) if (!deepCompareStrict(a[i], b[i])) return false;
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
if (typeofa === "object") {
|
|
18
|
-
if (!a || !b) return a === b;
|
|
19
|
-
const aKeys = Object.keys(a);
|
|
20
|
-
const bKeys = Object.keys(b);
|
|
21
|
-
if (aKeys.length !== bKeys.length) return false;
|
|
22
|
-
for (const k of aKeys) if (!deepCompareStrict(a[k], b[k])) return false;
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
return a === b;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region node_modules/@cfworker/json-schema/dist/esm/pointer.js
|
|
30
|
-
function encodePointer(p) {
|
|
31
|
-
return encodeURI(escapePointer(p));
|
|
32
|
-
}
|
|
33
|
-
function escapePointer(p) {
|
|
34
|
-
return p.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
//#endregion
|
|
38
|
-
//#region node_modules/@cfworker/json-schema/dist/esm/dereference.js
|
|
39
|
-
const schemaArrayKeyword = {
|
|
40
|
-
prefixItems: true,
|
|
41
|
-
items: true,
|
|
42
|
-
allOf: true,
|
|
43
|
-
anyOf: true,
|
|
44
|
-
oneOf: true
|
|
45
|
-
};
|
|
46
|
-
const schemaMapKeyword = {
|
|
47
|
-
$defs: true,
|
|
48
|
-
definitions: true,
|
|
49
|
-
properties: true,
|
|
50
|
-
patternProperties: true,
|
|
51
|
-
dependentSchemas: true
|
|
52
|
-
};
|
|
53
|
-
const ignoredKeyword = {
|
|
54
|
-
id: true,
|
|
55
|
-
$id: true,
|
|
56
|
-
$ref: true,
|
|
57
|
-
$schema: true,
|
|
58
|
-
$anchor: true,
|
|
59
|
-
$vocabulary: true,
|
|
60
|
-
$comment: true,
|
|
61
|
-
default: true,
|
|
62
|
-
enum: true,
|
|
63
|
-
const: true,
|
|
64
|
-
required: true,
|
|
65
|
-
type: true,
|
|
66
|
-
maximum: true,
|
|
67
|
-
minimum: true,
|
|
68
|
-
exclusiveMaximum: true,
|
|
69
|
-
exclusiveMinimum: true,
|
|
70
|
-
multipleOf: true,
|
|
71
|
-
maxLength: true,
|
|
72
|
-
minLength: true,
|
|
73
|
-
pattern: true,
|
|
74
|
-
format: true,
|
|
75
|
-
maxItems: true,
|
|
76
|
-
minItems: true,
|
|
77
|
-
uniqueItems: true,
|
|
78
|
-
maxProperties: true,
|
|
79
|
-
minProperties: true
|
|
80
|
-
};
|
|
81
|
-
let initialBaseURI = typeof self !== "undefined" && self.location && self.location.origin !== "null" ? new URL(self.location.origin + self.location.pathname + location.search) : new URL("https://github.com/cfworker");
|
|
82
|
-
function dereference(schema, lookup = Object.create(null), baseURI = initialBaseURI, basePointer = "") {
|
|
83
|
-
if (schema && typeof schema === "object" && !Array.isArray(schema)) {
|
|
84
|
-
const id = schema.$id || schema.id;
|
|
85
|
-
if (id) {
|
|
86
|
-
const url = new URL(id, baseURI.href);
|
|
87
|
-
if (url.hash.length > 1) lookup[url.href] = schema;
|
|
88
|
-
else {
|
|
89
|
-
url.hash = "";
|
|
90
|
-
if (basePointer === "") baseURI = url;
|
|
91
|
-
else dereference(schema, lookup, baseURI);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
} else if (schema !== true && schema !== false) return lookup;
|
|
95
|
-
const schemaURI = baseURI.href + (basePointer ? "#" + basePointer : "");
|
|
96
|
-
if (lookup[schemaURI] !== void 0) throw new Error(`Duplicate schema URI "${schemaURI}".`);
|
|
97
|
-
lookup[schemaURI] = schema;
|
|
98
|
-
if (schema === true || schema === false) return lookup;
|
|
99
|
-
if (schema.__absolute_uri__ === void 0) Object.defineProperty(schema, "__absolute_uri__", {
|
|
100
|
-
enumerable: false,
|
|
101
|
-
value: schemaURI
|
|
102
|
-
});
|
|
103
|
-
if (schema.$ref && schema.__absolute_ref__ === void 0) {
|
|
104
|
-
const url = new URL(schema.$ref, baseURI.href);
|
|
105
|
-
url.hash = url.hash;
|
|
106
|
-
Object.defineProperty(schema, "__absolute_ref__", {
|
|
107
|
-
enumerable: false,
|
|
108
|
-
value: url.href
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
if (schema.$recursiveRef && schema.__absolute_recursive_ref__ === void 0) {
|
|
112
|
-
const url = new URL(schema.$recursiveRef, baseURI.href);
|
|
113
|
-
url.hash = url.hash;
|
|
114
|
-
Object.defineProperty(schema, "__absolute_recursive_ref__", {
|
|
115
|
-
enumerable: false,
|
|
116
|
-
value: url.href
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
if (schema.$anchor) {
|
|
120
|
-
const url = new URL("#" + schema.$anchor, baseURI.href);
|
|
121
|
-
lookup[url.href] = schema;
|
|
122
|
-
}
|
|
123
|
-
for (let key in schema) {
|
|
124
|
-
if (ignoredKeyword[key]) continue;
|
|
125
|
-
const keyBase = `${basePointer}/${encodePointer(key)}`;
|
|
126
|
-
const subSchema = schema[key];
|
|
127
|
-
if (Array.isArray(subSchema)) {
|
|
128
|
-
if (schemaArrayKeyword[key]) {
|
|
129
|
-
const length = subSchema.length;
|
|
130
|
-
for (let i = 0; i < length; i++) dereference(subSchema[i], lookup, baseURI, `${keyBase}/${i}`);
|
|
131
|
-
}
|
|
132
|
-
} else if (schemaMapKeyword[key]) for (let subKey in subSchema) dereference(subSchema[subKey], lookup, baseURI, `${keyBase}/${encodePointer(subKey)}`);
|
|
133
|
-
else dereference(subSchema, lookup, baseURI, keyBase);
|
|
134
|
-
}
|
|
135
|
-
return lookup;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
//#endregion
|
|
139
|
-
//#region node_modules/@cfworker/json-schema/dist/esm/format.js
|
|
140
|
-
const DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
|
|
141
|
-
const DAYS = [
|
|
142
|
-
0,
|
|
143
|
-
31,
|
|
144
|
-
28,
|
|
145
|
-
31,
|
|
146
|
-
30,
|
|
147
|
-
31,
|
|
148
|
-
30,
|
|
149
|
-
31,
|
|
150
|
-
31,
|
|
151
|
-
30,
|
|
152
|
-
31,
|
|
153
|
-
30,
|
|
154
|
-
31
|
|
155
|
-
];
|
|
156
|
-
const TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i;
|
|
157
|
-
const HOSTNAME = /^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i;
|
|
158
|
-
const URIREF = /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
|
159
|
-
const URITEMPLATE = /^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i;
|
|
160
|
-
const URL_ = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)(?:\.(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu;
|
|
161
|
-
const UUID = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
|
|
162
|
-
const JSON_POINTER = /^(?:\/(?:[^~/]|~0|~1)*)*$/;
|
|
163
|
-
const JSON_POINTER_URI_FRAGMENT = /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;
|
|
164
|
-
const RELATIVE_JSON_POINTER = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;
|
|
165
|
-
const EMAIL = (input) => {
|
|
166
|
-
if (input[0] === "\"") return false;
|
|
167
|
-
const [name, host, ...rest] = input.split("@");
|
|
168
|
-
if (!name || !host || rest.length !== 0 || name.length > 64 || host.length > 253) return false;
|
|
169
|
-
if (name[0] === "." || name.endsWith(".") || name.includes("..")) return false;
|
|
170
|
-
if (!/^[a-z0-9.-]+$/i.test(host) || !/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+$/i.test(name)) return false;
|
|
171
|
-
return host.split(".").every((part) => /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/i.test(part));
|
|
172
|
-
};
|
|
173
|
-
const IPV4 = /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/;
|
|
174
|
-
const IPV6 = /^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i;
|
|
175
|
-
const DURATION = (input) => input.length > 1 && input.length < 80 && (/^P\d+([.,]\d+)?W$/.test(input) || /^P[\dYMDTHS]*(\d[.,]\d+)?[YMDHS]$/.test(input) && /^P([.,\d]+Y)?([.,\d]+M)?([.,\d]+D)?(T([.,\d]+H)?([.,\d]+M)?([.,\d]+S)?)?$/.test(input));
|
|
176
|
-
function bind(r) {
|
|
177
|
-
return r.test.bind(r);
|
|
178
|
-
}
|
|
179
|
-
const format = {
|
|
180
|
-
date,
|
|
181
|
-
time: time.bind(void 0, false),
|
|
182
|
-
"date-time": date_time,
|
|
183
|
-
duration: DURATION,
|
|
184
|
-
uri,
|
|
185
|
-
"uri-reference": bind(URIREF),
|
|
186
|
-
"uri-template": bind(URITEMPLATE),
|
|
187
|
-
url: bind(URL_),
|
|
188
|
-
email: EMAIL,
|
|
189
|
-
hostname: bind(HOSTNAME),
|
|
190
|
-
ipv4: bind(IPV4),
|
|
191
|
-
ipv6: bind(IPV6),
|
|
192
|
-
regex,
|
|
193
|
-
uuid: bind(UUID),
|
|
194
|
-
"json-pointer": bind(JSON_POINTER),
|
|
195
|
-
"json-pointer-uri-fragment": bind(JSON_POINTER_URI_FRAGMENT),
|
|
196
|
-
"relative-json-pointer": bind(RELATIVE_JSON_POINTER)
|
|
197
|
-
};
|
|
198
|
-
function isLeapYear(year) {
|
|
199
|
-
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
200
|
-
}
|
|
201
|
-
function date(str) {
|
|
202
|
-
const matches = str.match(DATE);
|
|
203
|
-
if (!matches) return false;
|
|
204
|
-
const year = +matches[1];
|
|
205
|
-
const month = +matches[2];
|
|
206
|
-
const day = +matches[3];
|
|
207
|
-
return month >= 1 && month <= 12 && day >= 1 && day <= (month == 2 && isLeapYear(year) ? 29 : DAYS[month]);
|
|
208
|
-
}
|
|
209
|
-
function time(full, str) {
|
|
210
|
-
const matches = str.match(TIME);
|
|
211
|
-
if (!matches) return false;
|
|
212
|
-
const hour = +matches[1];
|
|
213
|
-
const minute = +matches[2];
|
|
214
|
-
const second = +matches[3];
|
|
215
|
-
const timeZone = !!matches[5];
|
|
216
|
-
return (hour <= 23 && minute <= 59 && second <= 59 || hour == 23 && minute == 59 && second == 60) && (!full || timeZone);
|
|
217
|
-
}
|
|
218
|
-
const DATE_TIME_SEPARATOR = /t|\s/i;
|
|
219
|
-
function date_time(str) {
|
|
220
|
-
const dateTime = str.split(DATE_TIME_SEPARATOR);
|
|
221
|
-
return dateTime.length == 2 && date(dateTime[0]) && time(true, dateTime[1]);
|
|
222
|
-
}
|
|
223
|
-
const NOT_URI_FRAGMENT = /\/|:/;
|
|
224
|
-
const URI_PATTERN = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
|
225
|
-
function uri(str) {
|
|
226
|
-
return NOT_URI_FRAGMENT.test(str) && URI_PATTERN.test(str);
|
|
227
|
-
}
|
|
228
|
-
const Z_ANCHOR = /[^\\]\\Z/;
|
|
229
|
-
function regex(str) {
|
|
230
|
-
if (Z_ANCHOR.test(str)) return false;
|
|
231
|
-
try {
|
|
232
|
-
new RegExp(str, "u");
|
|
233
|
-
return true;
|
|
234
|
-
} catch (e) {
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
//#endregion
|
|
240
|
-
//#region node_modules/@cfworker/json-schema/dist/esm/ucs2-length.js
|
|
241
|
-
function ucs2length(s) {
|
|
242
|
-
let result = 0;
|
|
243
|
-
let length = s.length;
|
|
244
|
-
let index = 0;
|
|
245
|
-
let charCode;
|
|
246
|
-
while (index < length) {
|
|
247
|
-
result++;
|
|
248
|
-
charCode = s.charCodeAt(index++);
|
|
249
|
-
if (charCode >= 55296 && charCode <= 56319 && index < length) {
|
|
250
|
-
charCode = s.charCodeAt(index);
|
|
251
|
-
if ((charCode & 64512) == 56320) index++;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return result;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
//#endregion
|
|
258
|
-
//#region node_modules/@cfworker/json-schema/dist/esm/validate.js
|
|
259
|
-
function validate(instance, schema, draft = "2019-09", lookup = dereference(schema), shortCircuit = true, recursiveAnchor = null, instanceLocation = "#", schemaLocation = "#", evaluated = Object.create(null)) {
|
|
260
|
-
if (schema === true) return {
|
|
261
|
-
valid: true,
|
|
262
|
-
errors: []
|
|
263
|
-
};
|
|
264
|
-
if (schema === false) return {
|
|
265
|
-
valid: false,
|
|
266
|
-
errors: [{
|
|
267
|
-
instanceLocation,
|
|
268
|
-
keyword: "false",
|
|
269
|
-
keywordLocation: instanceLocation,
|
|
270
|
-
error: "False boolean schema."
|
|
271
|
-
}]
|
|
272
|
-
};
|
|
273
|
-
const rawInstanceType = typeof instance;
|
|
274
|
-
let instanceType;
|
|
275
|
-
switch (rawInstanceType) {
|
|
276
|
-
case "boolean":
|
|
277
|
-
case "number":
|
|
278
|
-
case "string":
|
|
279
|
-
instanceType = rawInstanceType;
|
|
280
|
-
break;
|
|
281
|
-
case "object":
|
|
282
|
-
if (instance === null) instanceType = "null";
|
|
283
|
-
else if (Array.isArray(instance)) instanceType = "array";
|
|
284
|
-
else instanceType = "object";
|
|
285
|
-
break;
|
|
286
|
-
default: throw new Error(`Instances of "${rawInstanceType}" type are not supported.`);
|
|
287
|
-
}
|
|
288
|
-
const { $ref, $recursiveRef, $recursiveAnchor, type: $type, const: $const, enum: $enum, required: $required, not: $not, anyOf: $anyOf, allOf: $allOf, oneOf: $oneOf, if: $if, then: $then, else: $else, format: $format, properties: $properties, patternProperties: $patternProperties, additionalProperties: $additionalProperties, unevaluatedProperties: $unevaluatedProperties, minProperties: $minProperties, maxProperties: $maxProperties, propertyNames: $propertyNames, dependentRequired: $dependentRequired, dependentSchemas: $dependentSchemas, dependencies: $dependencies, prefixItems: $prefixItems, items: $items, additionalItems: $additionalItems, unevaluatedItems: $unevaluatedItems, contains: $contains, minContains: $minContains, maxContains: $maxContains, minItems: $minItems, maxItems: $maxItems, uniqueItems: $uniqueItems, minimum: $minimum, maximum: $maximum, exclusiveMinimum: $exclusiveMinimum, exclusiveMaximum: $exclusiveMaximum, multipleOf: $multipleOf, minLength: $minLength, maxLength: $maxLength, pattern: $pattern, __absolute_ref__, __absolute_recursive_ref__ } = schema;
|
|
289
|
-
const errors = [];
|
|
290
|
-
if ($recursiveAnchor === true && recursiveAnchor === null) recursiveAnchor = schema;
|
|
291
|
-
if ($recursiveRef === "#") {
|
|
292
|
-
const refSchema = recursiveAnchor === null ? lookup[__absolute_recursive_ref__] : recursiveAnchor;
|
|
293
|
-
const keywordLocation = `${schemaLocation}/$recursiveRef`;
|
|
294
|
-
const result = validate(instance, recursiveAnchor === null ? schema : recursiveAnchor, draft, lookup, shortCircuit, refSchema, instanceLocation, keywordLocation, evaluated);
|
|
295
|
-
if (!result.valid) errors.push({
|
|
296
|
-
instanceLocation,
|
|
297
|
-
keyword: "$recursiveRef",
|
|
298
|
-
keywordLocation,
|
|
299
|
-
error: "A subschema had errors."
|
|
300
|
-
}, ...result.errors);
|
|
301
|
-
}
|
|
302
|
-
if ($ref !== void 0) {
|
|
303
|
-
const refSchema = lookup[__absolute_ref__ || $ref];
|
|
304
|
-
if (refSchema === void 0) {
|
|
305
|
-
let message = `Unresolved $ref "${$ref}".`;
|
|
306
|
-
if (__absolute_ref__ && __absolute_ref__ !== $ref) message += ` Absolute URI "${__absolute_ref__}".`;
|
|
307
|
-
message += `\nKnown schemas:\n- ${Object.keys(lookup).join("\n- ")}`;
|
|
308
|
-
throw new Error(message);
|
|
309
|
-
}
|
|
310
|
-
const keywordLocation = `${schemaLocation}/$ref`;
|
|
311
|
-
const result = validate(instance, refSchema, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, keywordLocation, evaluated);
|
|
312
|
-
if (!result.valid) errors.push({
|
|
313
|
-
instanceLocation,
|
|
314
|
-
keyword: "$ref",
|
|
315
|
-
keywordLocation,
|
|
316
|
-
error: "A subschema had errors."
|
|
317
|
-
}, ...result.errors);
|
|
318
|
-
if (draft === "4" || draft === "7") return {
|
|
319
|
-
valid: errors.length === 0,
|
|
320
|
-
errors
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
if (Array.isArray($type)) {
|
|
324
|
-
let length = $type.length;
|
|
325
|
-
let valid = false;
|
|
326
|
-
for (let i = 0; i < length; i++) if (instanceType === $type[i] || $type[i] === "integer" && instanceType === "number" && instance % 1 === 0 && instance === instance) {
|
|
327
|
-
valid = true;
|
|
328
|
-
break;
|
|
329
|
-
}
|
|
330
|
-
if (!valid) errors.push({
|
|
331
|
-
instanceLocation,
|
|
332
|
-
keyword: "type",
|
|
333
|
-
keywordLocation: `${schemaLocation}/type`,
|
|
334
|
-
error: `Instance type "${instanceType}" is invalid. Expected "${$type.join("\", \"")}".`
|
|
335
|
-
});
|
|
336
|
-
} else if ($type === "integer") {
|
|
337
|
-
if (instanceType !== "number" || instance % 1 || instance !== instance) errors.push({
|
|
338
|
-
instanceLocation,
|
|
339
|
-
keyword: "type",
|
|
340
|
-
keywordLocation: `${schemaLocation}/type`,
|
|
341
|
-
error: `Instance type "${instanceType}" is invalid. Expected "${$type}".`
|
|
342
|
-
});
|
|
343
|
-
} else if ($type !== void 0 && instanceType !== $type) errors.push({
|
|
344
|
-
instanceLocation,
|
|
345
|
-
keyword: "type",
|
|
346
|
-
keywordLocation: `${schemaLocation}/type`,
|
|
347
|
-
error: `Instance type "${instanceType}" is invalid. Expected "${$type}".`
|
|
348
|
-
});
|
|
349
|
-
if ($const !== void 0) {
|
|
350
|
-
if (instanceType === "object" || instanceType === "array") {
|
|
351
|
-
if (!deepCompareStrict(instance, $const)) errors.push({
|
|
352
|
-
instanceLocation,
|
|
353
|
-
keyword: "const",
|
|
354
|
-
keywordLocation: `${schemaLocation}/const`,
|
|
355
|
-
error: `Instance does not match ${JSON.stringify($const)}.`
|
|
356
|
-
});
|
|
357
|
-
} else if (instance !== $const) errors.push({
|
|
358
|
-
instanceLocation,
|
|
359
|
-
keyword: "const",
|
|
360
|
-
keywordLocation: `${schemaLocation}/const`,
|
|
361
|
-
error: `Instance does not match ${JSON.stringify($const)}.`
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
if ($enum !== void 0) {
|
|
365
|
-
if (instanceType === "object" || instanceType === "array") {
|
|
366
|
-
if (!$enum.some((value) => deepCompareStrict(instance, value))) errors.push({
|
|
367
|
-
instanceLocation,
|
|
368
|
-
keyword: "enum",
|
|
369
|
-
keywordLocation: `${schemaLocation}/enum`,
|
|
370
|
-
error: `Instance does not match any of ${JSON.stringify($enum)}.`
|
|
371
|
-
});
|
|
372
|
-
} else if (!$enum.some((value) => instance === value)) errors.push({
|
|
373
|
-
instanceLocation,
|
|
374
|
-
keyword: "enum",
|
|
375
|
-
keywordLocation: `${schemaLocation}/enum`,
|
|
376
|
-
error: `Instance does not match any of ${JSON.stringify($enum)}.`
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
if ($not !== void 0) {
|
|
380
|
-
const keywordLocation = `${schemaLocation}/not`;
|
|
381
|
-
if (validate(instance, $not, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, keywordLocation).valid) errors.push({
|
|
382
|
-
instanceLocation,
|
|
383
|
-
keyword: "not",
|
|
384
|
-
keywordLocation,
|
|
385
|
-
error: "Instance matched \"not\" schema."
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
let subEvaluateds = [];
|
|
389
|
-
if ($anyOf !== void 0) {
|
|
390
|
-
const keywordLocation = `${schemaLocation}/anyOf`;
|
|
391
|
-
const errorsLength = errors.length;
|
|
392
|
-
let anyValid = false;
|
|
393
|
-
for (let i = 0; i < $anyOf.length; i++) {
|
|
394
|
-
const subSchema = $anyOf[i];
|
|
395
|
-
const subEvaluated = Object.create(evaluated);
|
|
396
|
-
const result = validate(instance, subSchema, draft, lookup, shortCircuit, $recursiveAnchor === true ? recursiveAnchor : null, instanceLocation, `${keywordLocation}/${i}`, subEvaluated);
|
|
397
|
-
errors.push(...result.errors);
|
|
398
|
-
anyValid = anyValid || result.valid;
|
|
399
|
-
if (result.valid) subEvaluateds.push(subEvaluated);
|
|
400
|
-
}
|
|
401
|
-
if (anyValid) errors.length = errorsLength;
|
|
402
|
-
else errors.splice(errorsLength, 0, {
|
|
403
|
-
instanceLocation,
|
|
404
|
-
keyword: "anyOf",
|
|
405
|
-
keywordLocation,
|
|
406
|
-
error: "Instance does not match any subschemas."
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
if ($allOf !== void 0) {
|
|
410
|
-
const keywordLocation = `${schemaLocation}/allOf`;
|
|
411
|
-
const errorsLength = errors.length;
|
|
412
|
-
let allValid = true;
|
|
413
|
-
for (let i = 0; i < $allOf.length; i++) {
|
|
414
|
-
const subSchema = $allOf[i];
|
|
415
|
-
const subEvaluated = Object.create(evaluated);
|
|
416
|
-
const result = validate(instance, subSchema, draft, lookup, shortCircuit, $recursiveAnchor === true ? recursiveAnchor : null, instanceLocation, `${keywordLocation}/${i}`, subEvaluated);
|
|
417
|
-
errors.push(...result.errors);
|
|
418
|
-
allValid = allValid && result.valid;
|
|
419
|
-
if (result.valid) subEvaluateds.push(subEvaluated);
|
|
420
|
-
}
|
|
421
|
-
if (allValid) errors.length = errorsLength;
|
|
422
|
-
else errors.splice(errorsLength, 0, {
|
|
423
|
-
instanceLocation,
|
|
424
|
-
keyword: "allOf",
|
|
425
|
-
keywordLocation,
|
|
426
|
-
error: `Instance does not match every subschema.`
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
if ($oneOf !== void 0) {
|
|
430
|
-
const keywordLocation = `${schemaLocation}/oneOf`;
|
|
431
|
-
const errorsLength = errors.length;
|
|
432
|
-
const matches = $oneOf.filter((subSchema, i) => {
|
|
433
|
-
const subEvaluated = Object.create(evaluated);
|
|
434
|
-
const result = validate(instance, subSchema, draft, lookup, shortCircuit, $recursiveAnchor === true ? recursiveAnchor : null, instanceLocation, `${keywordLocation}/${i}`, subEvaluated);
|
|
435
|
-
errors.push(...result.errors);
|
|
436
|
-
if (result.valid) subEvaluateds.push(subEvaluated);
|
|
437
|
-
return result.valid;
|
|
438
|
-
}).length;
|
|
439
|
-
if (matches === 1) errors.length = errorsLength;
|
|
440
|
-
else errors.splice(errorsLength, 0, {
|
|
441
|
-
instanceLocation,
|
|
442
|
-
keyword: "oneOf",
|
|
443
|
-
keywordLocation,
|
|
444
|
-
error: `Instance does not match exactly one subschema (${matches} matches).`
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
if (instanceType === "object" || instanceType === "array") Object.assign(evaluated, ...subEvaluateds);
|
|
448
|
-
if ($if !== void 0) {
|
|
449
|
-
const keywordLocation = `${schemaLocation}/if`;
|
|
450
|
-
if (validate(instance, $if, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, keywordLocation, evaluated).valid) {
|
|
451
|
-
if ($then !== void 0) {
|
|
452
|
-
const thenResult = validate(instance, $then, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${schemaLocation}/then`, evaluated);
|
|
453
|
-
if (!thenResult.valid) errors.push({
|
|
454
|
-
instanceLocation,
|
|
455
|
-
keyword: "if",
|
|
456
|
-
keywordLocation,
|
|
457
|
-
error: `Instance does not match "then" schema.`
|
|
458
|
-
}, ...thenResult.errors);
|
|
459
|
-
}
|
|
460
|
-
} else if ($else !== void 0) {
|
|
461
|
-
const elseResult = validate(instance, $else, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${schemaLocation}/else`, evaluated);
|
|
462
|
-
if (!elseResult.valid) errors.push({
|
|
463
|
-
instanceLocation,
|
|
464
|
-
keyword: "if",
|
|
465
|
-
keywordLocation,
|
|
466
|
-
error: `Instance does not match "else" schema.`
|
|
467
|
-
}, ...elseResult.errors);
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
if (instanceType === "object") {
|
|
471
|
-
if ($required !== void 0) {
|
|
472
|
-
for (const key of $required) if (!(key in instance)) errors.push({
|
|
473
|
-
instanceLocation,
|
|
474
|
-
keyword: "required",
|
|
475
|
-
keywordLocation: `${schemaLocation}/required`,
|
|
476
|
-
error: `Instance does not have required property "${key}".`
|
|
477
|
-
});
|
|
478
|
-
}
|
|
479
|
-
const keys = Object.keys(instance);
|
|
480
|
-
if ($minProperties !== void 0 && keys.length < $minProperties) errors.push({
|
|
481
|
-
instanceLocation,
|
|
482
|
-
keyword: "minProperties",
|
|
483
|
-
keywordLocation: `${schemaLocation}/minProperties`,
|
|
484
|
-
error: `Instance does not have at least ${$minProperties} properties.`
|
|
485
|
-
});
|
|
486
|
-
if ($maxProperties !== void 0 && keys.length > $maxProperties) errors.push({
|
|
487
|
-
instanceLocation,
|
|
488
|
-
keyword: "maxProperties",
|
|
489
|
-
keywordLocation: `${schemaLocation}/maxProperties`,
|
|
490
|
-
error: `Instance does not have at least ${$maxProperties} properties.`
|
|
491
|
-
});
|
|
492
|
-
if ($propertyNames !== void 0) {
|
|
493
|
-
const keywordLocation = `${schemaLocation}/propertyNames`;
|
|
494
|
-
for (const key in instance) {
|
|
495
|
-
const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
|
|
496
|
-
const result = validate(key, $propertyNames, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, keywordLocation);
|
|
497
|
-
if (!result.valid) errors.push({
|
|
498
|
-
instanceLocation,
|
|
499
|
-
keyword: "propertyNames",
|
|
500
|
-
keywordLocation,
|
|
501
|
-
error: `Property name "${key}" does not match schema.`
|
|
502
|
-
}, ...result.errors);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
if ($dependentRequired !== void 0) {
|
|
506
|
-
const keywordLocation = `${schemaLocation}/dependantRequired`;
|
|
507
|
-
for (const key in $dependentRequired) if (key in instance) {
|
|
508
|
-
const required = $dependentRequired[key];
|
|
509
|
-
for (const dependantKey of required) if (!(dependantKey in instance)) errors.push({
|
|
510
|
-
instanceLocation,
|
|
511
|
-
keyword: "dependentRequired",
|
|
512
|
-
keywordLocation,
|
|
513
|
-
error: `Instance has "${key}" but does not have "${dependantKey}".`
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
if ($dependentSchemas !== void 0) for (const key in $dependentSchemas) {
|
|
518
|
-
const keywordLocation = `${schemaLocation}/dependentSchemas`;
|
|
519
|
-
if (key in instance) {
|
|
520
|
-
const result = validate(instance, $dependentSchemas[key], draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${keywordLocation}/${encodePointer(key)}`, evaluated);
|
|
521
|
-
if (!result.valid) errors.push({
|
|
522
|
-
instanceLocation,
|
|
523
|
-
keyword: "dependentSchemas",
|
|
524
|
-
keywordLocation,
|
|
525
|
-
error: `Instance has "${key}" but does not match dependant schema.`
|
|
526
|
-
}, ...result.errors);
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
if ($dependencies !== void 0) {
|
|
530
|
-
const keywordLocation = `${schemaLocation}/dependencies`;
|
|
531
|
-
for (const key in $dependencies) if (key in instance) {
|
|
532
|
-
const propsOrSchema = $dependencies[key];
|
|
533
|
-
if (Array.isArray(propsOrSchema)) {
|
|
534
|
-
for (const dependantKey of propsOrSchema) if (!(dependantKey in instance)) errors.push({
|
|
535
|
-
instanceLocation,
|
|
536
|
-
keyword: "dependencies",
|
|
537
|
-
keywordLocation,
|
|
538
|
-
error: `Instance has "${key}" but does not have "${dependantKey}".`
|
|
539
|
-
});
|
|
540
|
-
} else {
|
|
541
|
-
const result = validate(instance, propsOrSchema, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${keywordLocation}/${encodePointer(key)}`);
|
|
542
|
-
if (!result.valid) errors.push({
|
|
543
|
-
instanceLocation,
|
|
544
|
-
keyword: "dependencies",
|
|
545
|
-
keywordLocation,
|
|
546
|
-
error: `Instance has "${key}" but does not match dependant schema.`
|
|
547
|
-
}, ...result.errors);
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
const thisEvaluated = Object.create(null);
|
|
552
|
-
let stop = false;
|
|
553
|
-
if ($properties !== void 0) {
|
|
554
|
-
const keywordLocation = `${schemaLocation}/properties`;
|
|
555
|
-
for (const key in $properties) {
|
|
556
|
-
if (!(key in instance)) continue;
|
|
557
|
-
const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
|
|
558
|
-
const result = validate(instance[key], $properties[key], draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, `${keywordLocation}/${encodePointer(key)}`);
|
|
559
|
-
if (result.valid) evaluated[key] = thisEvaluated[key] = true;
|
|
560
|
-
else {
|
|
561
|
-
stop = shortCircuit;
|
|
562
|
-
errors.push({
|
|
563
|
-
instanceLocation,
|
|
564
|
-
keyword: "properties",
|
|
565
|
-
keywordLocation,
|
|
566
|
-
error: `Property "${key}" does not match schema.`
|
|
567
|
-
}, ...result.errors);
|
|
568
|
-
if (stop) break;
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
if (!stop && $patternProperties !== void 0) {
|
|
573
|
-
const keywordLocation = `${schemaLocation}/patternProperties`;
|
|
574
|
-
for (const pattern in $patternProperties) {
|
|
575
|
-
const regex = new RegExp(pattern, "u");
|
|
576
|
-
const subSchema = $patternProperties[pattern];
|
|
577
|
-
for (const key in instance) {
|
|
578
|
-
if (!regex.test(key)) continue;
|
|
579
|
-
const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
|
|
580
|
-
const result = validate(instance[key], subSchema, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, `${keywordLocation}/${encodePointer(pattern)}`);
|
|
581
|
-
if (result.valid) evaluated[key] = thisEvaluated[key] = true;
|
|
582
|
-
else {
|
|
583
|
-
stop = shortCircuit;
|
|
584
|
-
errors.push({
|
|
585
|
-
instanceLocation,
|
|
586
|
-
keyword: "patternProperties",
|
|
587
|
-
keywordLocation,
|
|
588
|
-
error: `Property "${key}" matches pattern "${pattern}" but does not match associated schema.`
|
|
589
|
-
}, ...result.errors);
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
if (!stop && $additionalProperties !== void 0) {
|
|
595
|
-
const keywordLocation = `${schemaLocation}/additionalProperties`;
|
|
596
|
-
for (const key in instance) {
|
|
597
|
-
if (thisEvaluated[key]) continue;
|
|
598
|
-
const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
|
|
599
|
-
const result = validate(instance[key], $additionalProperties, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, keywordLocation);
|
|
600
|
-
if (result.valid) evaluated[key] = true;
|
|
601
|
-
else {
|
|
602
|
-
stop = shortCircuit;
|
|
603
|
-
errors.push({
|
|
604
|
-
instanceLocation,
|
|
605
|
-
keyword: "additionalProperties",
|
|
606
|
-
keywordLocation,
|
|
607
|
-
error: `Property "${key}" does not match additional properties schema.`
|
|
608
|
-
}, ...result.errors);
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
} else if (!stop && $unevaluatedProperties !== void 0) {
|
|
612
|
-
const keywordLocation = `${schemaLocation}/unevaluatedProperties`;
|
|
613
|
-
for (const key in instance) if (!evaluated[key]) {
|
|
614
|
-
const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
|
|
615
|
-
const result = validate(instance[key], $unevaluatedProperties, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, keywordLocation);
|
|
616
|
-
if (result.valid) evaluated[key] = true;
|
|
617
|
-
else errors.push({
|
|
618
|
-
instanceLocation,
|
|
619
|
-
keyword: "unevaluatedProperties",
|
|
620
|
-
keywordLocation,
|
|
621
|
-
error: `Property "${key}" does not match unevaluated properties schema.`
|
|
622
|
-
}, ...result.errors);
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
} else if (instanceType === "array") {
|
|
626
|
-
if ($maxItems !== void 0 && instance.length > $maxItems) errors.push({
|
|
627
|
-
instanceLocation,
|
|
628
|
-
keyword: "maxItems",
|
|
629
|
-
keywordLocation: `${schemaLocation}/maxItems`,
|
|
630
|
-
error: `Array has too many items (${instance.length} > ${$maxItems}).`
|
|
631
|
-
});
|
|
632
|
-
if ($minItems !== void 0 && instance.length < $minItems) errors.push({
|
|
633
|
-
instanceLocation,
|
|
634
|
-
keyword: "minItems",
|
|
635
|
-
keywordLocation: `${schemaLocation}/minItems`,
|
|
636
|
-
error: `Array has too few items (${instance.length} < ${$minItems}).`
|
|
637
|
-
});
|
|
638
|
-
const length = instance.length;
|
|
639
|
-
let i = 0;
|
|
640
|
-
let stop = false;
|
|
641
|
-
if ($prefixItems !== void 0) {
|
|
642
|
-
const keywordLocation = `${schemaLocation}/prefixItems`;
|
|
643
|
-
const length2 = Math.min($prefixItems.length, length);
|
|
644
|
-
for (; i < length2; i++) {
|
|
645
|
-
const result = validate(instance[i], $prefixItems[i], draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, `${keywordLocation}/${i}`);
|
|
646
|
-
evaluated[i] = true;
|
|
647
|
-
if (!result.valid) {
|
|
648
|
-
stop = shortCircuit;
|
|
649
|
-
errors.push({
|
|
650
|
-
instanceLocation,
|
|
651
|
-
keyword: "prefixItems",
|
|
652
|
-
keywordLocation,
|
|
653
|
-
error: `Items did not match schema.`
|
|
654
|
-
}, ...result.errors);
|
|
655
|
-
if (stop) break;
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
if ($items !== void 0) {
|
|
660
|
-
const keywordLocation = `${schemaLocation}/items`;
|
|
661
|
-
if (Array.isArray($items)) {
|
|
662
|
-
const length2 = Math.min($items.length, length);
|
|
663
|
-
for (; i < length2; i++) {
|
|
664
|
-
const result = validate(instance[i], $items[i], draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, `${keywordLocation}/${i}`);
|
|
665
|
-
evaluated[i] = true;
|
|
666
|
-
if (!result.valid) {
|
|
667
|
-
stop = shortCircuit;
|
|
668
|
-
errors.push({
|
|
669
|
-
instanceLocation,
|
|
670
|
-
keyword: "items",
|
|
671
|
-
keywordLocation,
|
|
672
|
-
error: `Items did not match schema.`
|
|
673
|
-
}, ...result.errors);
|
|
674
|
-
if (stop) break;
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
} else for (; i < length; i++) {
|
|
678
|
-
const result = validate(instance[i], $items, draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, keywordLocation);
|
|
679
|
-
evaluated[i] = true;
|
|
680
|
-
if (!result.valid) {
|
|
681
|
-
stop = shortCircuit;
|
|
682
|
-
errors.push({
|
|
683
|
-
instanceLocation,
|
|
684
|
-
keyword: "items",
|
|
685
|
-
keywordLocation,
|
|
686
|
-
error: `Items did not match schema.`
|
|
687
|
-
}, ...result.errors);
|
|
688
|
-
if (stop) break;
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
if (!stop && $additionalItems !== void 0) {
|
|
692
|
-
const keywordLocation = `${schemaLocation}/additionalItems`;
|
|
693
|
-
for (; i < length; i++) {
|
|
694
|
-
const result = validate(instance[i], $additionalItems, draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, keywordLocation);
|
|
695
|
-
evaluated[i] = true;
|
|
696
|
-
if (!result.valid) {
|
|
697
|
-
stop = shortCircuit;
|
|
698
|
-
errors.push({
|
|
699
|
-
instanceLocation,
|
|
700
|
-
keyword: "additionalItems",
|
|
701
|
-
keywordLocation,
|
|
702
|
-
error: `Items did not match additional items schema.`
|
|
703
|
-
}, ...result.errors);
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
if ($contains !== void 0) if (length === 0 && $minContains === void 0) errors.push({
|
|
709
|
-
instanceLocation,
|
|
710
|
-
keyword: "contains",
|
|
711
|
-
keywordLocation: `${schemaLocation}/contains`,
|
|
712
|
-
error: `Array is empty. It must contain at least one item matching the schema.`
|
|
713
|
-
});
|
|
714
|
-
else if ($minContains !== void 0 && length < $minContains) errors.push({
|
|
715
|
-
instanceLocation,
|
|
716
|
-
keyword: "minContains",
|
|
717
|
-
keywordLocation: `${schemaLocation}/minContains`,
|
|
718
|
-
error: `Array has less items (${length}) than minContains (${$minContains}).`
|
|
719
|
-
});
|
|
720
|
-
else {
|
|
721
|
-
const keywordLocation = `${schemaLocation}/contains`;
|
|
722
|
-
const errorsLength = errors.length;
|
|
723
|
-
let contained = 0;
|
|
724
|
-
for (let j = 0; j < length; j++) {
|
|
725
|
-
const result = validate(instance[j], $contains, draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${j}`, keywordLocation);
|
|
726
|
-
if (result.valid) {
|
|
727
|
-
evaluated[j] = true;
|
|
728
|
-
contained++;
|
|
729
|
-
} else errors.push(...result.errors);
|
|
730
|
-
}
|
|
731
|
-
if (contained >= ($minContains || 0)) errors.length = errorsLength;
|
|
732
|
-
if ($minContains === void 0 && $maxContains === void 0 && contained === 0) errors.splice(errorsLength, 0, {
|
|
733
|
-
instanceLocation,
|
|
734
|
-
keyword: "contains",
|
|
735
|
-
keywordLocation,
|
|
736
|
-
error: `Array does not contain item matching schema.`
|
|
737
|
-
});
|
|
738
|
-
else if ($minContains !== void 0 && contained < $minContains) errors.push({
|
|
739
|
-
instanceLocation,
|
|
740
|
-
keyword: "minContains",
|
|
741
|
-
keywordLocation: `${schemaLocation}/minContains`,
|
|
742
|
-
error: `Array must contain at least ${$minContains} items matching schema. Only ${contained} items were found.`
|
|
743
|
-
});
|
|
744
|
-
else if ($maxContains !== void 0 && contained > $maxContains) errors.push({
|
|
745
|
-
instanceLocation,
|
|
746
|
-
keyword: "maxContains",
|
|
747
|
-
keywordLocation: `${schemaLocation}/maxContains`,
|
|
748
|
-
error: `Array may contain at most ${$maxContains} items matching schema. ${contained} items were found.`
|
|
749
|
-
});
|
|
750
|
-
}
|
|
751
|
-
if (!stop && $unevaluatedItems !== void 0) {
|
|
752
|
-
const keywordLocation = `${schemaLocation}/unevaluatedItems`;
|
|
753
|
-
for (; i < length; i++) {
|
|
754
|
-
if (evaluated[i]) continue;
|
|
755
|
-
const result = validate(instance[i], $unevaluatedItems, draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, keywordLocation);
|
|
756
|
-
evaluated[i] = true;
|
|
757
|
-
if (!result.valid) errors.push({
|
|
758
|
-
instanceLocation,
|
|
759
|
-
keyword: "unevaluatedItems",
|
|
760
|
-
keywordLocation,
|
|
761
|
-
error: `Items did not match unevaluated items schema.`
|
|
762
|
-
}, ...result.errors);
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
if ($uniqueItems) for (let j = 0; j < length; j++) {
|
|
766
|
-
const a = instance[j];
|
|
767
|
-
const ao = typeof a === "object" && a !== null;
|
|
768
|
-
for (let k = 0; k < length; k++) {
|
|
769
|
-
if (j === k) continue;
|
|
770
|
-
const b = instance[k];
|
|
771
|
-
if (a === b || ao && typeof b === "object" && b !== null && deepCompareStrict(a, b)) {
|
|
772
|
-
errors.push({
|
|
773
|
-
instanceLocation,
|
|
774
|
-
keyword: "uniqueItems",
|
|
775
|
-
keywordLocation: `${schemaLocation}/uniqueItems`,
|
|
776
|
-
error: `Duplicate items at indexes ${j} and ${k}.`
|
|
777
|
-
});
|
|
778
|
-
j = Number.MAX_SAFE_INTEGER;
|
|
779
|
-
k = Number.MAX_SAFE_INTEGER;
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
} else if (instanceType === "number") {
|
|
784
|
-
if (draft === "4") {
|
|
785
|
-
if ($minimum !== void 0 && ($exclusiveMinimum === true && instance <= $minimum || instance < $minimum)) errors.push({
|
|
786
|
-
instanceLocation,
|
|
787
|
-
keyword: "minimum",
|
|
788
|
-
keywordLocation: `${schemaLocation}/minimum`,
|
|
789
|
-
error: `${instance} is less than ${$exclusiveMinimum ? "or equal to " : ""} ${$minimum}.`
|
|
790
|
-
});
|
|
791
|
-
if ($maximum !== void 0 && ($exclusiveMaximum === true && instance >= $maximum || instance > $maximum)) errors.push({
|
|
792
|
-
instanceLocation,
|
|
793
|
-
keyword: "maximum",
|
|
794
|
-
keywordLocation: `${schemaLocation}/maximum`,
|
|
795
|
-
error: `${instance} is greater than ${$exclusiveMaximum ? "or equal to " : ""} ${$maximum}.`
|
|
796
|
-
});
|
|
797
|
-
} else {
|
|
798
|
-
if ($minimum !== void 0 && instance < $minimum) errors.push({
|
|
799
|
-
instanceLocation,
|
|
800
|
-
keyword: "minimum",
|
|
801
|
-
keywordLocation: `${schemaLocation}/minimum`,
|
|
802
|
-
error: `${instance} is less than ${$minimum}.`
|
|
803
|
-
});
|
|
804
|
-
if ($maximum !== void 0 && instance > $maximum) errors.push({
|
|
805
|
-
instanceLocation,
|
|
806
|
-
keyword: "maximum",
|
|
807
|
-
keywordLocation: `${schemaLocation}/maximum`,
|
|
808
|
-
error: `${instance} is greater than ${$maximum}.`
|
|
809
|
-
});
|
|
810
|
-
if ($exclusiveMinimum !== void 0 && instance <= $exclusiveMinimum) errors.push({
|
|
811
|
-
instanceLocation,
|
|
812
|
-
keyword: "exclusiveMinimum",
|
|
813
|
-
keywordLocation: `${schemaLocation}/exclusiveMinimum`,
|
|
814
|
-
error: `${instance} is less than ${$exclusiveMinimum}.`
|
|
815
|
-
});
|
|
816
|
-
if ($exclusiveMaximum !== void 0 && instance >= $exclusiveMaximum) errors.push({
|
|
817
|
-
instanceLocation,
|
|
818
|
-
keyword: "exclusiveMaximum",
|
|
819
|
-
keywordLocation: `${schemaLocation}/exclusiveMaximum`,
|
|
820
|
-
error: `${instance} is greater than or equal to ${$exclusiveMaximum}.`
|
|
821
|
-
});
|
|
822
|
-
}
|
|
823
|
-
if ($multipleOf !== void 0) {
|
|
824
|
-
const remainder = instance % $multipleOf;
|
|
825
|
-
if (Math.abs(0 - remainder) >= 1.1920929e-7 && Math.abs($multipleOf - remainder) >= 1.1920929e-7) errors.push({
|
|
826
|
-
instanceLocation,
|
|
827
|
-
keyword: "multipleOf",
|
|
828
|
-
keywordLocation: `${schemaLocation}/multipleOf`,
|
|
829
|
-
error: `${instance} is not a multiple of ${$multipleOf}.`
|
|
830
|
-
});
|
|
831
|
-
}
|
|
832
|
-
} else if (instanceType === "string") {
|
|
833
|
-
const length = $minLength === void 0 && $maxLength === void 0 ? 0 : ucs2length(instance);
|
|
834
|
-
if ($minLength !== void 0 && length < $minLength) errors.push({
|
|
835
|
-
instanceLocation,
|
|
836
|
-
keyword: "minLength",
|
|
837
|
-
keywordLocation: `${schemaLocation}/minLength`,
|
|
838
|
-
error: `String is too short (${length} < ${$minLength}).`
|
|
839
|
-
});
|
|
840
|
-
if ($maxLength !== void 0 && length > $maxLength) errors.push({
|
|
841
|
-
instanceLocation,
|
|
842
|
-
keyword: "maxLength",
|
|
843
|
-
keywordLocation: `${schemaLocation}/maxLength`,
|
|
844
|
-
error: `String is too long (${length} > ${$maxLength}).`
|
|
845
|
-
});
|
|
846
|
-
if ($pattern !== void 0 && !new RegExp($pattern, "u").test(instance)) errors.push({
|
|
847
|
-
instanceLocation,
|
|
848
|
-
keyword: "pattern",
|
|
849
|
-
keywordLocation: `${schemaLocation}/pattern`,
|
|
850
|
-
error: `String does not match pattern.`
|
|
851
|
-
});
|
|
852
|
-
if ($format !== void 0 && format[$format] && !format[$format](instance)) errors.push({
|
|
853
|
-
instanceLocation,
|
|
854
|
-
keyword: "format",
|
|
855
|
-
keywordLocation: `${schemaLocation}/format`,
|
|
856
|
-
error: `String does not match format "${$format}".`
|
|
857
|
-
});
|
|
858
|
-
}
|
|
859
|
-
return {
|
|
860
|
-
valid: errors.length === 0,
|
|
861
|
-
errors
|
|
862
|
-
};
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
//#endregion
|
|
866
|
-
//#region node_modules/@cfworker/json-schema/dist/esm/validator.js
|
|
867
|
-
var Validator = class {
|
|
868
|
-
schema;
|
|
869
|
-
draft;
|
|
870
|
-
shortCircuit;
|
|
871
|
-
lookup;
|
|
872
|
-
constructor(schema, draft = "2019-09", shortCircuit = true) {
|
|
873
|
-
this.schema = schema;
|
|
874
|
-
this.draft = draft;
|
|
875
|
-
this.shortCircuit = shortCircuit;
|
|
876
|
-
this.lookup = dereference(schema);
|
|
877
|
-
}
|
|
878
|
-
validate(instance) {
|
|
879
|
-
return validate(instance, this.schema, this.draft, this.lookup, this.shortCircuit);
|
|
880
|
-
}
|
|
881
|
-
addSchema(schema, id) {
|
|
882
|
-
if (id) schema = {
|
|
883
|
-
...schema,
|
|
884
|
-
$id: id
|
|
885
|
-
};
|
|
886
|
-
dereference(schema, this.lookup);
|
|
887
|
-
}
|
|
888
|
-
};
|
|
889
|
-
|
|
890
|
-
//#endregion
|
|
891
|
-
//#region node_modules/@mcp-b/webmcp-polyfill/dist/index.js
|
|
892
|
-
const FAILED_TO_PARSE_INPUT_ARGUMENTS_MESSAGE = "Failed to parse input arguments";
|
|
893
|
-
const TOOL_INVOCATION_FAILED_MESSAGE = "Tool was executed but the invocation failed. For example, the script function threw an error";
|
|
894
|
-
const TOOL_CANCELLED_MESSAGE = "Tool was cancelled";
|
|
895
|
-
const DEFAULT_INPUT_SCHEMA = {
|
|
896
|
-
type: "object",
|
|
897
|
-
properties: {}
|
|
898
|
-
};
|
|
899
|
-
const STANDARD_JSON_SCHEMA_TARGETS = ["draft-2020-12", "draft-07"];
|
|
900
|
-
const POLYFILL_MARKER_PROPERTY = "__isWebMCPPolyfill";
|
|
901
|
-
const STANDARD_VALIDATOR_SYMBOL = Symbol("standardValidator");
|
|
902
|
-
const installState = {
|
|
903
|
-
installed: false,
|
|
904
|
-
previousNavigatorModelContextDescriptor: void 0,
|
|
905
|
-
previousNavigatorModelContextTestingDescriptor: void 0,
|
|
906
|
-
previousDocumentModelContextDescriptor: void 0,
|
|
907
|
-
installedNavigatorModelContext: false,
|
|
908
|
-
installedNavigatorModelContextTesting: false,
|
|
909
|
-
installedDocumentModelContext: false
|
|
910
|
-
};
|
|
911
|
-
var StrictWebMCPContext = class extends EventTarget {
|
|
912
|
-
tools = /* @__PURE__ */ new Map();
|
|
913
|
-
testingShim = null;
|
|
914
|
-
_ontoolchange = null;
|
|
915
|
-
unregisterToolDeprecationWarned = false;
|
|
916
|
-
get ontoolchange() {
|
|
917
|
-
return this._ontoolchange;
|
|
918
|
-
}
|
|
919
|
-
set ontoolchange(handler) {
|
|
920
|
-
this._ontoolchange = handler;
|
|
921
|
-
}
|
|
922
|
-
registerTool(tool, options) {
|
|
923
|
-
const signal = options?.signal;
|
|
924
|
-
if (signal?.aborted) {
|
|
925
|
-
console.warn(`[WebMCPPolyfill] registerTool("${tool?.name ?? "<unknown>"}") skipped: options.signal was already aborted.`);
|
|
926
|
-
return;
|
|
927
|
-
}
|
|
928
|
-
const normalized = normalizeToolDescriptor(tool, this.tools);
|
|
929
|
-
this.tools.set(normalized.name, normalized);
|
|
930
|
-
this.notifyToolsChanged();
|
|
931
|
-
if (signal) signal.addEventListener("abort", () => {
|
|
932
|
-
if (this.tools.delete(normalized.name)) this.notifyToolsChanged();
|
|
933
|
-
}, { once: true });
|
|
934
|
-
}
|
|
935
|
-
unregisterTool(nameOrTool) {
|
|
936
|
-
this.warnUnregisterToolDeprecationOnce();
|
|
937
|
-
const name = getToolNameForUnregister(nameOrTool);
|
|
938
|
-
if (this.tools.delete(name)) this.notifyToolsChanged();
|
|
939
|
-
}
|
|
940
|
-
getTools() {
|
|
941
|
-
return Promise.resolve(this.getRegisteredToolInfos());
|
|
942
|
-
}
|
|
943
|
-
executeTool(tool, inputArgsJson, options) {
|
|
944
|
-
return this.executeToolByName(tool.name, inputArgsJson, options, false);
|
|
945
|
-
}
|
|
946
|
-
getTestingShim() {
|
|
947
|
-
if (!this.testingShim) this.testingShim = new PolyfillTestingShim(this);
|
|
948
|
-
return this.testingShim;
|
|
949
|
-
}
|
|
950
|
-
/** @internal Used by PolyfillTestingShim */
|
|
951
|
-
getToolInfos() {
|
|
952
|
-
return [...this.tools.values()].map((tool) => {
|
|
953
|
-
let inputSchema;
|
|
954
|
-
try {
|
|
955
|
-
inputSchema = JSON.stringify(tool.inputSchema ?? { type: "object" });
|
|
956
|
-
} catch {
|
|
957
|
-
inputSchema = "{\"type\":\"object\"}";
|
|
958
|
-
}
|
|
959
|
-
return {
|
|
960
|
-
name: tool.name,
|
|
961
|
-
description: tool.description,
|
|
962
|
-
inputSchema
|
|
963
|
-
};
|
|
964
|
-
});
|
|
965
|
-
}
|
|
966
|
-
/** @internal Used by getTools() */
|
|
967
|
-
getRegisteredToolInfos() {
|
|
968
|
-
return this.getToolInfos().map((toolInfo) => {
|
|
969
|
-
const tool = this.tools.get(toolInfo.name);
|
|
970
|
-
return {
|
|
971
|
-
...toolInfo,
|
|
972
|
-
title: tool?.title ?? "",
|
|
973
|
-
origin: globalThis.location?.origin ?? "",
|
|
974
|
-
window: globalThis.window
|
|
975
|
-
};
|
|
976
|
-
});
|
|
977
|
-
}
|
|
978
|
-
/** @internal Used by PolyfillTestingShim */
|
|
979
|
-
async executeToolForTesting(toolName, inputArgsJson, options) {
|
|
980
|
-
return this.executeToolByName(toolName, inputArgsJson, options, true);
|
|
981
|
-
}
|
|
982
|
-
async executeToolByName(toolName, inputArgsJson, options, normalizeResult) {
|
|
983
|
-
if (options?.signal?.aborted) throw createUnknownError(TOOL_CANCELLED_MESSAGE);
|
|
984
|
-
const tool = this.tools.get(toolName);
|
|
985
|
-
if (!tool) throw createUnknownError(`Tool not found: ${toolName}`);
|
|
986
|
-
const args = parseInputArgsJson(inputArgsJson);
|
|
987
|
-
const validationError = await validateArgsForTool(args, tool);
|
|
988
|
-
if (validationError) throw createUnknownError(validationError);
|
|
989
|
-
let contextActive = true;
|
|
990
|
-
const client = { requestUserInteraction: async (callback) => {
|
|
991
|
-
if (!contextActive) throw new Error(`ModelContextClient for tool "${toolName}" is no longer active after execute() resolved`);
|
|
992
|
-
if (typeof callback !== "function") throw new TypeError("requestUserInteraction(callback) requires a function callback");
|
|
993
|
-
return callback();
|
|
994
|
-
} };
|
|
995
|
-
try {
|
|
996
|
-
const execution = tool.execute(args, client);
|
|
997
|
-
const rawResult = await withAbortSignal(Promise.resolve(execution), options?.signal);
|
|
998
|
-
if (normalizeResult) return toSerializedTestingResult(normalizeToolResponse(rawResult));
|
|
999
|
-
const serialized = JSON.stringify(rawResult);
|
|
1000
|
-
return serialized === void 0 ? null : serialized;
|
|
1001
|
-
} catch (error) {
|
|
1002
|
-
throw createUnknownError(error instanceof Error ? `${TOOL_INVOCATION_FAILED_MESSAGE}: ${error.message}` : TOOL_INVOCATION_FAILED_MESSAGE);
|
|
1003
|
-
} finally {
|
|
1004
|
-
contextActive = false;
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
notifyToolsChanged() {
|
|
1008
|
-
queueMicrotask(() => {
|
|
1009
|
-
const event = new Event("toolchange");
|
|
1010
|
-
try {
|
|
1011
|
-
this._ontoolchange?.call(this, event);
|
|
1012
|
-
} catch (error) {
|
|
1013
|
-
console.warn("[WebMCPPolyfill] navigator.modelContext.ontoolchange handler threw:", error);
|
|
1014
|
-
}
|
|
1015
|
-
this.dispatchEvent(event);
|
|
1016
|
-
this.testingShim?.dispatchToolChange();
|
|
1017
|
-
});
|
|
1018
|
-
}
|
|
1019
|
-
warnUnregisterToolDeprecationOnce() {
|
|
1020
|
-
if (this.unregisterToolDeprecationWarned) return;
|
|
1021
|
-
this.unregisterToolDeprecationWarned = true;
|
|
1022
|
-
console.warn("[WebMCPPolyfill] navigator.modelContext.unregisterTool() is deprecated. The April 23, 2026 WebMCP draft removed it in favor of registerTool(tool, { signal }) — pass an AbortSignal and abort it to unregister.");
|
|
1023
|
-
}
|
|
1024
|
-
};
|
|
1025
|
-
/**
|
|
1026
|
-
* EventTarget-based testing shim matching the native Chromium ModelContextTesting surface.
|
|
1027
|
-
*
|
|
1028
|
-
* Fires `toolchange` events and supports the `ontoolchange` handler property,
|
|
1029
|
-
* matching the native Chromium 148 API. The deprecated `registerToolsChangedCallback`
|
|
1030
|
-
* is kept as a compat layer that wraps `addEventListener`.
|
|
1031
|
-
*/
|
|
1032
|
-
var PolyfillTestingShim = class extends EventTarget {
|
|
1033
|
-
context;
|
|
1034
|
-
_ontoolchange = null;
|
|
1035
|
-
constructor(context) {
|
|
1036
|
-
super();
|
|
1037
|
-
this.context = context;
|
|
1038
|
-
}
|
|
1039
|
-
listTools() {
|
|
1040
|
-
return this.context.getToolInfos();
|
|
1041
|
-
}
|
|
1042
|
-
executeTool(toolName, inputArgsJson, options) {
|
|
1043
|
-
return this.context.executeToolForTesting(toolName, inputArgsJson, options);
|
|
1044
|
-
}
|
|
1045
|
-
getCrossDocumentScriptToolResult() {
|
|
1046
|
-
return Promise.resolve("[]");
|
|
1047
|
-
}
|
|
1048
|
-
get ontoolchange() {
|
|
1049
|
-
return this._ontoolchange;
|
|
1050
|
-
}
|
|
1051
|
-
set ontoolchange(handler) {
|
|
1052
|
-
this._ontoolchange = handler;
|
|
1053
|
-
}
|
|
1054
|
-
/**
|
|
1055
|
-
* @deprecated Use `addEventListener('toolchange', callback)` instead.
|
|
1056
|
-
* Kept for backward compatibility with older polyfill consumers.
|
|
1057
|
-
*/
|
|
1058
|
-
registerToolsChangedCallback(callback) {
|
|
1059
|
-
if (typeof callback !== "function") throw new TypeError("Failed to execute 'registerToolsChangedCallback' on 'ModelContextTesting': parameter 1 is not of type 'Function'.");
|
|
1060
|
-
this.addEventListener("toolchange", callback);
|
|
1061
|
-
}
|
|
1062
|
-
/** @internal Called by StrictWebMCPContext when tools change. */
|
|
1063
|
-
dispatchToolChange() {
|
|
1064
|
-
const event = new Event("toolchange");
|
|
1065
|
-
try {
|
|
1066
|
-
this._ontoolchange?.call(this, event);
|
|
1067
|
-
} catch (error) {
|
|
1068
|
-
console.warn("[WebMCPPolyfill] ontoolchange handler threw:", error);
|
|
1069
|
-
}
|
|
1070
|
-
this.dispatchEvent(event);
|
|
1071
|
-
this.dispatchEvent(new Event("toolschanged"));
|
|
1072
|
-
}
|
|
1073
|
-
};
|
|
1074
|
-
function createUnknownError(message) {
|
|
1075
|
-
try {
|
|
1076
|
-
return new DOMException(message, "UnknownError");
|
|
1077
|
-
} catch {
|
|
1078
|
-
const error = new Error(message);
|
|
1079
|
-
error.name = "UnknownError";
|
|
1080
|
-
return error;
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
function parseInputArgsJson(inputArgsJson) {
|
|
1084
|
-
let parsed;
|
|
1085
|
-
try {
|
|
1086
|
-
parsed = JSON.parse(inputArgsJson);
|
|
1087
|
-
} catch {
|
|
1088
|
-
throw createUnknownError(FAILED_TO_PARSE_INPUT_ARGUMENTS_MESSAGE);
|
|
1089
|
-
}
|
|
1090
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw createUnknownError(FAILED_TO_PARSE_INPUT_ARGUMENTS_MESSAGE);
|
|
1091
|
-
return parsed;
|
|
1092
|
-
}
|
|
1093
|
-
function getToolNameForUnregister(nameOrTool) {
|
|
1094
|
-
if (typeof nameOrTool === "string") return nameOrTool;
|
|
1095
|
-
if (isPlainObject(nameOrTool) && typeof nameOrTool.name === "string") return nameOrTool.name;
|
|
1096
|
-
throw new TypeError("Failed to execute 'unregisterTool' on 'ModelContext': parameter 1 must be a string or an object with a string name.");
|
|
1097
|
-
}
|
|
1098
|
-
function isPlainObject(value) {
|
|
1099
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1100
|
-
}
|
|
1101
|
-
function getStandardProps(value) {
|
|
1102
|
-
if (!isPlainObject(value)) return null;
|
|
1103
|
-
const standard = value["~standard"];
|
|
1104
|
-
if (!isPlainObject(standard)) return null;
|
|
1105
|
-
return standard;
|
|
1106
|
-
}
|
|
1107
|
-
function isStandardInputValidatorSchema(value) {
|
|
1108
|
-
const standard = getStandardProps(value);
|
|
1109
|
-
return Boolean(standard && standard.version === 1 && typeof standard.validate === "function");
|
|
1110
|
-
}
|
|
1111
|
-
function isStandardInputJsonSchema(value) {
|
|
1112
|
-
const standard = getStandardProps(value);
|
|
1113
|
-
if (!standard || standard.version !== 1 || !isPlainObject(standard.jsonSchema)) return false;
|
|
1114
|
-
return typeof standard.jsonSchema.input === "function";
|
|
1115
|
-
}
|
|
1116
|
-
function createStandardValidatorFromJsonSchema(schema) {
|
|
1117
|
-
return { "~standard": {
|
|
1118
|
-
version: 1,
|
|
1119
|
-
vendor: "@mcp-b/webmcp-polyfill-json-schema",
|
|
1120
|
-
validate(value) {
|
|
1121
|
-
if (!isPlainObject(value)) return { issues: [{ message: "expected object arguments" }] };
|
|
1122
|
-
const issue = validateArgsWithSchema(value, schema);
|
|
1123
|
-
if (issue) return { issues: [issue] };
|
|
1124
|
-
return { value };
|
|
1125
|
-
}
|
|
1126
|
-
} };
|
|
1127
|
-
}
|
|
1128
|
-
function convertStandardInputSchema(schema) {
|
|
1129
|
-
for (const target of STANDARD_JSON_SCHEMA_TARGETS) try {
|
|
1130
|
-
const converted = schema["~standard"].jsonSchema.input({ target });
|
|
1131
|
-
validateInputSchema(converted);
|
|
1132
|
-
return converted;
|
|
1133
|
-
} catch (error) {
|
|
1134
|
-
console.warn(`[WebMCPPolyfill] Standard JSON Schema conversion failed for target "${target}":`, error);
|
|
1135
|
-
}
|
|
1136
|
-
throw new Error("Failed to convert Standard JSON Schema inputSchema to a JSON Schema object");
|
|
1137
|
-
}
|
|
1138
|
-
function normalizeInputSchema(inputSchema) {
|
|
1139
|
-
if (inputSchema === void 0) {
|
|
1140
|
-
const normalized = DEFAULT_INPUT_SCHEMA;
|
|
1141
|
-
return {
|
|
1142
|
-
inputSchema: normalized,
|
|
1143
|
-
standardValidator: createStandardValidatorFromJsonSchema(normalized)
|
|
1144
|
-
};
|
|
1145
|
-
}
|
|
1146
|
-
if (isStandardInputJsonSchema(inputSchema)) {
|
|
1147
|
-
const converted = convertStandardInputSchema(inputSchema);
|
|
1148
|
-
return {
|
|
1149
|
-
inputSchema: converted,
|
|
1150
|
-
standardValidator: createStandardValidatorFromJsonSchema(converted)
|
|
1151
|
-
};
|
|
1152
|
-
}
|
|
1153
|
-
if (isStandardInputValidatorSchema(inputSchema)) return {
|
|
1154
|
-
inputSchema: DEFAULT_INPUT_SCHEMA,
|
|
1155
|
-
standardValidator: inputSchema
|
|
1156
|
-
};
|
|
1157
|
-
validateInputSchema(inputSchema);
|
|
1158
|
-
if (Object.keys(inputSchema).length === 0) return {
|
|
1159
|
-
inputSchema: DEFAULT_INPUT_SCHEMA,
|
|
1160
|
-
standardValidator: createStandardValidatorFromJsonSchema(DEFAULT_INPUT_SCHEMA)
|
|
1161
|
-
};
|
|
1162
|
-
const normalizedSchema = inputSchema.type === void 0 ? {
|
|
1163
|
-
type: "object",
|
|
1164
|
-
...inputSchema
|
|
1165
|
-
} : inputSchema;
|
|
1166
|
-
return {
|
|
1167
|
-
inputSchema: normalizedSchema,
|
|
1168
|
-
standardValidator: createStandardValidatorFromJsonSchema(normalizedSchema)
|
|
1169
|
-
};
|
|
1170
|
-
}
|
|
1171
|
-
function validateInputSchema(schema) {
|
|
1172
|
-
if (!isPlainObject(schema)) throw new Error("inputSchema must be a JSON Schema object");
|
|
1173
|
-
validateJsonSchemaNode(schema, "$");
|
|
1174
|
-
}
|
|
1175
|
-
function validateJsonSchemaNode(node, path) {
|
|
1176
|
-
const typeValue = node.type;
|
|
1177
|
-
if (typeValue !== void 0 && typeof typeValue !== "string" && !(Array.isArray(typeValue) && typeValue.every((entry) => typeof entry === "string" && entry.length > 0))) throw new Error(`Invalid JSON Schema at ${path}: "type" must be a string or string[]`);
|
|
1178
|
-
const requiredValue = node.required;
|
|
1179
|
-
if (requiredValue !== void 0 && !(Array.isArray(requiredValue) && requiredValue.every((entry) => typeof entry === "string"))) throw new Error(`Invalid JSON Schema at ${path}: "required" must be an array of strings`);
|
|
1180
|
-
const propertiesValue = node.properties;
|
|
1181
|
-
if (propertiesValue !== void 0) {
|
|
1182
|
-
if (!isPlainObject(propertiesValue)) throw new Error(`Invalid JSON Schema at ${path}: "properties" must be an object`);
|
|
1183
|
-
for (const [key, value] of Object.entries(propertiesValue)) {
|
|
1184
|
-
if (!isPlainObject(value)) throw new Error(`Invalid JSON Schema at ${path}.properties.${key}: expected object schema`);
|
|
1185
|
-
validateJsonSchemaNode(value, `${path}.properties.${key}`);
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
const itemsValue = node.items;
|
|
1189
|
-
if (itemsValue !== void 0) if (Array.isArray(itemsValue)) for (const [index, value] of itemsValue.entries()) {
|
|
1190
|
-
if (!isPlainObject(value)) throw new Error(`Invalid JSON Schema at ${path}.items[${index}]: expected object schema`);
|
|
1191
|
-
validateJsonSchemaNode(value, `${path}.items[${index}]`);
|
|
1192
|
-
}
|
|
1193
|
-
else if (isPlainObject(itemsValue)) validateJsonSchemaNode(itemsValue, `${path}.items`);
|
|
1194
|
-
else throw new Error(`Invalid JSON Schema at ${path}: "items" must be an object or object[]`);
|
|
1195
|
-
for (const keyword of [
|
|
1196
|
-
"allOf",
|
|
1197
|
-
"anyOf",
|
|
1198
|
-
"oneOf"
|
|
1199
|
-
]) {
|
|
1200
|
-
const value = node[keyword];
|
|
1201
|
-
if (value === void 0) continue;
|
|
1202
|
-
if (!Array.isArray(value)) throw new Error(`Invalid JSON Schema at ${path}: "${keyword}" must be an array`);
|
|
1203
|
-
for (const [index, entry] of value.entries()) {
|
|
1204
|
-
if (!isPlainObject(entry)) throw new Error(`Invalid JSON Schema at ${path}.${keyword}[${index}]: expected object schema`);
|
|
1205
|
-
validateJsonSchemaNode(entry, `${path}.${keyword}[${index}]`);
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1208
|
-
const notValue = node.not;
|
|
1209
|
-
if (notValue !== void 0) {
|
|
1210
|
-
if (!isPlainObject(notValue)) throw new Error(`Invalid JSON Schema at ${path}: "not" must be an object schema`);
|
|
1211
|
-
validateJsonSchemaNode(notValue, `${path}.not`);
|
|
1212
|
-
}
|
|
1213
|
-
try {
|
|
1214
|
-
JSON.stringify(node);
|
|
1215
|
-
} catch {
|
|
1216
|
-
throw new Error(`Invalid JSON Schema at ${path}: schema must be JSON-serializable`);
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
function normalizeToolDescriptor(tool, existing) {
|
|
1220
|
-
if (!tool || typeof tool !== "object") throw new TypeError("registerTool(tool) requires a tool object");
|
|
1221
|
-
if (typeof tool.name !== "string" || tool.name.length === 0) throw new TypeError("Tool \"name\" must be a non-empty string");
|
|
1222
|
-
if (typeof tool.description !== "string" || tool.description.length === 0) throw new TypeError("Tool \"description\" must be a non-empty string");
|
|
1223
|
-
if (typeof tool.execute !== "function") throw new TypeError("Tool \"execute\" must be a function");
|
|
1224
|
-
if (existing.has(tool.name)) throw new Error(`Tool already registered: ${tool.name}`);
|
|
1225
|
-
const normalizedInputSchema = normalizeInputSchema(tool.inputSchema);
|
|
1226
|
-
const annotations = tool.annotations;
|
|
1227
|
-
const normalizedAnnotations = annotations ? {
|
|
1228
|
-
...annotations,
|
|
1229
|
-
...annotations.readOnlyHint === "true" ? { readOnlyHint: true } : annotations.readOnlyHint === "false" ? { readOnlyHint: false } : {},
|
|
1230
|
-
...annotations.destructiveHint === "true" ? { destructiveHint: true } : annotations.destructiveHint === "false" ? { destructiveHint: false } : {},
|
|
1231
|
-
...annotations.idempotentHint === "true" ? { idempotentHint: true } : annotations.idempotentHint === "false" ? { idempotentHint: false } : {},
|
|
1232
|
-
...annotations.openWorldHint === "true" ? { openWorldHint: true } : annotations.openWorldHint === "false" ? { openWorldHint: false } : {}
|
|
1233
|
-
} : void 0;
|
|
1234
|
-
return {
|
|
1235
|
-
...tool,
|
|
1236
|
-
...normalizedAnnotations ? { annotations: normalizedAnnotations } : {},
|
|
1237
|
-
inputSchema: normalizedInputSchema.inputSchema,
|
|
1238
|
-
[STANDARD_VALIDATOR_SYMBOL]: normalizedInputSchema.standardValidator
|
|
1239
|
-
};
|
|
1240
|
-
}
|
|
1241
|
-
function validateArgsWithSchema(args, schema) {
|
|
1242
|
-
const result = new Validator(schema, "2020-12", true).validate(args);
|
|
1243
|
-
if (result.valid) return null;
|
|
1244
|
-
const error = result.errors[result.errors.length - 1];
|
|
1245
|
-
if (!error) return { message: "Input validation failed" };
|
|
1246
|
-
return { message: error.error };
|
|
1247
|
-
}
|
|
1248
|
-
function formatStandardIssuePath(path) {
|
|
1249
|
-
if (!path || path.length === 0) return null;
|
|
1250
|
-
const segments = path.map((segment) => {
|
|
1251
|
-
if (isPlainObject(segment) && "key" in segment) return segment.key;
|
|
1252
|
-
return segment;
|
|
1253
|
-
}).map((segment) => String(segment)).filter((segment) => segment.length > 0);
|
|
1254
|
-
if (segments.length === 0) return null;
|
|
1255
|
-
return segments.join(".");
|
|
1256
|
-
}
|
|
1257
|
-
async function validateArgsWithStandardSchema(args, schema) {
|
|
1258
|
-
let result;
|
|
1259
|
-
try {
|
|
1260
|
-
result = await Promise.resolve(schema["~standard"].validate(args));
|
|
1261
|
-
} catch (error) {
|
|
1262
|
-
const detail = error instanceof Error ? `: ${error.message}` : "";
|
|
1263
|
-
console.error("[WebMCPPolyfill] Standard Schema validation threw unexpectedly:", error);
|
|
1264
|
-
return `Input validation error: schema validation failed${detail}`;
|
|
1265
|
-
}
|
|
1266
|
-
if (!result.issues || result.issues.length === 0) return null;
|
|
1267
|
-
const firstIssue = result.issues[0];
|
|
1268
|
-
if (!firstIssue) return "Input validation error";
|
|
1269
|
-
const path = formatStandardIssuePath(firstIssue?.path);
|
|
1270
|
-
if (path) return `Input validation error: ${firstIssue.message} at ${path}`;
|
|
1271
|
-
return `Input validation error: ${firstIssue.message}`;
|
|
1272
|
-
}
|
|
1273
|
-
async function validateArgsForTool(args, tool) {
|
|
1274
|
-
return validateArgsWithStandardSchema(args, tool[STANDARD_VALIDATOR_SYMBOL]);
|
|
1275
|
-
}
|
|
1276
|
-
function isCallToolResult(value) {
|
|
1277
|
-
return isPlainObject(value) && Array.isArray(value.content);
|
|
1278
|
-
}
|
|
1279
|
-
function isJsonPrimitive(value) {
|
|
1280
|
-
return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
1281
|
-
}
|
|
1282
|
-
function isJsonValue(value) {
|
|
1283
|
-
if (isJsonPrimitive(value)) return Number.isFinite(value) || typeof value !== "number";
|
|
1284
|
-
if (Array.isArray(value)) return value.every((entry) => isJsonValue(entry));
|
|
1285
|
-
if (!isPlainObject(value)) return false;
|
|
1286
|
-
return Object.values(value).every((entry) => isJsonValue(entry));
|
|
1287
|
-
}
|
|
1288
|
-
function toStructuredContent(value) {
|
|
1289
|
-
if (!isPlainObject(value) || !isJsonValue(value)) return;
|
|
1290
|
-
return value;
|
|
1291
|
-
}
|
|
1292
|
-
function serializeTextContent(value) {
|
|
1293
|
-
if (typeof value === "string") return value;
|
|
1294
|
-
try {
|
|
1295
|
-
return JSON.stringify(value) ?? String(value);
|
|
1296
|
-
} catch {
|
|
1297
|
-
return String(value);
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
function normalizeToolResponse(value) {
|
|
1301
|
-
if (isCallToolResult(value)) return value;
|
|
1302
|
-
const structuredContent = toStructuredContent(value);
|
|
1303
|
-
return {
|
|
1304
|
-
content: [{
|
|
1305
|
-
type: "text",
|
|
1306
|
-
text: serializeTextContent(value)
|
|
1307
|
-
}],
|
|
1308
|
-
...structuredContent ? { structuredContent } : {},
|
|
1309
|
-
isError: false
|
|
1310
|
-
};
|
|
1311
|
-
}
|
|
1312
|
-
function getFirstTextBlock(result) {
|
|
1313
|
-
for (const block of result.content ?? []) if (block.type === "text" && "text" in block && typeof block.text === "string") return block.text;
|
|
1314
|
-
return null;
|
|
1315
|
-
}
|
|
1316
|
-
function toSerializedTestingResult(result) {
|
|
1317
|
-
if (result.isError) throw createUnknownError(getFirstTextBlock(result)?.replace(/^Error:\s*/i, "").trim() || TOOL_INVOCATION_FAILED_MESSAGE);
|
|
1318
|
-
const metadata = result.metadata;
|
|
1319
|
-
if (metadata && typeof metadata === "object" && metadata.willNavigate) return null;
|
|
1320
|
-
try {
|
|
1321
|
-
return JSON.stringify(result);
|
|
1322
|
-
} catch {
|
|
1323
|
-
throw createUnknownError(TOOL_INVOCATION_FAILED_MESSAGE);
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
function withAbortSignal(operation, signal) {
|
|
1327
|
-
if (!signal) return operation;
|
|
1328
|
-
if (signal.aborted) return Promise.reject(createUnknownError(TOOL_CANCELLED_MESSAGE));
|
|
1329
|
-
return new Promise((resolve, reject) => {
|
|
1330
|
-
const onAbort = () => {
|
|
1331
|
-
cleanup();
|
|
1332
|
-
reject(createUnknownError(TOOL_CANCELLED_MESSAGE));
|
|
1333
|
-
};
|
|
1334
|
-
const cleanup = () => {
|
|
1335
|
-
signal.removeEventListener("abort", onAbort);
|
|
1336
|
-
};
|
|
1337
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
1338
|
-
operation.then((value) => {
|
|
1339
|
-
cleanup();
|
|
1340
|
-
resolve(value);
|
|
1341
|
-
}, (error) => {
|
|
1342
|
-
cleanup();
|
|
1343
|
-
reject(error);
|
|
1344
|
-
});
|
|
1345
|
-
});
|
|
1346
|
-
}
|
|
1347
|
-
function getNavigator() {
|
|
1348
|
-
if (typeof navigator !== "undefined") return navigator;
|
|
1349
|
-
return null;
|
|
1350
|
-
}
|
|
1351
|
-
function getDocument() {
|
|
1352
|
-
if (typeof document !== "undefined") return document;
|
|
1353
|
-
return null;
|
|
1354
|
-
}
|
|
1355
|
-
function defineNavigatorProperty(target, key, value) {
|
|
1356
|
-
Object.defineProperty(target, key, {
|
|
1357
|
-
configurable: true,
|
|
1358
|
-
enumerable: true,
|
|
1359
|
-
writable: false,
|
|
1360
|
-
value
|
|
1361
|
-
});
|
|
1362
|
-
}
|
|
1363
|
-
function defineDocumentModelContextProperty(target, value) {
|
|
1364
|
-
Object.defineProperty(target, "modelContext", {
|
|
1365
|
-
configurable: true,
|
|
1366
|
-
enumerable: true,
|
|
1367
|
-
writable: false,
|
|
1368
|
-
value
|
|
1369
|
-
});
|
|
1370
|
-
}
|
|
1371
|
-
let navigatorModelContextDeprecationWarned = false;
|
|
1372
|
-
function defineDeprecatedNavigatorModelContext(target, value) {
|
|
1373
|
-
Object.defineProperty(target, "modelContext", {
|
|
1374
|
-
configurable: true,
|
|
1375
|
-
enumerable: true,
|
|
1376
|
-
get() {
|
|
1377
|
-
if (!navigatorModelContextDeprecationWarned) {
|
|
1378
|
-
navigatorModelContextDeprecationWarned = true;
|
|
1379
|
-
console.warn("[WebMCPPolyfill] navigator.modelContext is deprecated. The May 27, 2026 WebMCP draft moved the modelContext getter from Navigator to Document — use document.modelContext instead. See https://github.com/webmachinelearning/webmcp/pull/184.");
|
|
1380
|
-
}
|
|
1381
|
-
return value;
|
|
1382
|
-
}
|
|
1383
|
-
});
|
|
1384
|
-
}
|
|
1385
|
-
function initializeWebMCPPolyfill(options) {
|
|
1386
|
-
const nav = getNavigator();
|
|
1387
|
-
const doc = getDocument();
|
|
1388
|
-
if (!nav && !doc) return;
|
|
1389
|
-
const documentModelContext = doc?.modelContext;
|
|
1390
|
-
if (Boolean(documentModelContext)) return;
|
|
1391
|
-
const navigatorModelContext = nav?.modelContext;
|
|
1392
|
-
const hasNavigatorModelContext = Boolean(navigatorModelContext);
|
|
1393
|
-
if (installState.installed) cleanupWebMCPPolyfill();
|
|
1394
|
-
if (doc && navigatorModelContext) {
|
|
1395
|
-
installState.previousDocumentModelContextDescriptor = Object.getOwnPropertyDescriptor(doc, "modelContext");
|
|
1396
|
-
defineDocumentModelContextProperty(doc, navigatorModelContext);
|
|
1397
|
-
installState.installedDocumentModelContext = true;
|
|
1398
|
-
installState.installed = true;
|
|
1399
|
-
return;
|
|
1400
|
-
}
|
|
1401
|
-
if (hasNavigatorModelContext) return;
|
|
1402
|
-
const context = new StrictWebMCPContext();
|
|
1403
|
-
const modelContext = context;
|
|
1404
|
-
modelContext[POLYFILL_MARKER_PROPERTY] = true;
|
|
1405
|
-
if (doc) {
|
|
1406
|
-
installState.previousDocumentModelContextDescriptor = Object.getOwnPropertyDescriptor(doc, "modelContext");
|
|
1407
|
-
defineDocumentModelContextProperty(doc, modelContext);
|
|
1408
|
-
installState.installedDocumentModelContext = true;
|
|
1409
|
-
}
|
|
1410
|
-
if (nav) {
|
|
1411
|
-
installState.previousNavigatorModelContextDescriptor = Object.getOwnPropertyDescriptor(nav, "modelContext");
|
|
1412
|
-
installState.previousNavigatorModelContextTestingDescriptor = Object.getOwnPropertyDescriptor(nav, "modelContextTesting");
|
|
1413
|
-
navigatorModelContextDeprecationWarned = false;
|
|
1414
|
-
defineDeprecatedNavigatorModelContext(nav, modelContext);
|
|
1415
|
-
installState.installedNavigatorModelContext = true;
|
|
1416
|
-
const installTestingShim = options?.installTestingShim ?? "if-missing";
|
|
1417
|
-
const hasModelContextTesting = Boolean(nav.modelContextTesting);
|
|
1418
|
-
if (installTestingShim === "always" || (installTestingShim === true || installTestingShim === "if-missing") && !hasModelContextTesting) {
|
|
1419
|
-
defineNavigatorProperty(nav, "modelContextTesting", context.getTestingShim());
|
|
1420
|
-
installState.installedNavigatorModelContextTesting = true;
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
installState.installed = true;
|
|
1424
|
-
}
|
|
1425
|
-
function cleanupWebMCPPolyfill() {
|
|
1426
|
-
if (!installState.installed) return;
|
|
1427
|
-
const restore = (target, key, previousDescriptor) => {
|
|
1428
|
-
if (previousDescriptor) {
|
|
1429
|
-
Object.defineProperty(target, key, previousDescriptor);
|
|
1430
|
-
return;
|
|
1431
|
-
}
|
|
1432
|
-
delete target[key];
|
|
1433
|
-
};
|
|
1434
|
-
const nav = getNavigator();
|
|
1435
|
-
const doc = getDocument();
|
|
1436
|
-
if (doc && installState.installedDocumentModelContext) restore(doc, "modelContext", installState.previousDocumentModelContextDescriptor);
|
|
1437
|
-
if (nav && installState.installedNavigatorModelContext) restore(nav, "modelContext", installState.previousNavigatorModelContextDescriptor);
|
|
1438
|
-
if (nav && installState.installedNavigatorModelContextTesting) restore(nav, "modelContextTesting", installState.previousNavigatorModelContextTestingDescriptor);
|
|
1439
|
-
installState.installed = false;
|
|
1440
|
-
installState.previousDocumentModelContextDescriptor = void 0;
|
|
1441
|
-
installState.previousNavigatorModelContextDescriptor = void 0;
|
|
1442
|
-
installState.previousNavigatorModelContextTestingDescriptor = void 0;
|
|
1443
|
-
installState.installedDocumentModelContext = false;
|
|
1444
|
-
installState.installedNavigatorModelContext = false;
|
|
1445
|
-
installState.installedNavigatorModelContextTesting = false;
|
|
1446
|
-
navigatorModelContextDeprecationWarned = false;
|
|
1447
|
-
}
|
|
1448
|
-
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
1449
|
-
const options = window.__webMCPPolyfillOptions;
|
|
1450
|
-
if (options?.autoInitialize !== false) try {
|
|
1451
|
-
initializeWebMCPPolyfill(options);
|
|
1452
|
-
} catch (error) {
|
|
1453
|
-
console.error("[WebMCPPolyfill] Auto-initialization failed:", error);
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
|
|
1457
|
-
//#endregion
|
|
1458
|
-
//#region src/subsystems/mcp/webmcp.ts
|
|
1459
|
-
var webmcp_exports = /* @__PURE__ */ __exportAll({
|
|
1460
|
-
extractAbortSignal: () => extractAbortSignal,
|
|
1461
|
-
getWebMcpMode: () => getWebMcpMode,
|
|
1462
|
-
getWebMcpTools: () => getWebMcpTools,
|
|
1463
|
-
parseWebMcpInputSchema: () => parseWebMcpInputSchema,
|
|
1464
|
-
registerWebMcpTools: () => registerWebMcpTools,
|
|
1465
|
-
setWebMcpMode: () => setWebMcpMode,
|
|
1466
|
-
unregisterWebMcpTools: () => unregisterWebMcpTools
|
|
1467
|
-
});
|
|
1468
|
-
const registeredToolControllers = /* @__PURE__ */ new Map();
|
|
1469
|
-
const registeredToolNames = /* @__PURE__ */ new Set();
|
|
1470
|
-
let currentMode = "polyfill";
|
|
1471
|
-
/**
|
|
1472
|
-
* Set the WebMCP mode (polyfill vs native).
|
|
1473
|
-
*
|
|
1474
|
-
* - `"polyfill"` (default): Uses `@mcp-b/webmcp-polyfill` for a pure-JS
|
|
1475
|
-
* `document.modelContext` that works in all browsers.
|
|
1476
|
-
* - `"native"`: Uses Chrome's native `document.modelContext` from
|
|
1477
|
-
* `chrome://flags/#enable-webmcp-testing`. Requires the flag to be
|
|
1478
|
-
* enabled. May crash in early Canary builds.
|
|
1479
|
-
*
|
|
1480
|
-
* Detection follows Chrome's recommended compat pattern:
|
|
1481
|
-
* `document.modelContext || navigator.modelContext`
|
|
1482
|
-
* `navigator.modelContext` was deprecated in Chrome 150 and removed in
|
|
1483
|
-
* Chrome 152.0.7943.0, but the fallback keeps older clients working.
|
|
1484
|
-
*/
|
|
1485
|
-
function setWebMcpMode(mode) {
|
|
1486
|
-
currentMode = mode;
|
|
1487
|
-
}
|
|
1488
|
-
function getWebMcpMode() {
|
|
1489
|
-
return currentMode;
|
|
1490
|
-
}
|
|
1491
|
-
/**
|
|
1492
|
-
* Install the `@mcp-b/webmcp-polyfill` onto `document.modelContext`.
|
|
1493
|
-
*
|
|
1494
|
-
* The polyfill itself bails out when Chrome's native `document.modelContext`
|
|
1495
|
-
* is already present — it does NOT override the native API. We call it
|
|
1496
|
-
* unconditionally; if the polyfill is already installed it will detect the
|
|
1497
|
-
* existing install via its own `installState` guard and return quickly.
|
|
1498
|
-
*/
|
|
1499
|
-
function ensurePolyfill() {
|
|
1500
|
-
try {
|
|
1501
|
-
initializeWebMCPPolyfill();
|
|
1502
|
-
} catch (err) {
|
|
1503
|
-
console.warn("WebMCP polyfill initialization failed:", err);
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
/**
|
|
1507
|
-
* Access the WebMCP ModelContext API.
|
|
1508
|
-
*
|
|
1509
|
-
* In polyfill mode: installs the `@mcp-b/webmcp-polyfill` which surfaces
|
|
1510
|
-
* `document.modelContext`.
|
|
1511
|
-
* In native mode: follows Chrome's recommended feature-detection pattern:
|
|
1512
|
-
* `document.modelContext || navigator.modelContext`
|
|
1513
|
-
* `navigator.modelContext` was deprecated in Chrome 150 and removed in
|
|
1514
|
-
* Chrome 152.0.7943.0, but the fallback preserves compatibility with
|
|
1515
|
-
* earlier builds that may still be in the wild.
|
|
1516
|
-
*/
|
|
1517
|
-
function getModelContextApi() {
|
|
1518
|
-
if (typeof document === "undefined" && typeof navigator === "undefined") return null;
|
|
1519
|
-
if (currentMode === "polyfill") ensurePolyfill();
|
|
1520
|
-
try {
|
|
1521
|
-
const modelContext = typeof document !== "undefined" && typeof document.modelContext !== "undefined" ? Reflect.get(document, "modelContext") : typeof navigator !== "undefined" && typeof navigator.modelContext !== "undefined" ? Reflect.get(navigator, "modelContext") : void 0;
|
|
1522
|
-
if (!modelContext || typeof modelContext !== "object") return null;
|
|
1523
|
-
const api = modelContext;
|
|
1524
|
-
if (typeof api.registerTool !== "function") return null;
|
|
1525
|
-
return api;
|
|
1526
|
-
} catch (err) {
|
|
1527
|
-
console.warn("WebMCP modelContext access failed:", err);
|
|
1528
|
-
return null;
|
|
1529
|
-
}
|
|
1530
|
-
}
|
|
1531
|
-
/**
|
|
1532
|
-
* Safely parse or normalize WebMCP input schema.
|
|
1533
|
-
*
|
|
1534
|
-
* Starting in Chrome 154.0.8014.0 (PR #241), `RegisteredTool#inputSchema` returns
|
|
1535
|
-
* a JavaScript object (a deep copy of the schema provided at registration).
|
|
1536
|
-
* In Chrome < 154.0.8014.0, `RegisteredTool#inputSchema` returned a stringified JSON schema (DOMString).
|
|
1537
|
-
*
|
|
1538
|
-
* This function provides backwards-compatible schema parsing:
|
|
1539
|
-
* - If inputSchema is a string: attempts JSON.parse.
|
|
1540
|
-
* - If inputSchema is an object: returns the object.
|
|
1541
|
-
* - Fallbacks gracefully to an empty object schema if null, undefined, or invalid JSON.
|
|
1542
|
-
*/
|
|
1543
|
-
function parseWebMcpInputSchema(inputSchema) {
|
|
1544
|
-
if (typeof inputSchema === "string") {
|
|
1545
|
-
try {
|
|
1546
|
-
const parsed = JSON.parse(inputSchema);
|
|
1547
|
-
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
|
|
1548
|
-
} catch {}
|
|
1549
|
-
return {
|
|
1550
|
-
type: "object",
|
|
1551
|
-
properties: {}
|
|
1552
|
-
};
|
|
1553
|
-
}
|
|
1554
|
-
if (inputSchema && typeof inputSchema === "object" && !Array.isArray(inputSchema)) return inputSchema;
|
|
1555
|
-
return {
|
|
1556
|
-
type: "object",
|
|
1557
|
-
properties: {}
|
|
1558
|
-
};
|
|
1559
|
-
}
|
|
1560
|
-
/**
|
|
1561
|
-
* Safely extract AbortSignal from execute options/context.
|
|
1562
|
-
* Supports Chrome 153+ options object `{ signal }` (PR #247), direct AbortSignal instances,
|
|
1563
|
-
* or undefined for backward compatibility with Chrome < 153 and legacy callers.
|
|
1564
|
-
*/
|
|
1565
|
-
function extractAbortSignal(context) {
|
|
1566
|
-
if (!context) return;
|
|
1567
|
-
if (typeof AbortSignal !== "undefined" && context instanceof AbortSignal) return context;
|
|
1568
|
-
if (typeof context === "object" && "signal" in context && typeof AbortSignal !== "undefined" && context.signal instanceof AbortSignal) return context.signal;
|
|
1569
|
-
}
|
|
1570
|
-
/**
|
|
1571
|
-
* Retrieve tools registered on the WebMCP ModelContext API.
|
|
1572
|
-
*
|
|
1573
|
-
* Practicing graceful degradation:
|
|
1574
|
-
* - Feature-detects `getTools()` on `document.modelContext` / `navigator.modelContext`.
|
|
1575
|
-
* - If `getTools()` is absent (older browser builds or polyfills without getTools),
|
|
1576
|
-
* returns an empty array `[]` without throwing.
|
|
1577
|
-
* - Normalizes `RegisteredTool#inputSchema` so caller receives a JavaScript object
|
|
1578
|
-
* whether running on Chrome 154+ (native object) or Chrome < 154 (DOMString JSON).
|
|
1579
|
-
*/
|
|
1580
|
-
async function getWebMcpTools() {
|
|
1581
|
-
const modelContext = getModelContextApi();
|
|
1582
|
-
if (!modelContext || typeof modelContext.getTools !== "function") return [];
|
|
1583
|
-
try {
|
|
1584
|
-
const rawTools = await modelContext.getTools();
|
|
1585
|
-
if (!Array.isArray(rawTools)) return [];
|
|
1586
|
-
return rawTools.map((tool) => ({
|
|
1587
|
-
name: tool.name,
|
|
1588
|
-
...tool.description ? { description: tool.description } : {},
|
|
1589
|
-
inputSchema: parseWebMcpInputSchema(tool.inputSchema),
|
|
1590
|
-
...tool.annotations ? { annotations: tool.annotations } : {},
|
|
1591
|
-
...tool.execute ? { execute: tool.execute } : {}
|
|
1592
|
-
}));
|
|
1593
|
-
} catch (err) {
|
|
1594
|
-
console.warn("Failed to retrieve WebMCP tools via getTools():", err);
|
|
1595
|
-
return [];
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
/**
|
|
1599
|
-
* Register ShadowClaw tools with the WebMCP ModelContext API.
|
|
1600
|
-
*
|
|
1601
|
-
* Both the `@mcp-b/webmcp-polyfill` and Chrome's native API support
|
|
1602
|
-
* `registerTool(tool, { signal })`. We always use AbortController signals so
|
|
1603
|
-
* that unregistration works identically regardless of which implementation is
|
|
1604
|
-
* actually active.
|
|
1605
|
-
*
|
|
1606
|
-
* Key correctness detail: `initializeWebMCPPolyfill()` is a no-op when
|
|
1607
|
-
* Chrome's native `document.modelContext` already exists — it does NOT
|
|
1608
|
-
* override the native API. In that situation we are talking to the native
|
|
1609
|
-
* Chrome API even in "polyfill" mode. The native Chrome API only supports
|
|
1610
|
-
* signal-based unregistration, so using AbortController signals everywhere
|
|
1611
|
-
* prevents "Duplicate tool name" errors when tools are re-configured.
|
|
1612
|
-
*/
|
|
1613
|
-
async function registerWebMcpTools(agentWorker, _emit, groupId = DEFAULT_GROUP_ID, tools) {
|
|
1614
|
-
const activeTools = Array.isArray(tools) ? tools : TOOL_DEFINITIONS;
|
|
1615
|
-
if (activeTools.length === 0) return true;
|
|
1616
|
-
const modelContext = getModelContextApi();
|
|
1617
|
-
if (!modelContext) return false;
|
|
1618
|
-
for (const def of activeTools) {
|
|
1619
|
-
if (registeredToolNames.has(def.name)) continue;
|
|
1620
|
-
const controller = new AbortController();
|
|
1621
|
-
registeredToolControllers.set(def.name, controller);
|
|
1622
|
-
registeredToolNames.add(def.name);
|
|
1623
|
-
try {
|
|
1624
|
-
const toolDef = {
|
|
1625
|
-
name: def.name,
|
|
1626
|
-
description: def.description,
|
|
1627
|
-
inputSchema: parseWebMcpInputSchema(def.input_schema),
|
|
1628
|
-
annotations: {
|
|
1629
|
-
readOnlyHint: false,
|
|
1630
|
-
untrustedContentHint: true
|
|
1631
|
-
},
|
|
1632
|
-
execute: (input, context) => {
|
|
1633
|
-
if (!agentWorker) throw new Error("Cannot execute tool: agent worker is not ready");
|
|
1634
|
-
const signal = extractAbortSignal(context);
|
|
1635
|
-
if (signal?.aborted) return Promise.reject(/* @__PURE__ */ new Error("Tool execution aborted"));
|
|
1636
|
-
return new Promise((resolve, reject) => {
|
|
1637
|
-
const callId = Date.now().toString(36) + Math.random().toString(36).slice(2);
|
|
1638
|
-
let timeout = null;
|
|
1639
|
-
const cleanup = () => {
|
|
1640
|
-
if (timeout !== null) {
|
|
1641
|
-
clearTimeout(timeout);
|
|
1642
|
-
timeout = null;
|
|
1643
|
-
}
|
|
1644
|
-
agentWorker?.removeEventListener("message", handler);
|
|
1645
|
-
if (signal && onAbort) signal.removeEventListener("abort", onAbort);
|
|
1646
|
-
};
|
|
1647
|
-
const onAbort = () => {
|
|
1648
|
-
cleanup();
|
|
1649
|
-
reject(/* @__PURE__ */ new Error("Tool execution aborted"));
|
|
1650
|
-
};
|
|
1651
|
-
if (signal) signal.addEventListener("abort", onAbort, { once: true });
|
|
1652
|
-
timeout = setTimeout(() => {
|
|
1653
|
-
cleanup();
|
|
1654
|
-
reject(/* @__PURE__ */ new Error("Timeout waiting for tool execution"));
|
|
1655
|
-
}, 6e5);
|
|
1656
|
-
const handler = (event) => {
|
|
1657
|
-
const data = event.data;
|
|
1658
|
-
if (data && data.type === "execute-tool-result" && data.callId === callId) {
|
|
1659
|
-
cleanup();
|
|
1660
|
-
if (data.error) reject(new Error(data.error));
|
|
1661
|
-
else resolve(data.result);
|
|
1662
|
-
}
|
|
1663
|
-
};
|
|
1664
|
-
agentWorker.addEventListener("message", handler);
|
|
1665
|
-
agentWorker.postMessage({
|
|
1666
|
-
type: "execute-tool",
|
|
1667
|
-
callId,
|
|
1668
|
-
payload: {
|
|
1669
|
-
name: def.name,
|
|
1670
|
-
input: input || {},
|
|
1671
|
-
groupId
|
|
1672
|
-
}
|
|
1673
|
-
});
|
|
1674
|
-
});
|
|
1675
|
-
}
|
|
1676
|
-
};
|
|
1677
|
-
await modelContext.registerTool(toolDef, { signal: controller.signal });
|
|
1678
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1679
|
-
} catch (err) {
|
|
1680
|
-
registeredToolControllers.delete(def.name);
|
|
1681
|
-
registeredToolNames.delete(def.name);
|
|
1682
|
-
if (!(err instanceof Error && (err.message.includes("already registered") || err.message.includes("Duplicate tool name")))) {
|
|
1683
|
-
console.error(`Failed to register tool ${def.name}:`, err);
|
|
1684
|
-
throw err;
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
}
|
|
1688
|
-
return true;
|
|
1689
|
-
}
|
|
1690
|
-
/**
|
|
1691
|
-
* Unregister previously registered ShadowClaw WebMCP tools.
|
|
1692
|
-
*
|
|
1693
|
-
* Aborts every AbortController associated with a registered tool. This works
|
|
1694
|
-
* for both the polyfill (which listens for the `abort` event on the signal it
|
|
1695
|
-
* was given) and Chrome's native API (which also uses signal-based lifecycle).
|
|
1696
|
-
* The deprecated `unregisterTool(name)` is intentionally NOT called here
|
|
1697
|
-
* because it is absent from the native Chrome API and causes silent failures
|
|
1698
|
-
* that prevent proper cleanup.
|
|
1699
|
-
*/
|
|
1700
|
-
function unregisterWebMcpTools() {
|
|
1701
|
-
for (const controller of registeredToolControllers.values()) try {
|
|
1702
|
-
controller.abort();
|
|
1703
|
-
} catch {}
|
|
1704
|
-
registeredToolControllers.clear();
|
|
1705
|
-
registeredToolNames.clear();
|
|
1706
|
-
}
|
|
1707
|
-
|
|
1708
|
-
//#endregion
|
|
1709
|
-
export { webmcp_exports as a, unregisterWebMcpTools as i, registerWebMcpTools as n, setWebMcpMode as r, getWebMcpMode as t };
|
|
1710
|
-
//# sourceMappingURL=webmcp-BC8_WafM.js.map
|