@xopcai/xopc 0.0.373 → 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/{agent-avatar-dicebear--kDkSTqC.js → agent-avatar-dicebear-BrA20N2m.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-defaults-settings-panel-z4_2-Kn2.js → agent-defaults-settings-panel-BZrOdxou.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-plugin-dialog-BYndK83K.js → agent-plugin-dialog-B3ux1AhY.js} +1 -1
- package/dist/gateway/static/root/assets/{agents-CVo96cx1.js → agents-CXlXFU6M.js} +3 -3
- package/dist/gateway/static/root/assets/{app-management-settings-panel-D9oOJKiH.js → app-management-settings-panel-BXahEVPm.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-B0-8Cdyv.js → appearance-settings-CE2qJMkD.js} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-DasVc6i4.js → apps-page-DGVOnCxZ.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-BlCNqy2i.js → automations-page-BWL7eT4_.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-workspace-C8ipDP05.js → automations-workspace-BxIShhkZ.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-Cktlez6g.js → block-editor-3n446-mX.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-automations-page-KRfDl8ej.js → browser-automations-page-BmTK7Gtn.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-settings-page-BraQ4wnh.js → browser-settings-page-DBQ-WETQ.js} +1 -1
- package/dist/gateway/static/root/assets/{capabilities-page-B3m8xGzd.js → capabilities-page-D-nQ6Zzi.js} +2 -2
- package/dist/gateway/static/root/assets/{capabilities-settings-panel-VQ4fHuBV.js → capabilities-settings-panel-Dx1fpBmH.js} +1 -1
- package/dist/gateway/static/root/assets/{capability-header-actions-f5Ido4Eg.js → capability-header-actions-BRMqvQVb.js} +1 -1
- package/dist/gateway/static/root/assets/{channels-N4Vc2nEG.js → channels-DXfEP1FR.js} +1 -1
- package/dist/gateway/static/root/assets/{chat-terminal-dock-BwvTKwsn.js → chat-terminal-dock-BRdzCjWO.js} +1 -1
- package/dist/gateway/static/root/assets/{computer-settings-page-CAwUsKpw.js → computer-settings-page-BhCHMRpD.js} +1 -1
- package/dist/gateway/static/root/assets/{connector-service-page-C0HuAMuH.js → connector-service-page-BXE8Z-Ll.js} +1 -1
- package/dist/gateway/static/root/assets/{connectors-page-BcBmW8JT.js → connectors-page-D9RZjhw8.js} +1 -1
- package/dist/gateway/static/root/assets/{date-picker-DiQxRpe-.js → date-picker-BJ7N92wm.js} +1 -1
- package/dist/gateway/static/root/assets/{dependency-picker-Ds0_BJbN.js → dependency-picker-gyxCM-hb.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-ZMEOYwrR.js → desktop-pet-B-WM4l-L.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-DkyTqD07.js → desktop-pet-settings-usJqcew5.js} +1 -1
- package/dist/gateway/static/root/assets/{device-pairing-wizard-CvaI5ZJZ.js → device-pairing-wizard-DoSR4DGk.js} +1 -1
- package/dist/gateway/static/root/assets/{directory-picker-path-field-Bfv93eK1.js → directory-picker-path-field-DqVlV2YH.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-JXKGtIdM.js → extension-page-CUule9SU.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-lsQ2xvbr.js → extension-settings-page-_OFukkEJ.js} +1 -1
- package/dist/gateway/static/root/assets/{fallback-models-7bG0AND1.js → fallback-models-CiSc3h8i.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-settings-BpbcoPx9.js → gateway-settings-qSUrpS1h.js} +1 -1
- package/dist/gateway/static/root/assets/{home-page-BxctC0aJ.js → home-page-COjDsuzg.js} +1 -1
- package/dist/gateway/static/root/assets/{imports-page-Bq8CazCb.js → imports-page-DdvIj-ZL.js} +1 -1
- package/dist/gateway/static/root/assets/{index-B40-KDN8.js → index-DEaVabvo.js} +6 -6
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-kkAevkl2.js → keyboard-shortcuts-settings-DbqFlNsF.js} +1 -1
- package/dist/gateway/static/root/assets/{local-app-workbench-page-abLaf1hW.js → local-app-workbench-page-REowUzkp.js} +1 -1
- package/dist/gateway/static/root/assets/{local-apps-page-nwsnwYjK.js → local-apps-page-DdCMNn_z.js} +1 -1
- package/dist/gateway/static/root/assets/{logs-page-BEgYS-Xg.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/{note-detail-panel-CCnfurBR.js → note-detail-panel-B7U6EbAi.js} +3 -3
- package/dist/gateway/static/root/assets/{notes-page-D9u_znxM.js → notes-page-BzHVaH8j.js} +1 -1
- package/dist/gateway/static/root/assets/{page-context-capture-button-BO3FoRej.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-Dso2_hyl.js → product-open-page-CK_czbBx.js} +1 -1
- package/dist/gateway/static/root/assets/{product-preview-content-CkvVb3EA.js → product-preview-content-CU6KlaVP.js} +1 -1
- package/dist/gateway/static/root/assets/{project-detail-page-UjrrzE3H.js → project-detail-page-c3ye2bdq.js} +1 -1
- package/dist/gateway/static/root/assets/{projects-page-C1h63P2M.js → projects-page-BA1UuuRF.js} +1 -1
- package/dist/gateway/static/root/assets/{remote-access-hub-BJifH8AB.js → remote-access-hub-D_FLVZAm.js} +1 -1
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-vG1wqcEb.js → runtime-tools-settings-panel-Cxjmwdyf.js} +1 -1
- package/dist/gateway/static/root/assets/{scenes-page-CwoAoYMX.js → scenes-page-Av47PHdM.js} +1 -1
- package/dist/gateway/static/root/assets/{schema-form-BIsHdyz7.js → schema-form-IM7QeSm3.js} +1 -1
- package/dist/gateway/static/root/assets/{sessions-page-BcCLp3yU.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-z9Jlk0BL.js → settings-page-BeVtwwVd.js} +1 -1
- package/dist/gateway/static/root/assets/{setup-status-panel-CrpXECqe.js → setup-status-panel-zTmrMwMm.js} +1 -1
- package/dist/gateway/static/root/assets/{shares-settings-D9XpTJXP.js → shares-settings-Bkhkt_6M.js} +1 -1
- package/dist/gateway/static/root/assets/{skill-api-DtPOf1aW.js → skill-api-Dgwc707w.js} +1 -1
- package/dist/gateway/static/root/assets/{skills-page-Bq9-2b9U.js → skills-page-CFIte-vM.js} +1 -1
- package/dist/gateway/static/root/assets/{system-settings-panel-P7T729uD.js → system-settings-panel-Ck6zGDHb.js} +1 -1
- package/dist/gateway/static/root/assets/{task-detail-page-CsB9AFx6.js → task-detail-page-C3ZPEZqw.js} +1 -1
- package/dist/gateway/static/root/assets/{tunnel-api-CuowqIZ7.js → tunnel-api-CjxMpAm2.js} +1 -1
- package/dist/gateway/static/root/assets/{usage-page-avX3msoZ.js → usage-page-Dnhp9xQ4.js} +1 -1
- package/dist/gateway/static/root/assets/{user-model-page-DGDBWw7P.js → user-model-page-sx1lNWKf.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-overlay-BgJNz2tH.js → work-discovery-overlay-CVd_y3K2.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-1I2q2J_U.js → workflow-run-setup-panel-Dwg40uGK.js} +1 -1
- package/dist/gateway/static/root/assets/{workflows-page-DhJl9pnO.js → workflows-page-BQR4JdXB.js} +1 -1
- package/dist/gateway/static/root/assets/{xopc-cloud-account-card-CnPBP1V_.js → xopc-cloud-account-card-CaKc_J7j.js} +1 -1
- package/dist/gateway/static/root/index.html +1 -1
- package/dist/package.js +1 -1
- package/dist/packages/realtime-protocol/src/voice.js +11 -0
- package/dist/src/agent/agent-manager.js +4 -4
- package/dist/src/agent/background-review/run-background-review.js +1 -1
- package/dist/src/agent/embedded/model-runtime.js +1 -1
- package/dist/src/agent/embedded/run-for-session.js +2 -2
- package/dist/src/agent/embedded/run-turn.js +2 -2
- package/dist/src/agent/image/tool-model-config.js +1 -1
- package/dist/src/agent/service.js +3 -3
- package/dist/src/agent/session/session-inspector.js +1 -1
- package/dist/src/agent/tasks/task-judge-service.js +3 -3
- package/dist/src/agent-config/schema.d.ts +9 -0
- package/dist/src/agent-config/schema.js +1 -0
- package/dist/src/ai-assist/text-assist.js +1 -1
- package/dist/src/auth/credentials.js +2 -2
- package/dist/src/auth/model-credential-store.js +1 -1
- package/dist/src/auth/sync-provider-auth.js +1 -1
- package/dist/src/chat-commands/builtins/config.js +1 -1
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/cli/commands/doctor/checks/image-providers.js +1 -1
- package/dist/src/cli/commands/doctor/checks/provider-auth.js +1 -1
- package/dist/src/cli/commands/gateway/shared.js +2 -1
- package/dist/src/cli/commands/models.js +1 -1
- package/dist/src/cli/commands/onboard/model.js +3 -3
- package/dist/src/computer/runtime.js +1 -1
- package/dist/src/config/gateway-bind.js +2 -1
- package/dist/src/config/index.js +5 -5
- package/dist/src/config/loader.js +1 -1
- package/dist/src/config/models-json.d.ts +8 -8
- package/dist/src/config/models-json.js +2 -2
- 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/extensions/activation-context.js +1 -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.js +2 -2
- 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-patch/misc.js +1 -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 +3 -3
- package/dist/src/gateway/hono/routes/observability.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/voice.js +2 -1
- 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/config-coordinator.js +1 -1
- package/dist/src/gateway/service/session-command-service.js +1 -1
- package/dist/src/gateway/service.js +12 -10
- package/dist/src/gateway/tailscale-auth.js +2 -1
- package/dist/src/gateway/ws-security.js +2 -1
- package/dist/src/home-intelligence/generator.js +1 -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/notes/service.js +1 -1
- package/dist/src/observability/runtime.js +1 -1
- package/dist/src/personal-agent/proactivity/service.js +2 -2
- package/dist/src/personal-agent/reply-composer.js +2 -2
- 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 +1 -1
- package/dist/src/platform/contracts.d.ts +1 -1
- package/dist/src/platform/index.js +1 -1
- package/dist/src/providers/index.js +4 -4
- package/dist/src/providers/model-registry.js +2 -2
- package/dist/src/providers/provider-auth-service.js +1 -1
- package/dist/src/providers/provider-disconnect-core.js +1 -1
- package/dist/src/providers/register-runtime-providers.js +1 -1
- package/dist/src/providers/xopc-cloud-catalog-coordinator.js +1 -1
- 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/device-access-repository.d.ts +7 -0
- package/dist/src/storage/sqlite/device-access-repository.js +22 -4
- 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/tasks/task-main-update-decision-service.js +2 -2
- package/dist/src/tui/backends/embedded-backend.js +1 -1
- package/dist/src/tui/tui.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/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 +90 -1
- package/dist/src/voice/realtime/runtime.types.d.ts +4 -0
- package/dist/src/work-discovery/service.js +2 -2
- package/dist/src/workflows/service/workflow-run-service.js +1 -1
- package/package.json +3 -3
- package/dist/gateway/static/root/assets/management-settings-D_JQ6_X0.js +0 -1
- package/dist/gateway/static/root/assets/personal-page-BJn6UHAF.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-D114UdRI.js +0 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import type { DeviceRecord } from '../../storage/sqlite/device-access-repository.js';
|
|
3
|
+
export declare const REQUEST_PROOF_WINDOW_MS = 120000;
|
|
4
|
+
export declare const PROOF_HEADER = "X-Xopc-Proof";
|
|
5
|
+
export declare const SIGNED_REQUEST_HEADERS: readonly ["content-type", "idempotency-key", "x-xopc-expected-session-key", "x-endpoint-id", "x-endpoint-upload-token"];
|
|
6
|
+
/** Bounds buffered uploads through route completion, after signature verification. */
|
|
7
|
+
export declare function acquireProofBodyBudget(deviceId: string): (() => void) | undefined;
|
|
8
|
+
export declare function proofDigest(bytes: crypto.BinaryLike): string;
|
|
9
|
+
export interface RequestProof {
|
|
10
|
+
timestamp: number;
|
|
11
|
+
nonce: string;
|
|
12
|
+
digest: string;
|
|
13
|
+
signature: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function parseRequestProof(header: string | undefined): RequestProof | undefined;
|
|
16
|
+
export declare function requestProofMessage(input: {
|
|
17
|
+
gatewayId: string;
|
|
18
|
+
credential: string;
|
|
19
|
+
method: string;
|
|
20
|
+
target: string;
|
|
21
|
+
headers: (name: string) => string | undefined;
|
|
22
|
+
proof: Pick<RequestProof, 'timestamp' | 'nonce' | 'digest'>;
|
|
23
|
+
}): string;
|
|
24
|
+
export declare function verifyRequestProofSignature(device: DeviceRecord, proof: RequestProof, message: string): boolean;
|
|
25
|
+
/** The unique insert happens before business effects; expiry includes future-dated proofs. */
|
|
26
|
+
export declare function consumeRequestNonce(deviceId: string, proof: RequestProof, now?: number): boolean;
|
|
27
|
+
/** Native WebSocket upgrades bind the first ticket to the device key without another round trip. */
|
|
28
|
+
export declare function verifyDeviceConnectionProof(principalId: string, ticket: string, path: string, header: string | undefined): boolean;
|
|
@@ -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 };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createLogger } from "../../utils/logger/index.js";
|
|
2
2
|
import { init_logger } from "../../utils/logger.js";
|
|
3
|
+
import { configureTracing } from "../../observability/runtime.js";
|
|
3
4
|
import { getModelRegistry } from "../../providers/model-registry.js";
|
|
4
5
|
import { init_providers } from "../../providers/index.js";
|
|
5
|
-
import { configureTracing } from "../../observability/runtime.js";
|
|
6
6
|
import { evictAllEmbeddedSessionRunners } from "../../agent/embedded/session-runner.js";
|
|
7
7
|
import { reloadImageGenerationProviders } from "../../agent/image/generation/provider-registry.js";
|
|
8
8
|
import { loadConfig, saveConfig } from "../../config/loader.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getSessionMetadata } from "../../storage/sqlite/session-read-repository.js";
|
|
2
2
|
import { init_session_repository } from "../../storage/sqlite/session-repository.js";
|
|
3
|
-
import { init_providers, resolveModel } from "../../providers/index.js";
|
|
4
3
|
import { resolveEffectiveAgentConfigForAgent, resolveEffectiveAgentConfigForSession } from "../../config/agent-profile.js";
|
|
4
|
+
import { init_providers, resolveModel } from "../../providers/index.js";
|
|
5
5
|
import { getPersonalAgentByConversation } from "../../personal-agent/repository.js";
|
|
6
6
|
import { resolveProjectAgentId } from "../../projects/project-agent.js";
|
|
7
7
|
import "../../projects/index.js";
|
|
@@ -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";
|
|
@@ -18,17 +22,17 @@ import { getSessionConfig, init_config_repository } from "../storage/sqlite/conf
|
|
|
18
22
|
import { init_sqlite } from "../storage/sqlite/index.js";
|
|
19
23
|
import { normalizeAgentId } from "../agent-catalog/id.js";
|
|
20
24
|
import { init_agent_scope, listAgentEntries, resolveAgentWorkspaceDir, resolveDefaultAgentId } from "../agent/agent-scope.js";
|
|
25
|
+
import { init_paths, resolveConfigPath, resolveExtensionsDir } from "../config/paths.js";
|
|
26
|
+
import { flushTracing } from "../observability/runtime.js";
|
|
21
27
|
import { init_config, resolveKnowledgeReadPolicy } from "../user-context/config.js";
|
|
22
28
|
import { getAgentDefaultModelRef, init_schema } from "../config/schema.js";
|
|
23
|
-
import { init_paths, resolveConfigPath, resolveExtensionsDir } from "../config/paths.js";
|
|
24
|
-
import { prewarmModelRegistry } from "../providers/model-registry.js";
|
|
25
29
|
import { init_agent_session_key, resolveAgentMainConversationId } from "../routing/agent-session-key.js";
|
|
26
30
|
import { init_session_key, resolveConversationId, sanitizeSegment } from "../routing/session-key.js";
|
|
27
31
|
import { getDefaultAgentId, init_resolve_route } from "../routing/resolve-route.js";
|
|
32
|
+
import { resolveEffectiveAgentProfileForSession } from "../config/agent-profile.js";
|
|
33
|
+
import { prewarmModelRegistry } from "../providers/model-registry.js";
|
|
28
34
|
import { init_providers, providers_exports } from "../providers/index.js";
|
|
29
|
-
import { flushTracing } from "../observability/runtime.js";
|
|
30
35
|
import { AI_USAGE_RETENTION_MS, markStaleAiUsageEventsUnknown, pruneAiUsageEvents } from "../storage/sqlite/ai-usage-repository.js";
|
|
31
|
-
import { resolveEffectiveAgentProfileForSession } from "../config/agent-profile.js";
|
|
32
36
|
import { listKnowledgeItems } from "../knowledge-memory/repository.js";
|
|
33
37
|
import "../knowledge-memory/index.js";
|
|
34
38
|
import { getPersonalAgentByConversation } from "../personal-agent/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,7 +1,7 @@
|
|
|
1
1
|
import { init_agent_scope, resolveDefaultAgentId } from "../agent/agent-scope.js";
|
|
2
|
-
import { extractAssistantText, getAssistantMessageErrorReason } from "../providers/model-response.js";
|
|
3
2
|
import { init_providers, resolveModel } from "../providers/index.js";
|
|
4
3
|
import { completeWithResolvedCredentials, isLocalModelBaseUrl } from "../providers/model-call.js";
|
|
4
|
+
import { extractAssistantText, getAssistantMessageErrorReason } from "../providers/model-response.js";
|
|
5
5
|
import { resolveModelSelector } from "../config/agent-model-intents.js";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
//#region src/home-intelligence/generator.ts
|
|
@@ -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 };
|