@xopcai/xopc 0.0.372 → 0.0.374
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/dist/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{activity-store-BQ3PMp2q.js → activity-store-BeYLqqr8.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-D4iAZErG.js → agent-avatar-dicebear-BrA20N2m.js} +1 -1
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-BZrOdxou.js +1 -0
- package/dist/gateway/static/root/assets/{agent-plugin-dialog-BYB0G2aF.js → agent-plugin-dialog-B3ux1AhY.js} +1 -1
- package/dist/gateway/static/root/assets/{agents-D0JBkZPV.js → agents-CXlXFU6M.js} +3 -3
- package/dist/gateway/static/root/assets/{agents-admin-api-HBZvVyzF.js → agents-admin-api-B4tgTbWG.js} +1 -1
- package/dist/gateway/static/root/assets/{app-management-settings-panel-C1tQxHaP.js → app-management-settings-panel-BXahEVPm.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-BfavIBbb.js → appearance-settings-CE2qJMkD.js} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-CUS5S1qa.js → apps-page-DGVOnCxZ.js} +1 -1
- package/dist/gateway/static/root/assets/{archive-plugin-BO3I9zRP.js → archive-plugin-bI9OLnXj.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-iY0KMPSa.js → automations-page-BWL7eT4_.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-workspace-LQsa5ohY.js → automations-workspace-BxIShhkZ.js} +1 -1
- package/dist/gateway/static/root/assets/{binary-plugins-gFD7vH9R.js → binary-plugins-dOwLzjeH.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-Cft0fd_O.js → block-editor-3n446-mX.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-automation-inputs-DxRoKFun.js → browser-automation-inputs-i7h1Svpf.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-automations-page-C6EWx_Y4.js → browser-automations-page-BmTK7Gtn.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-settings-page-CKlt_8IS.js → browser-settings-page-DBQ-WETQ.js} +1 -1
- package/dist/gateway/static/root/assets/{capabilities-CY4SiHcP.js → capabilities-CquUV0DP.js} +1 -1
- package/dist/gateway/static/root/assets/{capabilities-gjQtMhKu.js → capabilities-D4KFLtqM.js} +1 -1
- package/dist/gateway/static/root/assets/{capabilities-page-UrQ8EY_o.js → capabilities-page-D-nQ6Zzi.js} +2 -2
- package/dist/gateway/static/root/assets/{capabilities-settings-panel-C9HIr2CZ.js → capabilities-settings-panel-Dx1fpBmH.js} +6 -6
- package/dist/gateway/static/root/assets/{capability-header-actions-uxIiW_2_.js → capability-header-actions-BRMqvQVb.js} +1 -1
- package/dist/gateway/static/root/assets/{channels-By3dmQ4Y.js → channels-DXfEP1FR.js} +1 -1
- package/dist/gateway/static/root/assets/{chat-terminal-dock-DeDTSl64.js → chat-terminal-dock-BRdzCjWO.js} +1 -1
- package/dist/gateway/static/root/assets/cloud-credits-BMYMiiNn.js +1 -0
- package/dist/gateway/static/root/assets/{computer-settings-page-Cw1Z1epy.js → computer-settings-page-BhCHMRpD.js} +1 -1
- package/dist/gateway/static/root/assets/{connector-service-page-D664WEhj.js → connector-service-page-BXE8Z-Ll.js} +1 -1
- package/dist/gateway/static/root/assets/{connectors-page-sjyjY7Fl.js → connectors-page-D9RZjhw8.js} +1 -1
- package/dist/gateway/static/root/assets/{date-picker-BVmFrPfX.js → date-picker-BJ7N92wm.js} +1 -1
- package/dist/gateway/static/root/assets/{dependency-picker-YIoP-e5-.js → dependency-picker-gyxCM-hb.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-CzS468vR.js → desktop-pet-B-WM4l-L.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-BPcgZUcK.js → desktop-pet-settings-usJqcew5.js} +1 -1
- package/dist/gateway/static/root/assets/{device-pairing-wizard-Cgba-4m9.js → device-pairing-wizard-DoSR4DGk.js} +1 -1
- package/dist/gateway/static/root/assets/{directory-picker-path-field-_nHmZtnY.js → directory-picker-path-field-DqVlV2YH.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-IIky9Iqr.js → extension-debug-page-CbgEonkK.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-C-7ngTTj.js → extension-page-CUule9SU.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-provider-VFWspV08.js → extension-provider-DxlAZ2iy.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-_hovFCWi.js → extension-settings-page-_OFukkEJ.js} +1 -1
- package/dist/gateway/static/root/assets/{fallback-models-CUHrPpGV.js → fallback-models-CiSc3h8i.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-swr-7RKqgU_U.js → gateway-config-swr-BoRkBnsw.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-realtime-BwX_fHUS.js → gateway-realtime-C3WQQY10.js} +1 -1
- package/dist/gateway/static/root/assets/gateway-realtime-store-cLCDEe4D.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-settings-sbaOzlEH.js → gateway-settings-qSUrpS1h.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-startup-retry-jiV5sbEX.js → gateway-startup-retry-TYSQEQcG.js} +1 -1
- package/dist/gateway/static/root/assets/{home-page-DjquRIFR.js → home-page-COjDsuzg.js} +1 -1
- package/dist/gateway/static/root/assets/{image-generation-api-DO4mXb6I.js → image-generation-api-_pKiNfSq.js} +1 -1
- package/dist/gateway/static/root/assets/{imports-page-xWWIeT_t.js → imports-page-DdvIj-ZL.js} +1 -1
- package/dist/gateway/static/root/assets/{index-BWDK2eIj.js → index-DEaVabvo.js} +7 -7
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-DWazrDgz.js → keyboard-shortcuts-settings-DbqFlNsF.js} +1 -1
- package/dist/gateway/static/root/assets/{local-app-workbench-page-CkxDdlYU.js → local-app-workbench-page-REowUzkp.js} +1 -1
- package/dist/gateway/static/root/assets/{local-apps-page-BISZ4bi5.js → local-apps-page-DdCMNn_z.js} +1 -1
- package/dist/gateway/static/root/assets/{local-session-drafts-pox8evDV.js → local-session-drafts-Cg9RdsNN.js} +1 -1
- package/dist/gateway/static/root/assets/{locale-store-COVscAqC.js → locale-store-rWFLl-p4.js} +1 -1
- package/dist/gateway/static/root/assets/{logs-page-GiCulc9k.js → logs-page-B_6fHDoi.js} +1 -1
- package/dist/gateway/static/root/assets/management-settings-D4vcSRE3.js +1 -0
- package/dist/gateway/static/root/assets/{markdown-view-B_qnAcW2.js → markdown-view-BHFFusQs.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-C0Pc-wSY.js → media-plugins-BVPTMWJI.js} +1 -1
- package/dist/gateway/static/root/assets/messages-C1SUo4gG.js +3 -0
- package/dist/gateway/static/root/assets/models-hub-cache-Jj8dvYcv.js +1 -0
- package/dist/gateway/static/root/assets/{note-detail-panel-CqealmSc.js → note-detail-panel-B7U6EbAi.js} +3 -3
- package/dist/gateway/static/root/assets/{notes-api-sBgBcyLW.js → notes-api-CSLVCZBn.js} +1 -1
- package/dist/gateway/static/root/assets/{notes-page-BtTU5mnS.js → notes-page-BzHVaH8j.js} +1 -1
- package/dist/gateway/static/root/assets/{page-context-capture-button-Yt-BpPRh.js → page-context-capture-button-D7Y4vFRN.js} +1 -1
- package/dist/gateway/static/root/assets/personal-page-E6huhFk4.js +1 -0
- package/dist/gateway/static/root/assets/{product-open-page-etM6Ijfe.js → product-open-page-CK_czbBx.js} +1 -1
- package/dist/gateway/static/root/assets/{product-preview-content-C6aeRrWe.js → product-preview-content-CU6KlaVP.js} +1 -1
- package/dist/gateway/static/root/assets/{project-detail-page-K4ASOTki.js → project-detail-page-c3ye2bdq.js} +1 -1
- package/dist/gateway/static/root/assets/{projects-page-BssImjwl.js → projects-page-BA1UuuRF.js} +1 -1
- package/dist/gateway/static/root/assets/{registry-api-Bh9UBb-f.js → registry-api-CoMBYjHD.js} +1 -1
- package/dist/gateway/static/root/assets/{remote-access-hub-BznC_5H0.js → remote-access-hub-D_FLVZAm.js} +1 -1
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-BJAzqQik.js → runtime-tools-settings-panel-Cxjmwdyf.js} +1 -1
- package/dist/gateway/static/root/assets/{scenes-page-uZUXm03X.js → scenes-page-Av47PHdM.js} +1 -1
- package/dist/gateway/static/root/assets/{schema-form-SA3Ld7zf.js → schema-form-IM7QeSm3.js} +1 -1
- package/dist/gateway/static/root/assets/{send-session-input-Di3Q846r.js → send-session-input-CLhR1uEp.js} +1 -1
- package/dist/gateway/static/root/assets/{session-api-yjpEz4pP.js → session-api-u_4_kFQt.js} +1 -1
- package/dist/gateway/static/root/assets/{session-manager-CWjhJxJs.js → session-manager-B06ZCie_.js} +1 -1
- package/dist/gateway/static/root/assets/{sessions-page-DdL8zVrF.js → sessions-page-Bol3ScEc.js} +1 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-DpCanqrD.js +1 -0
- package/dist/gateway/static/root/assets/{settings-page-CUJQMNF7.js → settings-page-BeVtwwVd.js} +1 -1
- package/dist/gateway/static/root/assets/{setup-status-panel-BGBWC0Bc.js → setup-status-panel-zTmrMwMm.js} +1 -1
- package/dist/gateway/static/root/assets/{share-link-dialog-HCHM8qnf.js → share-link-dialog-XhiuPKF4.js} +1 -1
- package/dist/gateway/static/root/assets/{share-preview-page-DJmyACyp.js → share-preview-page-Vc0TQuZ8.js} +1 -1
- package/dist/gateway/static/root/assets/{shares-api-c0dfWz6h.js → shares-api-BVSb1vh4.js} +1 -1
- package/dist/gateway/static/root/assets/{shares-settings-BzqcGh7W.js → shares-settings-Bkhkt_6M.js} +1 -1
- package/dist/gateway/static/root/assets/{skill-api-9XSn7R8L.js → skill-api-Dgwc707w.js} +1 -1
- package/dist/gateway/static/root/assets/{skill-reload-api-Ge5XymHa.js → skill-reload-api-BsLx_FXd.js} +1 -1
- package/dist/gateway/static/root/assets/{skills-page-DwyDfh9g.js → skills-page-CFIte-vM.js} +1 -1
- package/dist/gateway/static/root/assets/{system-settings-panel-B6axBPLO.js → system-settings-panel-Ck6zGDHb.js} +1 -1
- package/dist/gateway/static/root/assets/{task-detail-page-ftCTqBDB.js → task-detail-page-C3ZPEZqw.js} +1 -1
- package/dist/gateway/static/root/assets/{task-expandable-content-hYcgCEE3.js → task-expandable-content-DxeBTJvh.js} +1 -1
- package/dist/gateway/static/root/assets/{theme-store-BOfCKgl6.js → theme-store-KcQhCg1-.js} +1 -1
- package/dist/gateway/static/root/assets/{tracing-settings-page-DDWFXcST.js → tracing-settings-page-DJRAP3nb.js} +1 -1
- package/dist/gateway/static/root/assets/{tunnel-api-BYU2v0im.js → tunnel-api-CjxMpAm2.js} +1 -1
- package/dist/gateway/static/root/assets/usage-page-Dnhp9xQ4.js +1 -0
- package/dist/gateway/static/root/assets/{use-autosave-CSckcjFx.js → use-autosave-C-IWxbzm.js} +1 -1
- package/dist/gateway/static/root/assets/{use-composer-attachments-OFlldkKg.js → use-composer-attachments-Dxphaxk-.js} +1 -1
- package/dist/gateway/static/root/assets/{use-file-preview-expanded-BF1TeNXP.js → use-file-preview-expanded-Du37Gofn.js} +2 -2
- package/dist/gateway/static/root/assets/{user-model-page-CqnGITYf.js → user-model-page-sx1lNWKf.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-api-key-field-GEw5x2fU.js → voice-api-key-field-7BImy8Jc.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-config-api-3yyVwXln.js → voice-config-api-6MINytQl.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-overlay-BDM7BEKH.js → work-discovery-overlay-CVd_y3K2.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-BBwx-tUb.js → workflow-run-setup-panel-Dwg40uGK.js} +1 -1
- package/dist/gateway/static/root/assets/{workflows-page-BHigZn6E.js → workflows-page-BQR4JdXB.js} +1 -1
- package/dist/gateway/static/root/assets/{workspace-api-CTm8s6Jr.js → workspace-api-CXiyhTwv.js} +2 -2
- package/dist/gateway/static/root/assets/xopc-cloud-account-card-CaKc_J7j.js +1 -0
- package/dist/gateway/static/root/index.html +26 -26
- package/dist/package.js +1 -1
- package/dist/packages/gateway-contract/src/cloud-credits.js +80 -0
- package/dist/packages/gateway-contract/src/index.js +2 -0
- package/dist/packages/realtime-protocol/src/voice.js +11 -0
- package/dist/src/agent/client-error-format.d.ts +1 -1
- package/dist/src/agent/client-error-format.js +7 -0
- package/dist/src/agent/embedded/run-turn.js +39 -3
- package/dist/src/agent/embedded/xopc-stream-bridge.js +18 -0
- package/dist/src/agent/image/generation/openai-images-provider.d.ts +2 -1
- package/dist/src/agent/image/generation/openai-images-provider.js +13 -7
- package/dist/src/agent/image/generation/providers/xopc-cloud.js +14 -2
- package/dist/src/agent-config/schema.d.ts +13 -0
- package/dist/src/agent-config/schema.js +2 -0
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/cli/commands/gateway/shared.js +2 -1
- package/dist/src/cli/commands/models.js +41 -0
- package/dist/src/computer/runtime.js +3 -0
- package/dist/src/config/gateway-bind.js +2 -1
- package/dist/src/config/index.js +2 -2
- package/dist/src/config/models-json.d.ts +8 -8
- package/dist/src/config/schema.d.ts +13 -12
- package/dist/src/config/schema.js +7 -3
- package/dist/src/daemon/constants.js +14 -9
- package/dist/src/daemon/index.js +4 -1
- package/dist/src/daemon/install-plan.js +2 -1
- package/dist/src/daemon/launchd.js +2 -1
- package/dist/src/daemon/schtasks.js +2 -1
- package/dist/src/daemon/service-audit.js +2 -1
- package/dist/src/daemon/service.js +2 -1
- package/dist/src/daemon/systemd.js +2 -1
- package/dist/src/gateway/client-ip.js +2 -1
- package/dist/src/gateway/hono/app.js +2 -1
- package/dist/src/gateway/hono/lib/config-payload.d.ts +1 -0
- package/dist/src/gateway/hono/middleware/auth.d.ts +3 -5
- package/dist/src/gateway/hono/middleware/auth.js +56 -14
- package/dist/src/gateway/hono/middleware/logger.js +2 -1
- package/dist/src/gateway/hono/middleware/public-device-rate-limit.d.ts +16 -0
- package/dist/src/gateway/hono/middleware/public-device-rate-limit.js +43 -0
- package/dist/src/gateway/hono/middleware/strict-rate-limit.js +3 -2
- package/dist/src/gateway/hono/oauth-async.js +2 -1
- package/dist/src/gateway/hono/routes/browser.js +2 -1
- package/dist/src/gateway/hono/routes/config.js +2 -1
- package/dist/src/gateway/hono/routes/device-pairing-approval.d.ts +3 -8
- package/dist/src/gateway/hono/routes/device-pairing-approval.js +5 -20
- package/dist/src/gateway/hono/routes/devices.js +25 -9
- package/dist/src/gateway/hono/routes/endpoint-tools.js +1 -0
- package/dist/src/gateway/hono/routes/models.js +1 -1
- package/dist/src/gateway/hono/routes/personal-agent.js +3 -2
- package/dist/src/gateway/hono/routes/public-gateway.js +6 -6
- package/dist/src/gateway/hono/routes/shares.js +2 -1
- package/dist/src/gateway/hono/routes/usage.js +15 -5
- package/dist/src/gateway/hono/routes/voice.js +1 -0
- package/dist/src/gateway/host.js +9 -4
- package/dist/src/gateway/index.js +8 -4
- package/dist/src/gateway/listen.js +2 -1
- package/dist/src/gateway/rate-limit/auth-policy.js +7 -11
- package/dist/src/gateway/rate-limit/buckets.d.ts +6 -0
- package/dist/src/gateway/rate-limit/buckets.js +211 -189
- package/dist/src/gateway/rate-limit/env-flags.js +4 -1
- package/dist/src/gateway/rate-limit/index.js +13 -4
- package/dist/src/gateway/runtime-config.js +5 -3
- package/dist/src/gateway/security/audit.js +3 -2
- package/dist/src/gateway/security/browser-session.js +2 -1
- package/dist/src/gateway/security/device-request-proof.d.ts +28 -0
- package/dist/src/gateway/security/device-request-proof.js +122 -0
- package/dist/src/gateway/security/loopback.js +7 -6
- package/dist/src/gateway/service.js +8 -6
- package/dist/src/gateway/tailscale-auth.js +2 -1
- package/dist/src/gateway/ws-security.js +2 -1
- package/dist/src/infra/rate-limit/failure-limiter.js +78 -90
- package/dist/src/infra/rate-limit/index.js +11 -3
- package/dist/src/infra/rate-limit/keyed-store.js +52 -47
- package/dist/src/infra/rate-limit/rate-limiter.js +55 -58
- package/dist/src/infra/update-service-refresh.js +2 -1
- package/dist/src/personal-agent/repository.d.ts +3 -0
- package/dist/src/personal-agent/repository.js +1 -0
- package/dist/src/personal-agent/service.d.ts +6 -2
- package/dist/src/personal-agent/service.js +4 -3
- package/dist/src/platform/client.d.ts +2 -2
- package/dist/src/platform/contracts.d.ts +2 -2
- package/dist/src/providers/model-call.js +15 -1
- package/dist/src/providers/xopc-cloud-account-service.d.ts +7 -23
- package/dist/src/providers/xopc-cloud-account-service.js +49 -29
- package/dist/src/providers/xopc-cloud-credit-budget.d.ts +14 -0
- package/dist/src/providers/xopc-cloud-credit-budget.js +61 -0
- package/dist/src/realtime/runtime.js +6 -0
- package/dist/src/realtime/tickets.d.ts +1 -0
- package/dist/src/realtime/tickets.js +4 -0
- package/dist/src/remote-access/exposure-guards.js +2 -1
- package/dist/src/share/share-rate-limit.js +2 -1
- package/dist/src/share/share-url.js +2 -1
- package/dist/src/share/site-share-router.js +2 -1
- package/dist/src/storage/sqlite/ai-usage-repository.d.ts +9 -0
- package/dist/src/storage/sqlite/ai-usage-repository.js +94 -5
- package/dist/src/storage/sqlite/device-access-repository.d.ts +7 -0
- package/dist/src/storage/sqlite/device-access-repository.js +22 -4
- package/dist/src/storage/sqlite/migrations/242_cloud_usage_receipts.sql +5 -0
- package/dist/src/storage/sqlite/migrations/243_voice_opening_greetings.sql +12 -0
- package/dist/src/storage/sqlite/migrations/244_device_request_proofs.sql +8 -0
- package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
- package/dist/src/storage/sqlite/migrations/runner.js +3 -3
- package/dist/src/storage/sqlite/schema.js +1 -1
- package/dist/src/tunnel/broker-client.js +2 -0
- package/dist/src/tunnel/tunnel-config.js +2 -2
- package/dist/src/tunnel/tunnel-rate-limit.js +2 -1
- package/dist/src/usage/cloud-capability.d.ts +2 -0
- package/dist/src/usage/cloud-capability.js +34 -0
- package/dist/src/usage/cloud-receipts.d.ts +10 -0
- package/dist/src/usage/cloud-receipts.js +55 -0
- package/dist/src/usage/cost.js +1 -0
- package/dist/src/usage/recorder.js +3 -1
- package/dist/src/usage/scenario-registry.js +15 -0
- package/dist/src/utils/logger/redact.js +4 -1
- package/dist/src/voice/platform-streams.d.ts +6 -0
- package/dist/src/voice/platform-streams.js +43 -4
- package/dist/src/voice/realtime/agentEngine.js +138 -83
- package/dist/src/voice/realtime/engine.d.ts +6 -0
- package/dist/src/voice/realtime/opening-greeting.d.ts +12 -0
- package/dist/src/voice/realtime/opening-greeting.js +22 -0
- package/dist/src/voice/realtime/runtime.js +116 -22
- package/dist/src/voice/realtime/runtime.types.d.ts +4 -0
- package/dist/src/voice/stt/providers/xopc-cloud-transcription.js +28 -14
- package/dist/src/voice/tts/providers/xopc-cloud-speech.js +39 -29
- package/dist/src/voice/tts/speech-provider-types.d.ts +1 -0
- package/package.json +5 -5
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-BdxzGSiO.js +0 -1
- package/dist/gateway/static/root/assets/gateway-realtime-store-BheKaO6d.js +0 -1
- package/dist/gateway/static/root/assets/management-settings-GUpOcTqa.js +0 -1
- package/dist/gateway/static/root/assets/messages-Bb2GK-Nj.js +0 -3
- package/dist/gateway/static/root/assets/models-hub-cache-DyPPksMP.js +0 -1
- package/dist/gateway/static/root/assets/personal-page-C8SEQpEu.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-DmawLOHR.js +0 -1
- package/dist/gateway/static/root/assets/usage-page-BvPcpxTQ.js +0 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { init_transaction, runSqliteWriteTransaction } from "../../storage/sqlite/transaction.js";
|
|
2
|
+
import { getDevice, init_device_access_repository } from "../../storage/sqlite/device-access-repository.js";
|
|
3
|
+
import { getOrCreateGatewayIdentity, init_gateway_identity_repository } from "../../storage/sqlite/gateway-identity-repository.js";
|
|
4
|
+
import crypto from "node:crypto";
|
|
5
|
+
//#region src/gateway/security/device-request-proof.ts
|
|
6
|
+
init_device_access_repository();
|
|
7
|
+
init_gateway_identity_repository();
|
|
8
|
+
init_transaction();
|
|
9
|
+
const REQUEST_PROOF_WINDOW_MS = 12e4;
|
|
10
|
+
const PROOF_HEADER = "X-Xopc-Proof";
|
|
11
|
+
const SIGNED_REQUEST_HEADERS = [
|
|
12
|
+
"content-type",
|
|
13
|
+
"idempotency-key",
|
|
14
|
+
"x-xopc-expected-session-key",
|
|
15
|
+
"x-endpoint-id",
|
|
16
|
+
"x-endpoint-upload-token"
|
|
17
|
+
];
|
|
18
|
+
const MAX_PENDING_NONCES = 1e5;
|
|
19
|
+
const nonceBudgets = /* @__PURE__ */ new WeakMap();
|
|
20
|
+
let activeProofBodies = 0;
|
|
21
|
+
const activeDeviceBodies = /* @__PURE__ */ new Map();
|
|
22
|
+
/** Bounds buffered uploads through route completion, after signature verification. */
|
|
23
|
+
function acquireProofBodyBudget(deviceId) {
|
|
24
|
+
const count = activeDeviceBodies.get(deviceId) ?? 0;
|
|
25
|
+
if (activeProofBodies >= 16 || count >= 8) return void 0;
|
|
26
|
+
activeProofBodies++;
|
|
27
|
+
activeDeviceBodies.set(deviceId, count + 1);
|
|
28
|
+
let held = true;
|
|
29
|
+
return () => {
|
|
30
|
+
if (!held) return;
|
|
31
|
+
held = false;
|
|
32
|
+
activeProofBodies--;
|
|
33
|
+
const remaining = (activeDeviceBodies.get(deviceId) ?? 1) - 1;
|
|
34
|
+
if (remaining) activeDeviceBodies.set(deviceId, remaining);
|
|
35
|
+
else activeDeviceBodies.delete(deviceId);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function proofDigest(bytes) {
|
|
39
|
+
return crypto.createHash("sha256").update(bytes).digest("hex");
|
|
40
|
+
}
|
|
41
|
+
function parseRequestProof(header) {
|
|
42
|
+
if (!header || header.length > 256) return void 0;
|
|
43
|
+
const parts = header.split(".");
|
|
44
|
+
if (parts.length !== 4 || !/^\d{13}$/.test(parts[0]) || !/^[A-Za-z0-9_-]{22,64}$/.test(parts[1]) || !/^[a-f0-9]{64}$/.test(parts[2]) || !/^[A-Za-z0-9_-]{86}$/.test(parts[3])) return void 0;
|
|
45
|
+
return {
|
|
46
|
+
timestamp: Number(parts[0]),
|
|
47
|
+
nonce: parts[1],
|
|
48
|
+
digest: parts[2],
|
|
49
|
+
signature: parts[3]
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function requestProofMessage(input) {
|
|
53
|
+
return [
|
|
54
|
+
"xopc-request-v1",
|
|
55
|
+
input.gatewayId,
|
|
56
|
+
proofDigest(input.credential),
|
|
57
|
+
input.method,
|
|
58
|
+
input.target,
|
|
59
|
+
input.proof.digest,
|
|
60
|
+
...SIGNED_REQUEST_HEADERS.map((name) => input.headers(name) ?? ""),
|
|
61
|
+
String(input.proof.timestamp),
|
|
62
|
+
input.proof.nonce
|
|
63
|
+
].join("\n");
|
|
64
|
+
}
|
|
65
|
+
function verifyRequestProofSignature(device, proof, message) {
|
|
66
|
+
try {
|
|
67
|
+
const key = crypto.createPublicKey({
|
|
68
|
+
key: device.publicKeyJwk,
|
|
69
|
+
format: "jwk"
|
|
70
|
+
});
|
|
71
|
+
return crypto.verify("sha256", Buffer.from(message), {
|
|
72
|
+
key,
|
|
73
|
+
dsaEncoding: "ieee-p1363"
|
|
74
|
+
}, Buffer.from(proof.signature, "base64url"));
|
|
75
|
+
} catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** The unique insert happens before business effects; expiry includes future-dated proofs. */
|
|
80
|
+
function consumeRequestNonce(deviceId, proof, now = Date.now()) {
|
|
81
|
+
return runSqliteWriteTransaction((db) => {
|
|
82
|
+
let budget = nonceBudgets.get(db);
|
|
83
|
+
if (!budget || now >= budget.cleanupAt) {
|
|
84
|
+
db.prepare("DELETE FROM device_request_nonces WHERE expires_at < ?").run(now);
|
|
85
|
+
const count = db.prepare("SELECT count(*) AS total FROM device_request_nonces").get();
|
|
86
|
+
budget = {
|
|
87
|
+
cleanupAt: now + 3e4,
|
|
88
|
+
total: count.total
|
|
89
|
+
};
|
|
90
|
+
nonceBudgets.set(db, budget);
|
|
91
|
+
}
|
|
92
|
+
if (Math.abs(now - proof.timestamp) > 12e4 || budget.total >= MAX_PENDING_NONCES) return false;
|
|
93
|
+
const inserted = db.prepare("INSERT OR IGNORE INTO device_request_nonces (device_id, nonce, expires_at) VALUES (?, ?, ?)").run(deviceId, proof.nonce, proof.timestamp + REQUEST_PROOF_WINDOW_MS).changes === 1;
|
|
94
|
+
if (inserted) budget.total++;
|
|
95
|
+
return inserted;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/** Native WebSocket upgrades bind the first ticket to the device key without another round trip. */
|
|
99
|
+
function verifyDeviceConnectionProof(principalId, ticket, path, header) {
|
|
100
|
+
let device;
|
|
101
|
+
try {
|
|
102
|
+
device = getDevice(principalId);
|
|
103
|
+
} catch {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
if (!device) return !header;
|
|
107
|
+
if (device.revokedAt !== void 0) return false;
|
|
108
|
+
if (!device.requestProofVersion && !header) return true;
|
|
109
|
+
const proof = parseRequestProof(header);
|
|
110
|
+
if (!proof || Math.abs(Date.now() - proof.timestamp) > 12e4 || proof.digest !== proofDigest("")) return false;
|
|
111
|
+
const message = requestProofMessage({
|
|
112
|
+
gatewayId: getOrCreateGatewayIdentity().id,
|
|
113
|
+
credential: ticket,
|
|
114
|
+
method: "CONNECT",
|
|
115
|
+
target: path,
|
|
116
|
+
headers: () => void 0,
|
|
117
|
+
proof
|
|
118
|
+
});
|
|
119
|
+
return verifyRequestProofSignature(device, proof, message) && consumeRequestNonce(device.id, proof);
|
|
120
|
+
}
|
|
121
|
+
//#endregion
|
|
122
|
+
export { PROOF_HEADER, REQUEST_PROOF_WINDOW_MS, SIGNED_REQUEST_HEADERS, acquireProofBodyBudget, consumeRequestNonce, parseRequestProof, proofDigest, requestProofMessage, verifyDeviceConnectionProof, verifyRequestProofSignature };
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __esmMin } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { init_host, isLoopbackHost } from "../host.js";
|
|
2
3
|
//#region src/gateway/security/loopback.ts
|
|
3
|
-
/**
|
|
4
|
-
* Loopback / browser-origin classification helpers used by rate-limit policy
|
|
5
|
-
* and other security middleware. Pure functions, no I/O.
|
|
6
|
-
*/
|
|
7
4
|
function isLoopbackClientIp(clientIp) {
|
|
8
5
|
if (!clientIp || clientIp === "unknown") return false;
|
|
9
6
|
const trimmed = clientIp.trim();
|
|
@@ -39,5 +36,9 @@ function getClientIpFromHeaders(headers) {
|
|
|
39
36
|
if (cf) return cf;
|
|
40
37
|
return "unknown";
|
|
41
38
|
}
|
|
39
|
+
var init_loopback = __esmMin((() => {
|
|
40
|
+
init_host();
|
|
41
|
+
}));
|
|
42
42
|
//#endregion
|
|
43
|
-
|
|
43
|
+
init_loopback();
|
|
44
|
+
export { getClientIpFromHeaders, init_loopback, isLoopbackBrowserOrigin, isLoopbackClientIp, isLoopbackEmbeddedBrowserClient };
|
|
@@ -8,6 +8,10 @@ import { init_logger } from "../utils/logger.js";
|
|
|
8
8
|
import { closeXopcDatabase } from "../storage/sqlite/connection.js";
|
|
9
9
|
import { getSqliteDatabase, init_transaction } from "../storage/sqlite/transaction.js";
|
|
10
10
|
import { getBrowserTabBindingById, init_browser_tab_binding_repository } from "../storage/sqlite/browser-tab-binding-repository.js";
|
|
11
|
+
import { buckets } from "./rate-limit/buckets.js";
|
|
12
|
+
import { init_host, resolveEffectiveGatewayPort } from "./host.js";
|
|
13
|
+
import { isGatewayStrictSecurityEnabled } from "./rate-limit/env-flags.js";
|
|
14
|
+
import { init_rate_limit } from "./rate-limit/index.js";
|
|
11
15
|
import { bumpSessionInputRevision, findSessionInput, init_session_input_repository, insertSessionInput } from "../storage/sqlite/session-input-repository.js";
|
|
12
16
|
import { TaskRepository } from "../tasks/task-repository.js";
|
|
13
17
|
import { TaskRunRepository, init_task_run_repository } from "../tasks/task-run-repository.js";
|
|
@@ -38,7 +42,6 @@ import { DomainOutboxDispatcher } from "../infra/domain-outbox-dispatcher.js";
|
|
|
38
42
|
import { ProjectService } from "../projects/project-service.js";
|
|
39
43
|
import { resolveProjectAgentId } from "../projects/project-agent.js";
|
|
40
44
|
import "../projects/index.js";
|
|
41
|
-
import { resolveEffectiveGatewayPort } from "./host.js";
|
|
42
45
|
import { runMemoryMaintenance } from "../memory-maintenance/service.js";
|
|
43
46
|
import "../memory-maintenance/index.js";
|
|
44
47
|
import { RealtimeExtensionBrowserProvider } from "../browser/providers/realtime-extension.js";
|
|
@@ -72,10 +75,10 @@ import { bootstrapApplicationStateSync } from "../bootstrap/application-state.js
|
|
|
72
75
|
import { setPairingBroadcastSink } from "../channels/pairing/pairing-events.js";
|
|
73
76
|
import { registerClarificationChannelRuntime } from "./clarify-runtime.js";
|
|
74
77
|
import { ChannelManager } from "../channels/manager.js";
|
|
75
|
-
import { ChatPreviewService } from "../chat-previews/service.js";
|
|
76
|
-
import "../chat-previews/index.js";
|
|
77
78
|
import { getWorkspacePath } from "../config/workspace-path-helpers.js";
|
|
78
79
|
import "../config/index.js";
|
|
80
|
+
import { ChatPreviewService } from "../chat-previews/service.js";
|
|
81
|
+
import "../chat-previews/index.js";
|
|
79
82
|
import { ManagedComposioEventPoller } from "../connectors/composio-managed-events.js";
|
|
80
83
|
import { startConnectedKnowledgeCoordinator } from "../knowledge/coordinator.js";
|
|
81
84
|
import "../knowledge/index.js";
|
|
@@ -124,9 +127,6 @@ import { wireTunnelEventsToGateway } from "../tunnel/gateway-lifecycle.js";
|
|
|
124
127
|
import { getExposureManager } from "../remote-access/exposure-manager.js";
|
|
125
128
|
import { sanitizeTunnelConfig } from "../tunnel/tunnel-config.js";
|
|
126
129
|
import { assertGatewayAuthNotKnownWeak } from "./security/known-weak-secrets.js";
|
|
127
|
-
import { buckets } from "./rate-limit/buckets.js";
|
|
128
|
-
import { isGatewayStrictSecurityEnabled } from "./rate-limit/env-flags.js";
|
|
129
|
-
import "./rate-limit/index.js";
|
|
130
130
|
import { assertGatewayRuntimeConfig } from "./runtime-config.js";
|
|
131
131
|
import { auditGatewayConfig } from "./security/audit.js";
|
|
132
132
|
import { getXopcCloudCatalogCoordinator } from "../providers/xopc-cloud-catalog-coordinator.js";
|
|
@@ -169,6 +169,8 @@ init_config_repository();
|
|
|
169
169
|
init_changes();
|
|
170
170
|
init_agent_scope();
|
|
171
171
|
init_schema();
|
|
172
|
+
init_host();
|
|
173
|
+
init_rate_limit();
|
|
172
174
|
init_providers();
|
|
173
175
|
init_logger();
|
|
174
176
|
init_log_stream();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { init_host, isLoopbackHost } from "./host.js";
|
|
1
2
|
import { readTailscaleWhoisIdentity } from "../infra/tailscale.js";
|
|
2
|
-
import { isLoopbackHost } from "./host.js";
|
|
3
3
|
//#region src/gateway/tailscale-auth.ts
|
|
4
|
+
init_host();
|
|
4
5
|
function parseTailscaleAuthHeaders(headers) {
|
|
5
6
|
return {
|
|
6
7
|
forwardedFor: headers["x-forwarded-for"]?.split(",")[0]?.trim(),
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { isLoopbackHost } from "./host.js";
|
|
1
|
+
import { init_host, isLoopbackHost } from "./host.js";
|
|
2
2
|
import net from "node:net";
|
|
3
3
|
//#region src/gateway/ws-security.ts
|
|
4
4
|
/**
|
|
5
5
|
* WebSocket / gateway URL transport security (OpenClaw-aligned).
|
|
6
6
|
*/
|
|
7
|
+
init_host();
|
|
7
8
|
function isPrivateOrLoopbackHost(hostname) {
|
|
8
9
|
const host = hostname.trim().toLowerCase();
|
|
9
10
|
if (isLoopbackHost(host)) return true;
|
|
@@ -1,98 +1,86 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __esmMin } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { KeyedStore, init_keyed_store } from "./keyed-store.js";
|
|
2
3
|
//#region src/infra/rate-limit/failure-limiter.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
clock;
|
|
25
|
-
maxFailures;
|
|
26
|
-
windowMs;
|
|
27
|
-
blockDurationMs;
|
|
28
|
-
burstCoalesceMs;
|
|
29
|
-
constructor(cfg) {
|
|
30
|
-
this.maxFailures = Math.max(1, Math.floor(cfg.maxFailures));
|
|
31
|
-
this.windowMs = Math.max(1e3, Math.floor(cfg.windowMs));
|
|
32
|
-
this.blockDurationMs = Math.max(1e3, Math.floor(cfg.blockDurationMs));
|
|
33
|
-
this.burstCoalesceMs = Math.max(0, Math.floor(cfg.burstCoalesceMs ?? DEFAULT_BURST_COALESCE_MS));
|
|
34
|
-
this.clock = cfg.clock ?? Date.now;
|
|
35
|
-
this.store = new KeyedStore({
|
|
36
|
-
staleAfterMs: cfg.staleAfterMs ?? this.windowMs + this.blockDurationMs,
|
|
37
|
-
clock: this.clock
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
check(key) {
|
|
41
|
-
const now = this.clock();
|
|
42
|
-
const state = this.store.get(key);
|
|
43
|
-
if (!state?.blockedUntil) return { blocked: false };
|
|
44
|
-
if (now >= state.blockedUntil) {
|
|
45
|
-
state.blockedUntil = void 0;
|
|
46
|
-
state.count = 0;
|
|
47
|
-
state.windowStart = now;
|
|
48
|
-
state.lastTouchedMs = now;
|
|
49
|
-
return { blocked: false };
|
|
4
|
+
var DEFAULT_BURST_COALESCE_MS, FailureLimiter;
|
|
5
|
+
var init_failure_limiter = __esmMin((() => {
|
|
6
|
+
init_keyed_store();
|
|
7
|
+
DEFAULT_BURST_COALESCE_MS = 1e3;
|
|
8
|
+
FailureLimiter = class {
|
|
9
|
+
store;
|
|
10
|
+
clock;
|
|
11
|
+
maxFailures;
|
|
12
|
+
windowMs;
|
|
13
|
+
blockDurationMs;
|
|
14
|
+
burstCoalesceMs;
|
|
15
|
+
constructor(cfg) {
|
|
16
|
+
this.maxFailures = Math.max(1, Math.floor(cfg.maxFailures));
|
|
17
|
+
this.windowMs = Math.max(1e3, Math.floor(cfg.windowMs));
|
|
18
|
+
this.blockDurationMs = Math.max(1e3, Math.floor(cfg.blockDurationMs));
|
|
19
|
+
this.burstCoalesceMs = Math.max(0, Math.floor(cfg.burstCoalesceMs ?? DEFAULT_BURST_COALESCE_MS));
|
|
20
|
+
this.clock = cfg.clock ?? Date.now;
|
|
21
|
+
this.store = new KeyedStore({
|
|
22
|
+
staleAfterMs: cfg.staleAfterMs ?? this.windowMs + this.blockDurationMs,
|
|
23
|
+
clock: this.clock
|
|
24
|
+
});
|
|
50
25
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
26
|
+
check(key) {
|
|
27
|
+
const now = this.clock();
|
|
28
|
+
const state = this.store.get(key);
|
|
29
|
+
if (!state?.blockedUntil) return { blocked: false };
|
|
30
|
+
if (now >= state.blockedUntil) {
|
|
31
|
+
state.blockedUntil = void 0;
|
|
32
|
+
state.count = 0;
|
|
33
|
+
state.windowStart = now;
|
|
34
|
+
state.lastTouchedMs = now;
|
|
35
|
+
return { blocked: false };
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
blocked: true,
|
|
39
|
+
retryAfterSec: Math.max(1, Math.ceil((state.blockedUntil - now) / 1e3))
|
|
64
40
|
};
|
|
65
|
-
this.store.set(key, state);
|
|
66
41
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
state
|
|
71
|
-
|
|
72
|
-
|
|
42
|
+
fail(key) {
|
|
43
|
+
const now = this.clock();
|
|
44
|
+
let state = this.store.get(key);
|
|
45
|
+
if (!state) {
|
|
46
|
+
state = {
|
|
47
|
+
windowStart: now,
|
|
48
|
+
count: 0,
|
|
49
|
+
lastTouchedMs: now
|
|
50
|
+
};
|
|
51
|
+
this.store.set(key, state);
|
|
52
|
+
}
|
|
53
|
+
state.lastTouchedMs = now;
|
|
54
|
+
if (state.blockedUntil && now < state.blockedUntil) return;
|
|
55
|
+
if (state.blockedUntil && now >= state.blockedUntil) {
|
|
56
|
+
state.blockedUntil = void 0;
|
|
57
|
+
state.count = 0;
|
|
58
|
+
state.windowStart = now;
|
|
59
|
+
}
|
|
60
|
+
if (now - state.windowStart > this.windowMs) {
|
|
61
|
+
state.count = 0;
|
|
62
|
+
state.windowStart = now;
|
|
63
|
+
}
|
|
64
|
+
if (state.lastFailureAtMs !== void 0 && now - state.lastFailureAtMs < this.burstCoalesceMs) {
|
|
65
|
+
state.lastFailureAtMs = now;
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
state.lastFailureAtMs = now;
|
|
69
|
+
state.count += 1;
|
|
70
|
+
if (state.count >= this.maxFailures) state.blockedUntil = now + this.blockDurationMs;
|
|
73
71
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
state.windowStart = now;
|
|
72
|
+
succeed(key) {
|
|
73
|
+
this.store.delete(key);
|
|
77
74
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
75
|
+
/** @internal Test hook. */
|
|
76
|
+
resetForTests() {
|
|
77
|
+
this.store.clear();
|
|
78
|
+
}
|
|
79
|
+
destroy() {
|
|
80
|
+
this.store.destroy();
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (state.count >= this.maxFailures) state.blockedUntil = now + this.blockDurationMs;
|
|
85
|
-
}
|
|
86
|
-
succeed(key) {
|
|
87
|
-
this.store.delete(key);
|
|
88
|
-
}
|
|
89
|
-
/** @internal Test hook. */
|
|
90
|
-
resetForTests() {
|
|
91
|
-
this.store.clear();
|
|
92
|
-
}
|
|
93
|
-
destroy() {
|
|
94
|
-
this.store.destroy();
|
|
95
|
-
}
|
|
96
|
-
};
|
|
82
|
+
};
|
|
83
|
+
}));
|
|
97
84
|
//#endregion
|
|
98
|
-
|
|
85
|
+
init_failure_limiter();
|
|
86
|
+
export { FailureLimiter, init_failure_limiter };
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { __esmMin } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { RateLimiter, init_rate_limiter } from "./rate-limiter.js";
|
|
3
|
+
import { FailureLimiter, init_failure_limiter } from "./failure-limiter.js";
|
|
4
|
+
//#region src/infra/rate-limit/index.ts
|
|
5
|
+
var init_rate_limit = __esmMin((() => {
|
|
6
|
+
init_rate_limiter();
|
|
7
|
+
init_failure_limiter();
|
|
8
|
+
}));
|
|
9
|
+
//#endregion
|
|
10
|
+
init_rate_limit();
|
|
11
|
+
export { FailureLimiter, RateLimiter, init_rate_limit };
|
|
@@ -1,49 +1,54 @@
|
|
|
1
|
+
import { __esmMin } from "../../../_virtual/_rolldown/runtime.js";
|
|
1
2
|
//#region src/infra/rate-limit/keyed-store.ts
|
|
2
|
-
var KeyedStore
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this.cleanupTimer
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
3
|
+
var KeyedStore;
|
|
4
|
+
var init_keyed_store = __esmMin((() => {
|
|
5
|
+
KeyedStore = class {
|
|
6
|
+
map = /* @__PURE__ */ new Map();
|
|
7
|
+
maxEntries;
|
|
8
|
+
overflow;
|
|
9
|
+
clock;
|
|
10
|
+
staleAfterMs;
|
|
11
|
+
cleanupTimer;
|
|
12
|
+
constructor(opts) {
|
|
13
|
+
this.maxEntries = Math.max(1, opts.maxEntries ?? 1e4);
|
|
14
|
+
this.clock = opts.clock ?? Date.now;
|
|
15
|
+
this.staleAfterMs = Math.max(1e3, opts.staleAfterMs);
|
|
16
|
+
const interval = Math.min(600 * 1e3, Math.max(1e3, opts.cleanupIntervalMs ?? Math.floor(this.staleAfterMs / 4)));
|
|
17
|
+
this.cleanupTimer = setInterval(() => this.sweep(), interval);
|
|
18
|
+
this.cleanupTimer.unref?.();
|
|
19
|
+
}
|
|
20
|
+
get(key) {
|
|
21
|
+
return this.map.get(key) ?? (this.map.size >= this.maxEntries ? this.overflow : void 0);
|
|
22
|
+
}
|
|
23
|
+
set(key, value) {
|
|
24
|
+
if (this.map.has(key) || this.map.size < this.maxEntries) this.map.set(key, value);
|
|
25
|
+
else this.overflow ??= value;
|
|
26
|
+
}
|
|
27
|
+
delete(key) {
|
|
28
|
+
this.map.delete(key);
|
|
29
|
+
}
|
|
30
|
+
size() {
|
|
31
|
+
return this.map.size;
|
|
32
|
+
}
|
|
33
|
+
clear() {
|
|
34
|
+
this.map.clear();
|
|
35
|
+
this.overflow = void 0;
|
|
36
|
+
}
|
|
37
|
+
destroy() {
|
|
38
|
+
if (this.cleanupTimer) {
|
|
39
|
+
clearInterval(this.cleanupTimer);
|
|
40
|
+
this.cleanupTimer = void 0;
|
|
41
|
+
}
|
|
42
|
+
this.map.clear();
|
|
43
|
+
this.overflow = void 0;
|
|
44
|
+
}
|
|
45
|
+
sweep() {
|
|
46
|
+
const now = this.clock();
|
|
47
|
+
if (this.overflow && now - this.overflow.lastTouchedMs > this.staleAfterMs) this.overflow = void 0;
|
|
48
|
+
for (const [k, v] of this.map.entries()) if (now - v.lastTouchedMs > this.staleAfterMs) this.map.delete(k);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}));
|
|
48
52
|
//#endregion
|
|
49
|
-
|
|
53
|
+
init_keyed_store();
|
|
54
|
+
export { KeyedStore, init_keyed_store };
|
|
@@ -1,63 +1,60 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __esmMin } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { KeyedStore, init_keyed_store } from "./keyed-store.js";
|
|
2
3
|
//#region src/infra/rate-limit/rate-limiter.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
4
|
+
var RateLimiter;
|
|
5
|
+
var init_rate_limiter = __esmMin((() => {
|
|
6
|
+
init_keyed_store();
|
|
7
|
+
RateLimiter = class {
|
|
8
|
+
store;
|
|
9
|
+
clock;
|
|
10
|
+
maxRequests;
|
|
11
|
+
windowMs;
|
|
12
|
+
constructor(cfg) {
|
|
13
|
+
this.maxRequests = Math.max(1, Math.floor(cfg.maxRequests));
|
|
14
|
+
this.windowMs = Math.max(1, Math.floor(cfg.windowMs));
|
|
15
|
+
this.clock = cfg.clock ?? Date.now;
|
|
16
|
+
this.store = new KeyedStore({
|
|
17
|
+
staleAfterMs: cfg.staleAfterMs ?? this.windowMs * 4,
|
|
18
|
+
clock: this.clock
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
consume(key) {
|
|
22
|
+
const now = this.clock();
|
|
23
|
+
let state = this.store.get(key);
|
|
24
|
+
if (!state) {
|
|
25
|
+
state = {
|
|
26
|
+
windowStart: now,
|
|
27
|
+
count: 0,
|
|
28
|
+
lastTouchedMs: now
|
|
29
|
+
};
|
|
30
|
+
this.store.set(key, state);
|
|
31
|
+
}
|
|
32
|
+
if (now - state.windowStart >= this.windowMs) {
|
|
33
|
+
state.windowStart = now;
|
|
34
|
+
state.count = 0;
|
|
35
|
+
}
|
|
36
|
+
state.lastTouchedMs = now;
|
|
37
|
+
if (state.count >= this.maxRequests) return {
|
|
38
|
+
allowed: false,
|
|
39
|
+
remaining: 0,
|
|
40
|
+
retryAfterMs: Math.max(0, state.windowStart + this.windowMs - now)
|
|
41
|
+
};
|
|
42
|
+
state.count += 1;
|
|
43
|
+
return {
|
|
44
|
+
allowed: true,
|
|
45
|
+
remaining: this.maxRequests - state.count,
|
|
46
|
+
retryAfterMs: 0
|
|
34
47
|
};
|
|
35
|
-
this.store.set(key, state);
|
|
36
48
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
49
|
+
/** @internal Test hook. */
|
|
50
|
+
resetForTests() {
|
|
51
|
+
this.store.clear();
|
|
52
|
+
}
|
|
53
|
+
destroy() {
|
|
54
|
+
this.store.destroy();
|
|
40
55
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
allowed: false,
|
|
44
|
-
remaining: 0,
|
|
45
|
-
retryAfterMs: Math.max(0, state.windowStart + this.windowMs - now)
|
|
46
|
-
};
|
|
47
|
-
state.count += 1;
|
|
48
|
-
return {
|
|
49
|
-
allowed: true,
|
|
50
|
-
remaining: this.maxRequests - state.count,
|
|
51
|
-
retryAfterMs: 0
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
/** @internal Test hook. */
|
|
55
|
-
resetForTests() {
|
|
56
|
-
this.store.clear();
|
|
57
|
-
}
|
|
58
|
-
destroy() {
|
|
59
|
-
this.store.destroy();
|
|
60
|
-
}
|
|
61
|
-
};
|
|
56
|
+
};
|
|
57
|
+
}));
|
|
62
58
|
//#endregion
|
|
63
|
-
|
|
59
|
+
init_rate_limiter();
|
|
60
|
+
export { RateLimiter, init_rate_limiter };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createLogger } from "../utils/logger/index.js";
|
|
2
2
|
import { init_logger } from "../utils/logger.js";
|
|
3
|
-
import { SERVICE_VERSION_ENV_KEY, formatGatewayServiceDescription } from "../daemon/constants.js";
|
|
3
|
+
import { SERVICE_VERSION_ENV_KEY, formatGatewayServiceDescription, init_constants } from "../daemon/constants.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import fs from "node:fs/promises";
|
|
6
6
|
//#region src/infra/update-service-refresh.ts
|
|
7
|
+
init_constants();
|
|
7
8
|
init_logger();
|
|
8
9
|
const log = createLogger("UpdateServiceRefresh");
|
|
9
10
|
function resolveBinPath(bin) {
|