qarpeo 0.0.0-alpha.10
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/LICENSE +21 -0
- package/README.md +102 -0
- package/dist/chunks/auth-schema.mjs +219 -0
- package/dist/chunks/wrangler.mjs +783 -0
- package/dist/cli/index.mjs +1085 -0
- package/dist/dev/env.d.ts +12 -0
- package/dist/dev/wrangler.d.ts +18 -0
- package/dist/module.d.ts +16 -0
- package/dist/module.mjs +4436 -0
- package/dist/runtime/ai.d.ts +25 -0
- package/dist/runtime/ai.mjs +106 -0
- package/dist/runtime/analytics.d.ts +24 -0
- package/dist/runtime/analytics.mjs +38 -0
- package/dist/runtime/app/components/BlobImage.vue +100 -0
- package/dist/runtime/app/components/CMSBlocks.vue +93 -0
- package/dist/runtime/app/components/CMSContent.vue +23 -0
- package/dist/runtime/app/components/CMSImage.vue +49 -0
- package/dist/runtime/app/components/CMSLocaleSwitcher.vue +110 -0
- package/dist/runtime/app/components/CMSPreviewBanner.vue +79 -0
- package/dist/runtime/app/components/CMSVersionBanner.vue +49 -0
- package/dist/runtime/app/components/CMSVersionSwitcher.vue +126 -0
- package/dist/runtime/app/components/ContentRenderer.vue +80 -0
- package/dist/runtime/app/components/FileUpload.vue +196 -0
- package/dist/runtime/app/components/ImpersonationBanner.vue +57 -0
- package/dist/runtime/app/components/SignedIn.vue +13 -0
- package/dist/runtime/app/components/SignedOut.vue +13 -0
- package/dist/runtime/app/components/shiki.css +34 -0
- package/dist/runtime/app/composables/analytics.d.ts +125 -0
- package/dist/runtime/app/composables/analytics.mjs +81 -0
- package/dist/runtime/app/composables/api-tokens.d.ts +49 -0
- package/dist/runtime/app/composables/api-tokens.mjs +61 -0
- package/dist/runtime/app/composables/auth.d.ts +50 -0
- package/dist/runtime/app/composables/auth.mjs +101 -0
- package/dist/runtime/app/composables/chat.d.ts +69 -0
- package/dist/runtime/app/composables/chat.mjs +159 -0
- package/dist/runtime/app/composables/cms-preview.d.ts +33 -0
- package/dist/runtime/app/composables/cms-preview.mjs +83 -0
- package/dist/runtime/app/composables/cms.d.ts +307 -0
- package/dist/runtime/app/composables/cms.mjs +355 -0
- package/dist/runtime/app/composables/docs-version.d.ts +35 -0
- package/dist/runtime/app/composables/docs-version.mjs +70 -0
- package/dist/runtime/app/composables/impersonation.d.ts +14 -0
- package/dist/runtime/app/composables/impersonation.mjs +44 -0
- package/dist/runtime/app/composables/notifications.d.ts +35 -0
- package/dist/runtime/app/composables/notifications.mjs +139 -0
- package/dist/runtime/app/composables/organization.d.ts +127 -0
- package/dist/runtime/app/composables/organization.mjs +138 -0
- package/dist/runtime/app/composables/passkey.d.ts +6 -0
- package/dist/runtime/app/composables/passkey.mjs +105 -0
- package/dist/runtime/app/composables/passwordless.d.ts +7 -0
- package/dist/runtime/app/composables/passwordless.mjs +67 -0
- package/dist/runtime/app/composables/payments.d.ts +43 -0
- package/dist/runtime/app/composables/payments.mjs +74 -0
- package/dist/runtime/app/composables/realtime.d.ts +96 -0
- package/dist/runtime/app/composables/realtime.mjs +432 -0
- package/dist/runtime/app/composables/site.d.ts +35 -0
- package/dist/runtime/app/composables/site.mjs +36 -0
- package/dist/runtime/app/composables/storage.d.ts +60 -0
- package/dist/runtime/app/composables/storage.mjs +294 -0
- package/dist/runtime/app/composables/tenant.d.ts +82 -0
- package/dist/runtime/app/composables/tenant.mjs +120 -0
- package/dist/runtime/app/composables/turnstile.d.ts +3 -0
- package/dist/runtime/app/composables/turnstile.mjs +10 -0
- package/dist/runtime/app/composables/two-factor.d.ts +12 -0
- package/dist/runtime/app/composables/two-factor.mjs +65 -0
- package/dist/runtime/app/middleware/auth.global.d.ts +2 -0
- package/dist/runtime/app/middleware/auth.global.mjs +44 -0
- package/dist/runtime/app/pages/cms.vue +2249 -0
- package/dist/runtime/app/pages/devtools/agents.vue +717 -0
- package/dist/runtime/app/pages/devtools/analytics.vue +618 -0
- package/dist/runtime/app/pages/devtools/auth.vue +351 -0
- package/dist/runtime/app/pages/devtools/blob.vue +745 -0
- package/dist/runtime/app/pages/devtools/db.vue +546 -0
- package/dist/runtime/app/pages/devtools/domains.vue +772 -0
- package/dist/runtime/app/pages/devtools/kv.vue +829 -0
- package/dist/runtime/app/pages/devtools/logs.vue +655 -0
- package/dist/runtime/app/pages/devtools/mail.vue +389 -0
- package/dist/runtime/app/pages/devtools/overview.vue +390 -0
- package/dist/runtime/app/pages/devtools/settings.vue +560 -0
- package/dist/runtime/app/pages/devtools.vue +165 -0
- package/dist/runtime/app/plugins/seo.d.ts +2 -0
- package/dist/runtime/app/plugins/seo.mjs +105 -0
- package/dist/runtime/app/plugins/shortcuts.client.d.ts +6 -0
- package/dist/runtime/app/plugins/shortcuts.client.mjs +19 -0
- package/dist/runtime/app/public/sw-notifications.mjs +52 -0
- package/dist/runtime/auth.d.ts +25 -0
- package/dist/runtime/auth.mjs +11 -0
- package/dist/runtime/bindings.d.ts +27 -0
- package/dist/runtime/bindings.mjs +38 -0
- package/dist/runtime/blob.d.ts +26 -0
- package/dist/runtime/blob.mjs +334 -0
- package/dist/runtime/bots.d.ts +1 -0
- package/dist/runtime/bots.mjs +1 -0
- package/dist/runtime/browser.d.ts +21 -0
- package/dist/runtime/browser.mjs +64 -0
- package/dist/runtime/cache.d.ts +19 -0
- package/dist/runtime/cache.mjs +12 -0
- package/dist/runtime/cms.d.ts +2 -0
- package/dist/runtime/cms.mjs +0 -0
- package/dist/runtime/db.d.ts +21 -0
- package/dist/runtime/db.mjs +36 -0
- package/dist/runtime/drizzle.d.ts +11 -0
- package/dist/runtime/drizzle.mjs +18 -0
- package/dist/runtime/email.d.ts +51 -0
- package/dist/runtime/email.mjs +245 -0
- package/dist/runtime/hyperdrive.d.ts +21 -0
- package/dist/runtime/hyperdrive.mjs +49 -0
- package/dist/runtime/index.d.ts +23 -0
- package/dist/runtime/index.mjs +23 -0
- package/dist/runtime/kv.d.ts +16 -0
- package/dist/runtime/kv.mjs +126 -0
- package/dist/runtime/payments.d.ts +2 -0
- package/dist/runtime/payments.mjs +0 -0
- package/dist/runtime/queue.d.ts +21 -0
- package/dist/runtime/queue.mjs +41 -0
- package/dist/runtime/rag.d.ts +1 -0
- package/dist/runtime/rag.mjs +1 -0
- package/dist/runtime/ratelimit.d.ts +21 -0
- package/dist/runtime/ratelimit.mjs +38 -0
- package/dist/runtime/realtime.d.ts +6 -0
- package/dist/runtime/realtime.mjs +13 -0
- package/dist/runtime/server/db/cms-schema.d.ts +651 -0
- package/dist/runtime/server/db/cms-schema.mjs +74 -0
- package/dist/runtime/server/durable-objects/agent.d.ts +14 -0
- package/dist/runtime/server/durable-objects/agent.mjs +571 -0
- package/dist/runtime/server/durable-objects/room.d.ts +34 -0
- package/dist/runtime/server/durable-objects/room.mjs +514 -0
- package/dist/runtime/server/middleware/auth.d.ts +2 -0
- package/dist/runtime/server/middleware/auth.mjs +108 -0
- package/dist/runtime/server/middleware/devtools.d.ts +2 -0
- package/dist/runtime/server/middleware/devtools.mjs +61 -0
- package/dist/runtime/server/middleware/ratelimit.d.ts +2 -0
- package/dist/runtime/server/middleware/ratelimit.mjs +49 -0
- package/dist/runtime/server/middleware/tenancy.d.ts +6 -0
- package/dist/runtime/server/middleware/tenancy.mjs +15 -0
- package/dist/runtime/server/middleware/tracker.d.ts +7 -0
- package/dist/runtime/server/middleware/tracker.mjs +9 -0
- package/dist/runtime/server/plugins/agents.d.ts +7 -0
- package/dist/runtime/server/plugins/agents.mjs +3 -0
- package/dist/runtime/server/plugins/cms.d.ts +7 -0
- package/dist/runtime/server/plugins/cms.mjs +16 -0
- package/dist/runtime/server/plugins/dev-logs.d.ts +1 -0
- package/dist/runtime/server/plugins/dev-logs.mjs +58 -0
- package/dist/runtime/server/plugins/dev-proxy.d.ts +3 -0
- package/dist/runtime/server/plugins/dev-proxy.mjs +21 -0
- package/dist/runtime/server/plugins/env.d.ts +6 -0
- package/dist/runtime/server/plugins/env.mjs +17 -0
- package/dist/runtime/server/plugins/queue.d.ts +6 -0
- package/dist/runtime/server/plugins/queue.mjs +8 -0
- package/dist/runtime/server/routes/__qarpeo/agents/chat.post.d.ts +20 -0
- package/dist/runtime/server/routes/__qarpeo/agents/chat.post.mjs +110 -0
- package/dist/runtime/server/routes/__qarpeo/agents/clear.post.d.ts +7 -0
- package/dist/runtime/server/routes/__qarpeo/agents/clear.post.mjs +15 -0
- package/dist/runtime/server/routes/__qarpeo/agents/create.post.d.ts +17 -0
- package/dist/runtime/server/routes/__qarpeo/agents/create.post.mjs +47 -0
- package/dist/runtime/server/routes/__qarpeo/agents/history.get.d.ts +15 -0
- package/dist/runtime/server/routes/__qarpeo/agents/history.get.mjs +24 -0
- package/dist/runtime/server/routes/__qarpeo/agents/list.get.d.ts +5 -0
- package/dist/runtime/server/routes/__qarpeo/agents/list.get.mjs +63 -0
- package/dist/runtime/server/routes/__qarpeo/analytics/events.get.d.ts +64 -0
- package/dist/runtime/server/routes/__qarpeo/analytics/events.get.mjs +55 -0
- package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.d.ts +30 -0
- package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.mjs +73 -0
- package/dist/runtime/server/routes/__qarpeo/auth/revoke-session.post.d.ts +6 -0
- package/dist/runtime/server/routes/__qarpeo/auth/revoke-session.post.mjs +26 -0
- package/dist/runtime/server/routes/__qarpeo/auth/sessions.get.d.ts +6 -0
- package/dist/runtime/server/routes/__qarpeo/auth/sessions.get.mjs +46 -0
- package/dist/runtime/server/routes/__qarpeo/auth/users.get.d.ts +7 -0
- package/dist/runtime/server/routes/__qarpeo/auth/users.get.mjs +65 -0
- package/dist/runtime/server/routes/__qarpeo/blob/files.get.d.ts +22 -0
- package/dist/runtime/server/routes/__qarpeo/blob/files.get.mjs +36 -0
- package/dist/runtime/server/routes/__qarpeo/db/query.post.d.ts +23 -0
- package/dist/runtime/server/routes/__qarpeo/db/query.post.mjs +34 -0
- package/dist/runtime/server/routes/__qarpeo/db/tables.get.d.ts +31 -0
- package/dist/runtime/server/routes/__qarpeo/db/tables.get.mjs +81 -0
- package/dist/runtime/server/routes/__qarpeo/kv/delete.post.d.ts +11 -0
- package/dist/runtime/server/routes/__qarpeo/kv/delete.post.mjs +18 -0
- package/dist/runtime/server/routes/__qarpeo/kv/get.get.d.ts +11 -0
- package/dist/runtime/server/routes/__qarpeo/kv/get.get.mjs +20 -0
- package/dist/runtime/server/routes/__qarpeo/kv/keys.get.d.ts +8 -0
- package/dist/runtime/server/routes/__qarpeo/kv/keys.get.mjs +27 -0
- package/dist/runtime/server/routes/__qarpeo/kv/set.post.d.ts +14 -0
- package/dist/runtime/server/routes/__qarpeo/kv/set.post.mjs +24 -0
- package/dist/runtime/server/routes/__qarpeo/logs.delete.d.ts +5 -0
- package/dist/runtime/server/routes/__qarpeo/logs.delete.mjs +6 -0
- package/dist/runtime/server/routes/__qarpeo/logs.get.d.ts +5 -0
- package/dist/runtime/server/routes/__qarpeo/logs.get.mjs +26 -0
- package/dist/runtime/server/routes/__qarpeo/logs.post.d.ts +6 -0
- package/dist/runtime/server/routes/__qarpeo/logs.post.mjs +17 -0
- package/dist/runtime/server/routes/__qarpeo/mail/bounce.post.d.ts +5 -0
- package/dist/runtime/server/routes/__qarpeo/mail/bounce.post.mjs +37 -0
- package/dist/runtime/server/routes/__qarpeo/mail/clear.post.d.ts +4 -0
- package/dist/runtime/server/routes/__qarpeo/mail/clear.post.mjs +6 -0
- package/dist/runtime/server/routes/__qarpeo/mail/inbox.get.d.ts +5 -0
- package/dist/runtime/server/routes/__qarpeo/mail/inbox.get.mjs +7 -0
- package/dist/runtime/server/routes/__qarpeo/mail/send-test.post.d.ts +4 -0
- package/dist/runtime/server/routes/__qarpeo/mail/send-test.post.mjs +29 -0
- package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.d.ts +2 -0
- package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +23 -0
- package/dist/runtime/server/routes/__qarpeo/mail/track/open/[id].get.d.ts +2 -0
- package/dist/runtime/server/routes/__qarpeo/mail/track/open/[id].get.mjs +31 -0
- package/dist/runtime/server/routes/__qarpeo/overview/health.get.d.ts +8 -0
- package/dist/runtime/server/routes/__qarpeo/overview/health.get.mjs +46 -0
- package/dist/runtime/server/routes/__qarpeo/overview.get.d.ts +32 -0
- package/dist/runtime/server/routes/__qarpeo/overview.get.mjs +38 -0
- package/dist/runtime/server/routes/__qarpeo/settings/reset-dev-data.post.d.ts +11 -0
- package/dist/runtime/server/routes/__qarpeo/settings/reset-dev-data.post.mjs +84 -0
- package/dist/runtime/server/routes/__qarpeo/settings.get.d.ts +124 -0
- package/dist/runtime/server/routes/__qarpeo/settings.get.mjs +145 -0
- package/dist/runtime/server/routes/__qarpeo/tenants/create.post.d.ts +7 -0
- package/dist/runtime/server/routes/__qarpeo/tenants/create.post.mjs +26 -0
- package/dist/runtime/server/routes/__qarpeo/tenants/domain-add.post.d.ts +6 -0
- package/dist/runtime/server/routes/__qarpeo/tenants/domain-add.post.mjs +29 -0
- package/dist/runtime/server/routes/__qarpeo/tenants/domain-delete.post.d.ts +7 -0
- package/dist/runtime/server/routes/__qarpeo/tenants/domain-delete.post.mjs +21 -0
- package/dist/runtime/server/routes/__qarpeo/tenants/domain-verify.post.d.ts +9 -0
- package/dist/runtime/server/routes/__qarpeo/tenants/domain-verify.post.mjs +21 -0
- package/dist/runtime/server/routes/__qarpeo/tenants/list.get.d.ts +15 -0
- package/dist/runtime/server/routes/__qarpeo/tenants/list.get.mjs +22 -0
- package/dist/runtime/server/routes/agents/[agent]/chat.post.d.ts +2 -0
- package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +35 -0
- package/dist/runtime/server/routes/agents/[agent]/clear.post.d.ts +4 -0
- package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +27 -0
- package/dist/runtime/server/routes/agents/[agent]/history.get.d.ts +4 -0
- package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +27 -0
- package/dist/runtime/server/routes/analytics/events.get.d.ts +3 -0
- package/dist/runtime/server/routes/analytics/events.get.mjs +17 -0
- package/dist/runtime/server/routes/analytics/pageviews.get.d.ts +3 -0
- package/dist/runtime/server/routes/analytics/pageviews.get.mjs +15 -0
- package/dist/runtime/server/routes/analytics/summary.get.d.ts +6 -0
- package/dist/runtime/server/routes/analytics/summary.get.mjs +15 -0
- package/dist/runtime/server/routes/atom.xml.get.d.ts +2 -0
- package/dist/runtime/server/routes/atom.xml.get.mjs +76 -0
- package/dist/runtime/server/routes/auth/2fa/disable.post.d.ts +4 -0
- package/dist/runtime/server/routes/auth/2fa/disable.post.mjs +44 -0
- package/dist/runtime/server/routes/auth/2fa/setup.post.d.ts +6 -0
- package/dist/runtime/server/routes/auth/2fa/setup.post.mjs +32 -0
- package/dist/runtime/server/routes/auth/2fa/verify.post.d.ts +6 -0
- package/dist/runtime/server/routes/auth/2fa/verify.post.mjs +92 -0
- package/dist/runtime/server/routes/auth/[provider]/callback.d.ts +1 -0
- package/dist/runtime/server/routes/auth/[provider]/callback.mjs +1 -0
- package/dist/runtime/server/routes/auth/[provider].d.ts +3 -0
- package/dist/runtime/server/routes/auth/[provider].mjs +95 -0
- package/dist/runtime/server/routes/auth/account.delete.d.ts +5 -0
- package/dist/runtime/server/routes/auth/account.delete.mjs +52 -0
- package/dist/runtime/server/routes/auth/impersonate/start.post.d.ts +5 -0
- package/dist/runtime/server/routes/auth/impersonate/start.post.mjs +14 -0
- package/dist/runtime/server/routes/auth/impersonate/stop.post.d.ts +5 -0
- package/dist/runtime/server/routes/auth/impersonate/stop.post.mjs +5 -0
- package/dist/runtime/server/routes/auth/logout-all.post.d.ts +4 -0
- package/dist/runtime/server/routes/auth/logout-all.post.mjs +16 -0
- package/dist/runtime/server/routes/auth/logout-others.post.d.ts +4 -0
- package/dist/runtime/server/routes/auth/logout-others.post.mjs +11 -0
- package/dist/runtime/server/routes/auth/logout.post.d.ts +4 -0
- package/dist/runtime/server/routes/auth/logout.post.mjs +17 -0
- package/dist/runtime/server/routes/auth/magic-link/send.post.d.ts +10 -0
- package/dist/runtime/server/routes/auth/magic-link/send.post.mjs +29 -0
- package/dist/runtime/server/routes/auth/magic-link/verify.get.d.ts +2 -0
- package/dist/runtime/server/routes/auth/magic-link/verify.get.mjs +81 -0
- package/dist/runtime/server/routes/auth/organization/create.post.d.ts +5 -0
- package/dist/runtime/server/routes/auth/organization/create.post.mjs +10 -0
- package/dist/runtime/server/routes/auth/organization/invite.post.d.ts +9 -0
- package/dist/runtime/server/routes/auth/organization/invite.post.mjs +27 -0
- package/dist/runtime/server/routes/auth/organization/join.post.d.ts +6 -0
- package/dist/runtime/server/routes/auth/organization/join.post.mjs +15 -0
- package/dist/runtime/server/routes/auth/organization/list.get.d.ts +5 -0
- package/dist/runtime/server/routes/auth/organization/list.get.mjs +7 -0
- package/dist/runtime/server/routes/auth/organization/members/[id].delete.d.ts +4 -0
- package/dist/runtime/server/routes/auth/organization/members/[id].delete.mjs +33 -0
- package/dist/runtime/server/routes/auth/organization/members/index.get.d.ts +6 -0
- package/dist/runtime/server/routes/auth/organization/members/index.get.mjs +18 -0
- package/dist/runtime/server/routes/auth/organization/mfa.post.d.ts +6 -0
- package/dist/runtime/server/routes/auth/organization/mfa.post.mjs +33 -0
- package/dist/runtime/server/routes/auth/organization/sso/[id].delete.d.ts +4 -0
- package/dist/runtime/server/routes/auth/organization/sso/[id].delete.mjs +28 -0
- package/dist/runtime/server/routes/auth/organization/sso/index.get.d.ts +2 -0
- package/dist/runtime/server/routes/auth/organization/sso/index.get.mjs +23 -0
- package/dist/runtime/server/routes/auth/organization/sso/index.post.d.ts +5 -0
- package/dist/runtime/server/routes/auth/organization/sso/index.post.mjs +84 -0
- package/dist/runtime/server/routes/auth/organization/switch.post.d.ts +6 -0
- package/dist/runtime/server/routes/auth/organization/switch.post.mjs +14 -0
- package/dist/runtime/server/routes/auth/otp/send.post.d.ts +10 -0
- package/dist/runtime/server/routes/auth/otp/send.post.mjs +29 -0
- package/dist/runtime/server/routes/auth/otp/verify.post.d.ts +6 -0
- package/dist/runtime/server/routes/auth/otp/verify.post.mjs +95 -0
- package/dist/runtime/server/routes/auth/sessions/[id].delete.d.ts +5 -0
- package/dist/runtime/server/routes/auth/sessions/[id].delete.mjs +24 -0
- package/dist/runtime/server/routes/auth/sessions.get.d.ts +2 -0
- package/dist/runtime/server/routes/auth/sessions.get.mjs +11 -0
- package/dist/runtime/server/routes/auth/sso/login.get.d.ts +2 -0
- package/dist/runtime/server/routes/auth/sso/login.get.mjs +94 -0
- package/dist/runtime/server/routes/auth/sso/oidc/callback.get.d.ts +2 -0
- package/dist/runtime/server/routes/auth/sso/oidc/callback.get.mjs +113 -0
- package/dist/runtime/server/routes/auth/sso/saml/acs.post.d.ts +2 -0
- package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +95 -0
- package/dist/runtime/server/routes/auth/tokens/[id].delete.d.ts +4 -0
- package/dist/runtime/server/routes/auth/tokens/[id].delete.mjs +13 -0
- package/dist/runtime/server/routes/auth/tokens/create.post.d.ts +9 -0
- package/dist/runtime/server/routes/auth/tokens/create.post.mjs +17 -0
- package/dist/runtime/server/routes/auth/tokens/index.get.d.ts +9 -0
- package/dist/runtime/server/routes/auth/tokens/index.get.mjs +5 -0
- package/dist/runtime/server/routes/auth/turnstile/verify.post.d.ts +2 -0
- package/dist/runtime/server/routes/auth/turnstile/verify.post.mjs +15 -0
- package/dist/runtime/server/routes/auth/user.get.d.ts +2 -0
- package/dist/runtime/server/routes/auth/user.get.mjs +6 -0
- package/dist/runtime/server/routes/auth/webauthn/login/options.post.d.ts +2 -0
- package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +17 -0
- package/dist/runtime/server/routes/auth/webauthn/login/verify.post.d.ts +6 -0
- package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +127 -0
- package/dist/runtime/server/routes/auth/webauthn/register/options.post.d.ts +2 -0
- package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +47 -0
- package/dist/runtime/server/routes/auth/webauthn/register/verify.post.d.ts +5 -0
- package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +88 -0
- package/dist/runtime/server/routes/cms/[collection]/[id]/preview-token.post.d.ts +8 -0
- package/dist/runtime/server/routes/cms/[collection]/[id]/preview-token.post.mjs +27 -0
- package/dist/runtime/server/routes/cms/[collection]/[id]/publish.post.d.ts +6 -0
- package/dist/runtime/server/routes/cms/[collection]/[id]/publish.post.mjs +19 -0
- package/dist/runtime/server/routes/cms/[collection]/[id]/review.post.d.ts +6 -0
- package/dist/runtime/server/routes/cms/[collection]/[id]/review.post.mjs +33 -0
- package/dist/runtime/server/routes/cms/[collection]/[id].delete.d.ts +4 -0
- package/dist/runtime/server/routes/cms/[collection]/[id].delete.mjs +17 -0
- package/dist/runtime/server/routes/cms/[collection]/[id].put.d.ts +4 -0
- package/dist/runtime/server/routes/cms/[collection]/[id].put.mjs +18 -0
- package/dist/runtime/server/routes/cms/[collection]/[slug].get.d.ts +4 -0
- package/dist/runtime/server/routes/cms/[collection]/[slug].get.mjs +19 -0
- package/dist/runtime/server/routes/cms/[collection]/atom.xml.get.d.ts +2 -0
- package/dist/runtime/server/routes/cms/[collection]/atom.xml.get.mjs +69 -0
- package/dist/runtime/server/routes/cms/[collection]/by-path.get.d.ts +8 -0
- package/dist/runtime/server/routes/cms/[collection]/by-path.get.mjs +23 -0
- package/dist/runtime/server/routes/cms/[collection]/feed.xml.get.d.ts +2 -0
- package/dist/runtime/server/routes/cms/[collection]/feed.xml.get.mjs +65 -0
- package/dist/runtime/server/routes/cms/[collection]/index.get.d.ts +7 -0
- package/dist/runtime/server/routes/cms/[collection]/index.get.mjs +15 -0
- package/dist/runtime/server/routes/cms/[collection]/index.post.d.ts +4 -0
- package/dist/runtime/server/routes/cms/[collection]/index.post.mjs +23 -0
- package/dist/runtime/server/routes/cms/[collection]/references.get.d.ts +19 -0
- package/dist/runtime/server/routes/cms/[collection]/references.get.mjs +47 -0
- package/dist/runtime/server/routes/cms/[collection]/surroundings.get.d.ts +10 -0
- package/dist/runtime/server/routes/cms/[collection]/surroundings.get.mjs +12 -0
- package/dist/runtime/server/routes/cms/collections/[id].delete.d.ts +4 -0
- package/dist/runtime/server/routes/cms/collections/[id].delete.mjs +10 -0
- package/dist/runtime/server/routes/cms/collections/[id].put.d.ts +4 -0
- package/dist/runtime/server/routes/cms/collections/[id].put.mjs +11 -0
- package/dist/runtime/server/routes/cms/collections/index.get.d.ts +4 -0
- package/dist/runtime/server/routes/cms/collections/index.get.mjs +6 -0
- package/dist/runtime/server/routes/cms/collections/index.post.d.ts +4 -0
- package/dist/runtime/server/routes/cms/collections/index.post.mjs +19 -0
- package/dist/runtime/server/routes/cms/components/index.get.d.ts +17 -0
- package/dist/runtime/server/routes/cms/components/index.get.mjs +16 -0
- package/dist/runtime/server/routes/cms/deploy.post.d.ts +4 -0
- package/dist/runtime/server/routes/cms/deploy.post.mjs +46 -0
- package/dist/runtime/server/routes/cms/export.post.d.ts +10 -0
- package/dist/runtime/server/routes/cms/export.post.mjs +55 -0
- package/dist/runtime/server/routes/cms/navigation.get.d.ts +8 -0
- package/dist/runtime/server/routes/cms/navigation.get.mjs +36 -0
- package/dist/runtime/server/routes/cms/preview/disable.get.d.ts +9 -0
- package/dist/runtime/server/routes/cms/preview/disable.get.mjs +9 -0
- package/dist/runtime/server/routes/cms/preview/enable.get.d.ts +14 -0
- package/dist/runtime/server/routes/cms/preview/enable.get.mjs +42 -0
- package/dist/runtime/server/routes/cms/publish-scheduled.post.d.ts +11 -0
- package/dist/runtime/server/routes/cms/publish-scheduled.post.mjs +35 -0
- package/dist/runtime/server/routes/cms/search.get.d.ts +13 -0
- package/dist/runtime/server/routes/cms/search.get.mjs +137 -0
- package/dist/runtime/server/routes/cms/sync.post.d.ts +7 -0
- package/dist/runtime/server/routes/cms/sync.post.mjs +18 -0
- package/dist/runtime/server/routes/cms/webhooks/[provider].post.d.ts +150 -0
- package/dist/runtime/server/routes/cms/webhooks/[provider].post.mjs +213 -0
- package/dist/runtime/server/routes/docs/search.get.d.ts +15 -0
- package/dist/runtime/server/routes/docs/search.get.mjs +20 -0
- package/dist/runtime/server/routes/feed.xml.get.d.ts +2 -0
- package/dist/runtime/server/routes/feed.xml.get.mjs +73 -0
- package/dist/runtime/server/routes/mail/bounce.post.d.ts +14 -0
- package/dist/runtime/server/routes/mail/bounce.post.mjs +56 -0
- package/dist/runtime/server/routes/mail/inbox/[id].get.d.ts +2 -0
- package/dist/runtime/server/routes/mail/inbox/[id].get.mjs +9 -0
- package/dist/runtime/server/routes/mail/inbox.get.d.ts +4 -0
- package/dist/runtime/server/routes/mail/inbox.get.mjs +7 -0
- package/dist/runtime/server/routes/mail/suppressions/[email].delete.d.ts +11 -0
- package/dist/runtime/server/routes/mail/suppressions/[email].delete.mjs +18 -0
- package/dist/runtime/server/routes/mail/suppressions/index.get.d.ts +12 -0
- package/dist/runtime/server/routes/mail/suppressions/index.get.mjs +23 -0
- package/dist/runtime/server/routes/mail/suppressions/index.post.d.ts +10 -0
- package/dist/runtime/server/routes/mail/suppressions/index.post.mjs +23 -0
- package/dist/runtime/server/routes/mail/unsubscribe.d.ts +13 -0
- package/dist/runtime/server/routes/mail/unsubscribe.mjs +91 -0
- package/dist/runtime/server/routes/mail/webhooks.post.d.ts +12 -0
- package/dist/runtime/server/routes/mail/webhooks.post.mjs +71 -0
- package/dist/runtime/server/routes/notifications/[id]/read.post.d.ts +4 -0
- package/dist/runtime/server/routes/notifications/[id]/read.post.mjs +13 -0
- package/dist/runtime/server/routes/notifications/[id].delete.d.ts +4 -0
- package/dist/runtime/server/routes/notifications/[id].delete.mjs +13 -0
- package/dist/runtime/server/routes/notifications/[id].get.d.ts +2 -0
- package/dist/runtime/server/routes/notifications/[id].get.mjs +15 -0
- package/dist/runtime/server/routes/notifications/index.get.d.ts +6 -0
- package/dist/runtime/server/routes/notifications/index.get.mjs +18 -0
- package/dist/runtime/server/routes/notifications/push/subscribe.post.d.ts +4 -0
- package/dist/runtime/server/routes/notifications/push/subscribe.post.mjs +20 -0
- package/dist/runtime/server/routes/notifications/push/unsubscribe.post.d.ts +4 -0
- package/dist/runtime/server/routes/notifications/push/unsubscribe.post.mjs +15 -0
- package/dist/runtime/server/routes/notifications/read-all.post.d.ts +4 -0
- package/dist/runtime/server/routes/notifications/read-all.post.mjs +11 -0
- package/dist/runtime/server/routes/payments/cancel.post.d.ts +7 -0
- package/dist/runtime/server/routes/payments/cancel.post.mjs +9 -0
- package/dist/runtime/server/routes/payments/change-plan.post.d.ts +7 -0
- package/dist/runtime/server/routes/payments/change-plan.post.mjs +12 -0
- package/dist/runtime/server/routes/payments/checkout.post.d.ts +9 -0
- package/dist/runtime/server/routes/payments/checkout.post.mjs +16 -0
- package/dist/runtime/server/routes/payments/pause.post.d.ts +7 -0
- package/dist/runtime/server/routes/payments/pause.post.mjs +9 -0
- package/dist/runtime/server/routes/payments/portal.post.d.ts +5 -0
- package/dist/runtime/server/routes/payments/portal.post.mjs +9 -0
- package/dist/runtime/server/routes/payments/subscription.get.d.ts +6 -0
- package/dist/runtime/server/routes/payments/subscription.get.mjs +9 -0
- package/dist/runtime/server/routes/payments/usage.get.d.ts +12 -0
- package/dist/runtime/server/routes/payments/usage.get.mjs +18 -0
- package/dist/runtime/server/routes/payments/usage.post.d.ts +6 -0
- package/dist/runtime/server/routes/payments/usage.post.mjs +24 -0
- package/dist/runtime/server/routes/payments/webhook.post.d.ts +14 -0
- package/dist/runtime/server/routes/payments/webhook.post.mjs +21 -0
- package/dist/runtime/server/routes/realtime/broadcast.post.d.ts +4 -0
- package/dist/runtime/server/routes/realtime/broadcast.post.mjs +26 -0
- package/dist/runtime/server/routes/realtime/history.delete.d.ts +13 -0
- package/dist/runtime/server/routes/realtime/history.delete.mjs +12 -0
- package/dist/runtime/server/routes/realtime/history.get.d.ts +16 -0
- package/dist/runtime/server/routes/realtime/history.get.mjs +15 -0
- package/dist/runtime/server/routes/realtime/presence.get.d.ts +6 -0
- package/dist/runtime/server/routes/realtime/presence.get.mjs +27 -0
- package/dist/runtime/server/routes/realtime/state.get.d.ts +5 -0
- package/dist/runtime/server/routes/realtime/state.get.mjs +26 -0
- package/dist/runtime/server/routes/realtime/state.post.d.ts +6 -0
- package/dist/runtime/server/routes/realtime/state.post.mjs +37 -0
- package/dist/runtime/server/routes/realtime/ws.get.d.ts +2 -0
- package/dist/runtime/server/routes/realtime/ws.get.mjs +73 -0
- package/dist/runtime/server/routes/robots.txt.get.d.ts +2 -0
- package/dist/runtime/server/routes/robots.txt.get.mjs +41 -0
- package/dist/runtime/server/routes/rss.xml.get.d.ts +2 -0
- package/dist/runtime/server/routes/rss.xml.get.mjs +2 -0
- package/dist/runtime/server/routes/sitemap.xml.get.d.ts +2 -0
- package/dist/runtime/server/routes/sitemap.xml.get.mjs +84 -0
- package/dist/runtime/server/routes/storage/file/[...key].delete.d.ts +4 -0
- package/dist/runtime/server/routes/storage/file/[...key].delete.mjs +23 -0
- package/dist/runtime/server/routes/storage/file/[...key].get.d.ts +2 -0
- package/dist/runtime/server/routes/storage/file/[...key].get.mjs +23 -0
- package/dist/runtime/server/routes/storage/files.get.d.ts +14 -0
- package/dist/runtime/server/routes/storage/files.get.mjs +11 -0
- package/dist/runtime/server/routes/storage/presigned.post.d.ts +8 -0
- package/dist/runtime/server/routes/storage/presigned.post.mjs +39 -0
- package/dist/runtime/server/routes/storage/sign.post.d.ts +6 -0
- package/dist/runtime/server/routes/storage/sign.post.mjs +24 -0
- package/dist/runtime/server/routes/storage/upload.post.d.ts +22 -0
- package/dist/runtime/server/routes/storage/upload.post.mjs +96 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.d.ts +8 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +39 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.d.ts +8 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +39 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.get.d.ts +8 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.get.mjs +20 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.post.d.ts +8 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.post.mjs +44 -0
- package/dist/runtime/server/routes/tenants/current.get.d.ts +8 -0
- package/dist/runtime/server/routes/tenants/current.get.mjs +6 -0
- package/dist/runtime/server/tasks/cms/publish.d.ts +4 -0
- package/dist/runtime/server/tasks/cms/publish.mjs +18 -0
- package/dist/runtime/server/utils/agent-store.d.ts +24 -0
- package/dist/runtime/server/utils/agent-store.mjs +53 -0
- package/dist/runtime/server/utils/agents-registry-fallback.d.ts +1 -0
- package/dist/runtime/server/utils/agents-registry-fallback.mjs +1 -0
- package/dist/runtime/server/utils/ai.d.ts +119 -0
- package/dist/runtime/server/utils/ai.mjs +607 -0
- package/dist/runtime/server/utils/analytics-query.d.ts +109 -0
- package/dist/runtime/server/utils/analytics-query.mjs +234 -0
- package/dist/runtime/server/utils/auth.d.ts +60 -0
- package/dist/runtime/server/utils/auth.mjs +361 -0
- package/dist/runtime/server/utils/blob-store.d.ts +13 -0
- package/dist/runtime/server/utils/blob-store.mjs +60 -0
- package/dist/runtime/server/utils/bots.d.ts +21 -0
- package/dist/runtime/server/utils/bots.mjs +491 -0
- package/dist/runtime/server/utils/cache.d.ts +33 -0
- package/dist/runtime/server/utils/cache.mjs +128 -0
- package/dist/runtime/server/utils/cms-events.d.ts +17 -0
- package/dist/runtime/server/utils/cms-events.mjs +80 -0
- package/dist/runtime/server/utils/cms-filter.d.ts +3 -0
- package/dist/runtime/server/utils/cms-filter.mjs +34 -0
- package/dist/runtime/server/utils/cms.d.ts +278 -0
- package/dist/runtime/server/utils/cms.mjs +3268 -0
- package/dist/runtime/server/utils/config.d.ts +27 -0
- package/dist/runtime/server/utils/config.mjs +38 -0
- package/dist/runtime/server/utils/context.d.ts +13 -0
- package/dist/runtime/server/utils/context.mjs +98 -0
- package/dist/runtime/server/utils/crypto.d.ts +16 -0
- package/dist/runtime/server/utils/crypto.mjs +56 -0
- package/dist/runtime/server/utils/dev-logs.d.ts +21 -0
- package/dist/runtime/server/utils/dev-logs.mjs +41 -0
- package/dist/runtime/server/utils/dev-proxy.d.ts +1 -0
- package/dist/runtime/server/utils/dev-proxy.mjs +69 -0
- package/dist/runtime/server/utils/domains.d.ts +46 -0
- package/dist/runtime/server/utils/domains.mjs +318 -0
- package/dist/runtime/server/utils/drizzle.d.ts +10 -0
- package/dist/runtime/server/utils/drizzle.mjs +36 -0
- package/dist/runtime/server/utils/email-templates.d.ts +44 -0
- package/dist/runtime/server/utils/email-templates.mjs +373 -0
- package/dist/runtime/server/utils/feed.d.ts +42 -0
- package/dist/runtime/server/utils/feed.mjs +161 -0
- package/dist/runtime/server/utils/impersonation.d.ts +67 -0
- package/dist/runtime/server/utils/impersonation.mjs +298 -0
- package/dist/runtime/server/utils/jobs.d.ts +70 -0
- package/dist/runtime/server/utils/jobs.mjs +125 -0
- package/dist/runtime/server/utils/kv-store.d.ts +9 -0
- package/dist/runtime/server/utils/kv-store.mjs +32 -0
- package/dist/runtime/server/utils/mail-suppression.d.ts +62 -0
- package/dist/runtime/server/utils/mail-suppression.mjs +328 -0
- package/dist/runtime/server/utils/mail.d.ts +90 -0
- package/dist/runtime/server/utils/mail.mjs +366 -0
- package/dist/runtime/server/utils/notifications.d.ts +51 -0
- package/dist/runtime/server/utils/notifications.mjs +215 -0
- package/dist/runtime/server/utils/organization.d.ts +54 -0
- package/dist/runtime/server/utils/organization.mjs +354 -0
- package/dist/runtime/server/utils/passwordless.d.ts +48 -0
- package/dist/runtime/server/utils/passwordless.mjs +179 -0
- package/dist/runtime/server/utils/payments.d.ts +121 -0
- package/dist/runtime/server/utils/payments.mjs +1067 -0
- package/dist/runtime/server/utils/queue-fallback.d.ts +2 -0
- package/dist/runtime/server/utils/queue-fallback.mjs +2 -0
- package/dist/runtime/server/utils/queue.d.ts +4 -0
- package/dist/runtime/server/utils/queue.mjs +3 -0
- package/dist/runtime/server/utils/rag.d.ts +25 -0
- package/dist/runtime/server/utils/rag.mjs +333 -0
- package/dist/runtime/server/utils/ratelimit.d.ts +45 -0
- package/dist/runtime/server/utils/ratelimit.mjs +182 -0
- package/dist/runtime/server/utils/realtime.d.ts +110 -0
- package/dist/runtime/server/utils/realtime.mjs +197 -0
- package/dist/runtime/server/utils/schema-fallback.d.ts +3 -0
- package/dist/runtime/server/utils/schema-fallback.mjs +2 -0
- package/dist/runtime/server/utils/session.d.ts +72 -0
- package/dist/runtime/server/utils/session.mjs +287 -0
- package/dist/runtime/server/utils/sso.d.ts +49 -0
- package/dist/runtime/server/utils/sso.mjs +131 -0
- package/dist/runtime/server/utils/storage.d.ts +111 -0
- package/dist/runtime/server/utils/storage.mjs +654 -0
- package/dist/runtime/server/utils/tenant.d.ts +44 -0
- package/dist/runtime/server/utils/tenant.mjs +285 -0
- package/dist/runtime/server/utils/totp.d.ts +33 -0
- package/dist/runtime/server/utils/totp.mjs +112 -0
- package/dist/runtime/server/utils/tracker.d.ts +72 -0
- package/dist/runtime/server/utils/tracker.mjs +139 -0
- package/dist/runtime/server/utils/turnstile.d.ts +17 -0
- package/dist/runtime/server/utils/turnstile.mjs +68 -0
- package/dist/runtime/server/utils/vapid.d.ts +35 -0
- package/dist/runtime/server/utils/vapid.mjs +211 -0
- package/dist/runtime/storage.d.ts +1 -0
- package/dist/runtime/storage.mjs +0 -0
- package/dist/runtime/types/ai.d.ts +68 -0
- package/dist/runtime/types/ai.mjs +0 -0
- package/dist/runtime/types/analytics.d.ts +30 -0
- package/dist/runtime/types/analytics.mjs +0 -0
- package/dist/runtime/types/auth-globals.d.ts +14 -0
- package/dist/runtime/types/auth.d.ts +153 -0
- package/dist/runtime/types/auth.mjs +0 -0
- package/dist/runtime/types/browser.d.ts +29 -0
- package/dist/runtime/types/browser.mjs +0 -0
- package/dist/runtime/types/d1.d.ts +44 -0
- package/dist/runtime/types/d1.mjs +0 -0
- package/dist/runtime/types/drizzle.d.ts +13 -0
- package/dist/runtime/types/drizzle.mjs +0 -0
- package/dist/runtime/types/durable-object.d.ts +51 -0
- package/dist/runtime/types/durable-object.mjs +0 -0
- package/dist/runtime/types/email.d.ts +66 -0
- package/dist/runtime/types/email.mjs +0 -0
- package/dist/runtime/types/hyperdrive.d.ts +18 -0
- package/dist/runtime/types/hyperdrive.mjs +0 -0
- package/dist/runtime/types/imports.d.ts +58 -0
- package/dist/runtime/types/index.d.ts +156 -0
- package/dist/runtime/types/index.mjs +13 -0
- package/dist/runtime/types/queue.d.ts +67 -0
- package/dist/runtime/types/queue.mjs +0 -0
- package/dist/runtime/types/r2.d.ts +108 -0
- package/dist/runtime/types/r2.mjs +0 -0
- package/dist/runtime/types/ratelimit.d.ts +21 -0
- package/dist/runtime/types/ratelimit.mjs +0 -0
- package/dist/runtime/types/vectorize.d.ts +74 -0
- package/dist/runtime/types/vectorize.mjs +0 -0
- package/dist/runtime/vectorize.d.ts +21 -0
- package/dist/runtime/vectorize.mjs +53 -0
- package/dist/types.d.ts +2750 -0
- package/dist/types.mjs +1 -0
- package/dist/utils/agents.d.ts +8 -0
- package/dist/utils/auth-schema.d.ts +11 -0
- package/dist/utils/bindings.d.ts +16 -0
- package/dist/utils/cms-schema.d.ts +1 -0
- package/dist/utils/cms-sources.d.ts +62 -0
- package/dist/utils/drizzle.d.ts +42 -0
- package/dist/utils/jobs.d.ts +8 -0
- package/dist/utils/local-db.d.ts +28 -0
- package/dist/utils/notifications-schema.d.ts +15 -0
- package/dist/utils/payments-schema.d.ts +11 -0
- package/dist/utils/pkg.d.ts +15 -0
- package/dist/utils/queue.d.ts +8 -0
- package/dist/utils/tenants-schema.d.ts +11 -0
- package/package.json +104 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { QueueMessageBatch } from "../../index";
|
|
2
|
+
export type QueueHandler<T = any> = (batch: QueueMessageBatch<T>) => void | Promise<void>;
|
|
3
|
+
/** Defines a type-safe consumer event handler for incoming Cloudflare Queue batches. */
|
|
4
|
+
export declare function defineQueueHandler<T = any>(handler: QueueHandler<T>): QueueHandler<T>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ChunkOptions, RAGPipelineConfig, RAGPipeline } from "../../../types";
|
|
2
|
+
export type { ChunkOptions, RAGDocument, RAGChunk, RAGChunkMatch, RAGPipelineConfig, RAGQueryOptions, RAGContextResult, RAGAnswerOptions, RAGAnswerResult, RAGPipeline, } from "../../../types";
|
|
3
|
+
/**
|
|
4
|
+
* Splits raw text into overlapping contextual chunks respecting paragraph,
|
|
5
|
+
* sentence, and word boundaries.
|
|
6
|
+
*/
|
|
7
|
+
export declare function splitTextIntoChunks(text: string, options?: ChunkOptions): string[];
|
|
8
|
+
/**
|
|
9
|
+
* Creates an edge-native RAG (Retrieval-Augmented Generation) pipeline backed by
|
|
10
|
+
* Cloudflare Vectorize and Workers AI.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // server/utils/rag.ts
|
|
14
|
+
* export const docsRAG = createRAGPipeline({
|
|
15
|
+
* binding: "VECTORIZE",
|
|
16
|
+
* embeddingModel: "@cf/baai/bge-base-en-v1.5",
|
|
17
|
+
* })
|
|
18
|
+
*
|
|
19
|
+
* // Ingest docs:
|
|
20
|
+
* await docsRAG.indexDocument({ id: "auth-guide", text: "..." })
|
|
21
|
+
*
|
|
22
|
+
* // Answer questions:
|
|
23
|
+
* const { answer, sources } = await docsRAG.answer("How do I enable MFA?")
|
|
24
|
+
*/
|
|
25
|
+
export declare function createRAGPipeline(config?: RAGPipelineConfig): RAGPipeline;
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { getVectorizeBinding } from "../../vectorize.mjs";
|
|
2
|
+
import { embedText, generateText, defineTool } from "./ai.mjs";
|
|
3
|
+
const GLOBAL_RAG_KEY = "__qarpeo_dev_mock_rag__";
|
|
4
|
+
function getDevMockRAGStore() {
|
|
5
|
+
const g = globalThis;
|
|
6
|
+
if (!g[GLOBAL_RAG_KEY]) {
|
|
7
|
+
g[GLOBAL_RAG_KEY] = /* @__PURE__ */ new Map();
|
|
8
|
+
}
|
|
9
|
+
return g[GLOBAL_RAG_KEY];
|
|
10
|
+
}
|
|
11
|
+
function cosineSimilarity(a, b) {
|
|
12
|
+
if (!a || !b || a.length !== b.length) return 0;
|
|
13
|
+
let dotProduct = 0;
|
|
14
|
+
let normA = 0;
|
|
15
|
+
let normB = 0;
|
|
16
|
+
for (let i = 0; i < a.length; i++) {
|
|
17
|
+
dotProduct += a[i] * b[i];
|
|
18
|
+
normA += a[i] * a[i];
|
|
19
|
+
normB += b[i] * b[i];
|
|
20
|
+
}
|
|
21
|
+
if (normA === 0 || normB === 0) return 0;
|
|
22
|
+
return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
|
|
23
|
+
}
|
|
24
|
+
const DEFAULT_SEPARATORS = ["\n\n", "\n", ". ", "? ", "! ", "; ", ", ", " "];
|
|
25
|
+
export function splitTextIntoChunks(text, options) {
|
|
26
|
+
if (!text || typeof text !== "string") return [];
|
|
27
|
+
const chunkSize = options?.chunkSize ?? 800;
|
|
28
|
+
const chunkOverlap = options?.chunkOverlap ?? 100;
|
|
29
|
+
const separators = options?.separators ?? DEFAULT_SEPARATORS;
|
|
30
|
+
const cleanText = text.trim();
|
|
31
|
+
if (cleanText.length <= chunkSize) {
|
|
32
|
+
return [cleanText];
|
|
33
|
+
}
|
|
34
|
+
function splitRecursive(content, separatorIndex) {
|
|
35
|
+
if (content.length <= chunkSize) {
|
|
36
|
+
return [content];
|
|
37
|
+
}
|
|
38
|
+
if (separatorIndex >= separators.length) {
|
|
39
|
+
const hardChunks = [];
|
|
40
|
+
let start = 0;
|
|
41
|
+
while (start < content.length) {
|
|
42
|
+
const end = Math.min(start + chunkSize, content.length);
|
|
43
|
+
hardChunks.push(content.slice(start, end));
|
|
44
|
+
start += chunkSize - chunkOverlap;
|
|
45
|
+
}
|
|
46
|
+
return hardChunks;
|
|
47
|
+
}
|
|
48
|
+
const separator = separators[separatorIndex];
|
|
49
|
+
const parts = content.split(separator);
|
|
50
|
+
const chunks = [];
|
|
51
|
+
let currentChunk = "";
|
|
52
|
+
for (let i = 0; i < parts.length; i++) {
|
|
53
|
+
const part = parts[i];
|
|
54
|
+
const candidate = currentChunk ? `${currentChunk}${separator}${part}` : part;
|
|
55
|
+
if (candidate.length <= chunkSize) {
|
|
56
|
+
currentChunk = candidate;
|
|
57
|
+
} else {
|
|
58
|
+
if (currentChunk) {
|
|
59
|
+
chunks.push(currentChunk);
|
|
60
|
+
if (chunkOverlap > 0 && currentChunk.length > chunkOverlap) {
|
|
61
|
+
const overlapText = currentChunk.slice(currentChunk.length - chunkOverlap);
|
|
62
|
+
currentChunk = `${overlapText}${separator}${part}`;
|
|
63
|
+
} else {
|
|
64
|
+
currentChunk = part;
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
const subChunks = splitRecursive(part, separatorIndex + 1);
|
|
68
|
+
chunks.push(...subChunks);
|
|
69
|
+
currentChunk = "";
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (currentChunk.trim().length > 0) {
|
|
74
|
+
chunks.push(currentChunk);
|
|
75
|
+
}
|
|
76
|
+
return chunks;
|
|
77
|
+
}
|
|
78
|
+
return splitRecursive(cleanText, 0).map((c) => c.trim()).filter((c) => c.length > 0);
|
|
79
|
+
}
|
|
80
|
+
export function createRAGPipeline(config) {
|
|
81
|
+
const bindingName = config?.binding || "VECTORIZE";
|
|
82
|
+
const aiBindingName = config?.aiBinding || "AI";
|
|
83
|
+
const embeddingModel = config?.embeddingModel || "@cf/baai/bge-base-en-v1.5";
|
|
84
|
+
const llmModel = config?.llmModel || "@cf/meta/llama-3.3-70b-instruct";
|
|
85
|
+
const defaultChunking = config?.chunking || { chunkSize: 800, chunkOverlap: 100 };
|
|
86
|
+
const defaultNamespace = config?.namespace;
|
|
87
|
+
function resolveVectorize(event) {
|
|
88
|
+
try {
|
|
89
|
+
return getVectorizeBinding(bindingName, event || config?.event);
|
|
90
|
+
} catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
chunkText(text, options) {
|
|
96
|
+
return splitTextIntoChunks(text, { ...defaultChunking, ...options });
|
|
97
|
+
},
|
|
98
|
+
async indexDocument(doc, options) {
|
|
99
|
+
const chunkTexts = splitTextIntoChunks(doc.text, { ...defaultChunking, ...options?.chunking });
|
|
100
|
+
if (chunkTexts.length === 0) {
|
|
101
|
+
return { chunksIndexed: 0 };
|
|
102
|
+
}
|
|
103
|
+
const namespace = doc.namespace || defaultNamespace;
|
|
104
|
+
const event = options?.event || config?.event;
|
|
105
|
+
let embeddings = [];
|
|
106
|
+
try {
|
|
107
|
+
embeddings = await embedText(chunkTexts, {
|
|
108
|
+
model: embeddingModel,
|
|
109
|
+
binding: aiBindingName,
|
|
110
|
+
event
|
|
111
|
+
});
|
|
112
|
+
} catch {
|
|
113
|
+
embeddings = chunkTexts.map((txt) => {
|
|
114
|
+
const vec = new Array(768).fill(0);
|
|
115
|
+
for (let i = 0; i < txt.length; i++) {
|
|
116
|
+
vec[i % 768] = (vec[i % 768] + txt.charCodeAt(i)) / 1e3;
|
|
117
|
+
}
|
|
118
|
+
return vec;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
const vectors = chunkTexts.map((text, i) => {
|
|
122
|
+
const chunkId = `${doc.id}#chunk-${i}`;
|
|
123
|
+
const values = embeddings[i] || new Array(768).fill(0);
|
|
124
|
+
const metadata = {
|
|
125
|
+
...doc.metadata || {},
|
|
126
|
+
documentId: doc.id,
|
|
127
|
+
chunkIndex: i,
|
|
128
|
+
totalChunks: chunkTexts.length,
|
|
129
|
+
text
|
|
130
|
+
};
|
|
131
|
+
return {
|
|
132
|
+
id: chunkId,
|
|
133
|
+
values,
|
|
134
|
+
namespace,
|
|
135
|
+
metadata
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
const vectorize = resolveVectorize(event);
|
|
139
|
+
let mutationId;
|
|
140
|
+
if (vectorize) {
|
|
141
|
+
const res = await vectorize.upsert(vectors);
|
|
142
|
+
mutationId = res?.mutationId;
|
|
143
|
+
} else {
|
|
144
|
+
const store = getDevMockRAGStore();
|
|
145
|
+
for (const v of vectors) {
|
|
146
|
+
store.set(v.id, {
|
|
147
|
+
id: v.id,
|
|
148
|
+
vector: v.values,
|
|
149
|
+
documentId: doc.id,
|
|
150
|
+
chunkIndex: v.metadata.chunkIndex,
|
|
151
|
+
totalChunks: v.metadata.totalChunks,
|
|
152
|
+
text: v.metadata.text,
|
|
153
|
+
namespace: v.namespace,
|
|
154
|
+
metadata: v.metadata
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
mutationId = `mock_mut_${Date.now()}`;
|
|
158
|
+
}
|
|
159
|
+
return { chunksIndexed: vectors.length, mutationId };
|
|
160
|
+
},
|
|
161
|
+
async indexDocuments(docs, options) {
|
|
162
|
+
const batchSize = options?.batchSize || 10;
|
|
163
|
+
let totalChunks = 0;
|
|
164
|
+
for (let i = 0; i < docs.length; i += batchSize) {
|
|
165
|
+
const batch = docs.slice(i, i + batchSize);
|
|
166
|
+
await Promise.all(
|
|
167
|
+
batch.map(async (doc) => {
|
|
168
|
+
const res = await this.indexDocument(doc, options);
|
|
169
|
+
totalChunks += res.chunksIndexed;
|
|
170
|
+
})
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
return { totalIndexed: docs.length, totalChunks };
|
|
174
|
+
},
|
|
175
|
+
async deleteDocument(documentId, options) {
|
|
176
|
+
const maxChunks = options?.maxChunks || 100;
|
|
177
|
+
const idsToDelete = [];
|
|
178
|
+
for (let i = 0; i < maxChunks; i++) {
|
|
179
|
+
idsToDelete.push(`${documentId}#chunk-${i}`);
|
|
180
|
+
}
|
|
181
|
+
const vectorize = resolveVectorize(options?.event || config?.event);
|
|
182
|
+
if (vectorize) {
|
|
183
|
+
await vectorize.deleteByIds(idsToDelete);
|
|
184
|
+
} else {
|
|
185
|
+
const store = getDevMockRAGStore();
|
|
186
|
+
for (const [id, item] of store.entries()) {
|
|
187
|
+
if (item.documentId === documentId) {
|
|
188
|
+
store.delete(id);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
async query(queryText, options) {
|
|
194
|
+
const topK = options?.topK || 5;
|
|
195
|
+
const minScore = options?.minScore ?? 0;
|
|
196
|
+
const namespace = options?.namespace || defaultNamespace;
|
|
197
|
+
const event = options?.event || config?.event;
|
|
198
|
+
let queryVector = [];
|
|
199
|
+
try {
|
|
200
|
+
const emb = await embedText(queryText, {
|
|
201
|
+
model: embeddingModel,
|
|
202
|
+
binding: aiBindingName,
|
|
203
|
+
event
|
|
204
|
+
});
|
|
205
|
+
queryVector = emb[0] || [];
|
|
206
|
+
} catch {
|
|
207
|
+
queryVector = new Array(768).fill(0);
|
|
208
|
+
for (let i = 0; i < queryText.length; i++) {
|
|
209
|
+
queryVector[i % 768] = (queryVector[i % 768] + queryText.charCodeAt(i)) / 1e3;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const vectorize = resolveVectorize(event);
|
|
213
|
+
if (vectorize) {
|
|
214
|
+
const res = await vectorize.query(queryVector, {
|
|
215
|
+
topK,
|
|
216
|
+
returnMetadata: "all",
|
|
217
|
+
namespace,
|
|
218
|
+
filter: options?.filter
|
|
219
|
+
});
|
|
220
|
+
const matches = [];
|
|
221
|
+
for (const m of res.matches || []) {
|
|
222
|
+
if (m.score < minScore) continue;
|
|
223
|
+
const meta = m.metadata || {};
|
|
224
|
+
matches.push({
|
|
225
|
+
id: m.id,
|
|
226
|
+
text: meta.text || "",
|
|
227
|
+
documentId: meta.documentId || m.id.split("#chunk-")[0] || m.id,
|
|
228
|
+
chunkIndex: meta.chunkIndex ?? 0,
|
|
229
|
+
totalChunks: meta.totalChunks ?? 1,
|
|
230
|
+
score: m.score,
|
|
231
|
+
metadata: meta
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
return matches;
|
|
235
|
+
} else {
|
|
236
|
+
const store = getDevMockRAGStore();
|
|
237
|
+
const candidates = [];
|
|
238
|
+
for (const item of store.values()) {
|
|
239
|
+
if (namespace && item.namespace !== namespace) continue;
|
|
240
|
+
const sim = cosineSimilarity(queryVector, item.vector);
|
|
241
|
+
const hasKeyword = queryText.toLowerCase().split(/\s+/).some((w) => w.length > 2 && item.text.toLowerCase().includes(w));
|
|
242
|
+
const score = hasKeyword ? Math.max(sim, 0.75) : sim;
|
|
243
|
+
if (score >= minScore) {
|
|
244
|
+
candidates.push({ item, score });
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
candidates.sort((a, b) => b.score - a.score);
|
|
248
|
+
return candidates.slice(0, topK).map(({ item, score }) => ({
|
|
249
|
+
id: item.id,
|
|
250
|
+
text: item.text,
|
|
251
|
+
documentId: item.documentId,
|
|
252
|
+
chunkIndex: item.chunkIndex,
|
|
253
|
+
totalChunks: item.totalChunks,
|
|
254
|
+
score,
|
|
255
|
+
metadata: item.metadata || {}
|
|
256
|
+
}));
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
async retrieveContext(queryText, options) {
|
|
260
|
+
const matches = await this.query(queryText, options);
|
|
261
|
+
if (matches.length === 0) {
|
|
262
|
+
return {
|
|
263
|
+
contextText: "No relevant documents found.",
|
|
264
|
+
matches: []
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
const blocks = matches.map((m, idx) => {
|
|
268
|
+
const title = m.metadata.title || m.documentId;
|
|
269
|
+
const sourceInfo = m.metadata.url ? ` (${m.metadata.url})` : "";
|
|
270
|
+
return `[Source ${idx + 1}: ${title}${sourceInfo} | Relevance: ${(m.score * 100).toFixed(0)}%]
|
|
271
|
+
${m.text}`;
|
|
272
|
+
});
|
|
273
|
+
return {
|
|
274
|
+
contextText: blocks.join("\n\n"),
|
|
275
|
+
matches
|
|
276
|
+
};
|
|
277
|
+
},
|
|
278
|
+
async answer(queryText, options) {
|
|
279
|
+
const { contextText, matches } = await this.retrieveContext(queryText, options);
|
|
280
|
+
const defaultSystem = "You are an intelligent, factual assistant. Answer the user's question accurately based strictly on the provided Context below.\nIf the context does not contain sufficient information to answer the question, state honestly that the documentation does not contain this information.\nCite the relevant Source numbers when quoting facts.";
|
|
281
|
+
const systemPrompt = `${options?.system || defaultSystem}
|
|
282
|
+
|
|
283
|
+
Context:
|
|
284
|
+
${contextText}`;
|
|
285
|
+
let answer = "";
|
|
286
|
+
try {
|
|
287
|
+
answer = await generateText({
|
|
288
|
+
model: llmModel,
|
|
289
|
+
system: systemPrompt,
|
|
290
|
+
prompt: queryText,
|
|
291
|
+
temperature: options?.temperature ?? 0.2,
|
|
292
|
+
maxTokens: options?.maxTokens,
|
|
293
|
+
binding: aiBindingName,
|
|
294
|
+
event: options?.event || config?.event
|
|
295
|
+
});
|
|
296
|
+
} catch (err) {
|
|
297
|
+
answer = `[Dev Mock] Based on ${matches.length} retrieved context sources, here is the answer for: "${queryText}".`;
|
|
298
|
+
}
|
|
299
|
+
return {
|
|
300
|
+
answer,
|
|
301
|
+
sources: matches,
|
|
302
|
+
query: queryText
|
|
303
|
+
};
|
|
304
|
+
},
|
|
305
|
+
asTool(toolOptions) {
|
|
306
|
+
const self = this;
|
|
307
|
+
return defineTool({
|
|
308
|
+
name: toolOptions?.name || "searchKnowledge",
|
|
309
|
+
description: toolOptions?.description || "Search knowledge base and documentation for factual context and technical references.",
|
|
310
|
+
parameters: {
|
|
311
|
+
type: "object",
|
|
312
|
+
properties: {
|
|
313
|
+
query: {
|
|
314
|
+
type: "string",
|
|
315
|
+
description: "The search query or technical keywords to search for"
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
required: ["query"]
|
|
319
|
+
},
|
|
320
|
+
async execute({ query }) {
|
|
321
|
+
const { contextText, matches } = await self.retrieveContext(query, {
|
|
322
|
+
topK: toolOptions?.topK,
|
|
323
|
+
minScore: toolOptions?.minScore
|
|
324
|
+
});
|
|
325
|
+
return {
|
|
326
|
+
resultsCount: matches.length,
|
|
327
|
+
context: contextText
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { AppRateLimitRule } from "../../../types";
|
|
2
|
+
export interface RateLimitCheckResult {
|
|
3
|
+
/** Whether the request is permitted */
|
|
4
|
+
success: boolean;
|
|
5
|
+
/** Number of remaining requests permitted in the current window */
|
|
6
|
+
remaining: number;
|
|
7
|
+
/** Max limit for this window */
|
|
8
|
+
limit: number;
|
|
9
|
+
/** Seconds until the rate limit window resets */
|
|
10
|
+
reset: number;
|
|
11
|
+
}
|
|
12
|
+
export interface CheckRateLimitOptions extends AppRateLimitRule {
|
|
13
|
+
/** Optional custom identifier/key to rate limit against (defaults to client IP + route path) */
|
|
14
|
+
key?: string;
|
|
15
|
+
/** Storage backend override ('auto' | 'kv' | 'memory') */
|
|
16
|
+
backend?: "auto" | "kv" | "memory";
|
|
17
|
+
/** Custom binding name override */
|
|
18
|
+
binding?: string;
|
|
19
|
+
/** Custom error message when rate limit is exceeded */
|
|
20
|
+
message?: string;
|
|
21
|
+
/** Explicit event context */
|
|
22
|
+
event?: any;
|
|
23
|
+
}
|
|
24
|
+
/** Parses duration string (e.g. '10s', '1m', '15m', '1h', '1d') or number into seconds. */
|
|
25
|
+
export declare function parseRateLimitWindow(window: string | number | undefined, defaultSeconds?: number): number;
|
|
26
|
+
/** Extracts the client IP address from request headers or socket. */
|
|
27
|
+
export declare function getClientIp(event: any): string;
|
|
28
|
+
/**
|
|
29
|
+
* Evaluates whether a request or key is within the allowed rate limit.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const res = await checkRateLimit(event, { max: 10, window: "1m" })
|
|
33
|
+
* if (!res.success) {
|
|
34
|
+
* // exceeded
|
|
35
|
+
* }
|
|
36
|
+
*/
|
|
37
|
+
export declare function checkRateLimit(eventOrKey: any, options?: CheckRateLimitOptions): Promise<RateLimitCheckResult>;
|
|
38
|
+
/**
|
|
39
|
+
* Asserts that a request or key is within the rate limit. If exceeded, automatically sets standard
|
|
40
|
+
* rate limit headers and throws an HTTP 429 error.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* await assertRateLimit(event, { max: 5, window: "1m" })
|
|
44
|
+
*/
|
|
45
|
+
export declare function assertRateLimit(eventOrKey: any, options?: CheckRateLimitOptions): Promise<RateLimitCheckResult>;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { createError, getRequestHeader, getRequestURL } from "nuxt/server";
|
|
2
|
+
import { getKVBinding } from "../../kv.mjs";
|
|
3
|
+
import { getRateLimitBinding } from "../../ratelimit.mjs";
|
|
4
|
+
function setResponseHeaderSafe(event, name, value) {
|
|
5
|
+
if (!event) return;
|
|
6
|
+
try {
|
|
7
|
+
if (typeof event.node?.res?.setHeader === "function") {
|
|
8
|
+
event.node.res.setHeader(name, value);
|
|
9
|
+
} else if (event.headers && typeof event.headers.set === "function") {
|
|
10
|
+
event.headers.set(name, value);
|
|
11
|
+
} else if (event.response?.headers && typeof event.response.headers.set === "function") {
|
|
12
|
+
event.response.headers.set(name, value);
|
|
13
|
+
}
|
|
14
|
+
} catch {
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const memoryStore = /* @__PURE__ */ new Map();
|
|
18
|
+
export function parseRateLimitWindow(window, defaultSeconds = 60) {
|
|
19
|
+
if (window === void 0 || window === null) return defaultSeconds;
|
|
20
|
+
if (typeof window === "number") return Math.max(1, Math.floor(window));
|
|
21
|
+
const trimmed = window.trim().toLowerCase();
|
|
22
|
+
const match = trimmed.match(
|
|
23
|
+
/^(\d+(?:\.\d+)?)\s*(s|sec|seconds|m|min|minutes|h|hr|hours|d|days)?$/
|
|
24
|
+
);
|
|
25
|
+
if (!match) {
|
|
26
|
+
const parsed = Number(trimmed);
|
|
27
|
+
return isNaN(parsed) ? defaultSeconds : Math.max(1, Math.floor(parsed));
|
|
28
|
+
}
|
|
29
|
+
const value = parseFloat(match[1]);
|
|
30
|
+
const unit = match[2] || "s";
|
|
31
|
+
switch (unit) {
|
|
32
|
+
case "s":
|
|
33
|
+
case "sec":
|
|
34
|
+
case "seconds":
|
|
35
|
+
return Math.max(1, Math.floor(value));
|
|
36
|
+
case "m":
|
|
37
|
+
case "min":
|
|
38
|
+
case "minutes":
|
|
39
|
+
return Math.max(1, Math.floor(value * 60));
|
|
40
|
+
case "h":
|
|
41
|
+
case "hr":
|
|
42
|
+
case "hours":
|
|
43
|
+
return Math.max(1, Math.floor(value * 3600));
|
|
44
|
+
case "d":
|
|
45
|
+
case "days":
|
|
46
|
+
return Math.max(1, Math.floor(value * 86400));
|
|
47
|
+
default:
|
|
48
|
+
return defaultSeconds;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export function getClientIp(event) {
|
|
52
|
+
if (!event) return "127.0.0.1";
|
|
53
|
+
const cfIp = getRequestHeader(event, "cf-connecting-ip");
|
|
54
|
+
if (cfIp && typeof cfIp === "string" && cfIp.trim()) {
|
|
55
|
+
return cfIp.trim();
|
|
56
|
+
}
|
|
57
|
+
const xForwardedFor = getRequestHeader(event, "x-forwarded-for");
|
|
58
|
+
if (xForwardedFor && typeof xForwardedFor === "string") {
|
|
59
|
+
const firstIp = xForwardedFor.split(",")[0]?.trim();
|
|
60
|
+
if (firstIp) return firstIp;
|
|
61
|
+
}
|
|
62
|
+
const xRealIp = getRequestHeader(event, "x-real-ip");
|
|
63
|
+
if (xRealIp && typeof xRealIp === "string" && xRealIp.trim()) {
|
|
64
|
+
return xRealIp.trim();
|
|
65
|
+
}
|
|
66
|
+
const req = event.node?.req || event;
|
|
67
|
+
return req.socket?.remoteAddress || "127.0.0.1";
|
|
68
|
+
}
|
|
69
|
+
export async function checkRateLimit(eventOrKey, options) {
|
|
70
|
+
const isEvent = eventOrKey && typeof eventOrKey === "object" && ("node" in eventOrKey || "headers" in eventOrKey || "req" in eventOrKey);
|
|
71
|
+
const event = isEvent ? eventOrKey : options?.event;
|
|
72
|
+
const max = options?.max ?? 100;
|
|
73
|
+
const windowSecs = parseRateLimitWindow(options?.window, 60);
|
|
74
|
+
const backend = options?.backend ?? "auto";
|
|
75
|
+
let limitKey;
|
|
76
|
+
if (options?.key) {
|
|
77
|
+
limitKey = options.key;
|
|
78
|
+
} else if (isEvent) {
|
|
79
|
+
const ip = getClientIp(event);
|
|
80
|
+
let pathname = "";
|
|
81
|
+
try {
|
|
82
|
+
pathname = getRequestURL(event).pathname;
|
|
83
|
+
} catch {
|
|
84
|
+
pathname = event.path || "/";
|
|
85
|
+
}
|
|
86
|
+
limitKey = `${ip}:${pathname}`;
|
|
87
|
+
} else if (typeof eventOrKey === "string" && eventOrKey.trim()) {
|
|
88
|
+
limitKey = eventOrKey.trim();
|
|
89
|
+
} else {
|
|
90
|
+
limitKey = "anonymous";
|
|
91
|
+
}
|
|
92
|
+
if (backend === "auto") {
|
|
93
|
+
try {
|
|
94
|
+
const binding = getRateLimitBinding(options?.binding, event);
|
|
95
|
+
if (binding && typeof binding.limit === "function") {
|
|
96
|
+
const result = await binding.limit({ key: limitKey });
|
|
97
|
+
return {
|
|
98
|
+
success: result.success,
|
|
99
|
+
remaining: result.success ? 1 : 0,
|
|
100
|
+
limit: max,
|
|
101
|
+
reset: windowSecs
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
} catch {
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (backend === "kv" || backend === "auto") {
|
|
108
|
+
try {
|
|
109
|
+
const kv = getKVBinding(options?.binding, event);
|
|
110
|
+
if (kv && typeof kv.get === "function") {
|
|
111
|
+
const nowSec = Math.floor(Date.now() / 1e3);
|
|
112
|
+
const bucket = Math.floor(nowSec / windowSecs);
|
|
113
|
+
const kvKey = `_rl:${limitKey}:${bucket}`;
|
|
114
|
+
const raw = await kv.get(kvKey);
|
|
115
|
+
const count = raw ? parseInt(raw, 10) : 0;
|
|
116
|
+
const reset2 = windowSecs - nowSec % windowSecs;
|
|
117
|
+
if (count >= max) {
|
|
118
|
+
return {
|
|
119
|
+
success: false,
|
|
120
|
+
remaining: 0,
|
|
121
|
+
limit: max,
|
|
122
|
+
reset: reset2
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
await kv.put(kvKey, String(count + 1), {
|
|
126
|
+
expirationTtl: Math.max(60, windowSecs * 2)
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
success: true,
|
|
130
|
+
remaining: Math.max(0, max - (count + 1)),
|
|
131
|
+
limit: max,
|
|
132
|
+
reset: reset2
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
} catch {
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const now = Date.now();
|
|
139
|
+
const windowMs = windowSecs * 1e3;
|
|
140
|
+
let timestamps = memoryStore.get(limitKey) || [];
|
|
141
|
+
timestamps = timestamps.filter((t) => now - t < windowMs);
|
|
142
|
+
const reset = timestamps.length > 0 ? Math.ceil((timestamps[0] + windowMs - now) / 1e3) : windowSecs;
|
|
143
|
+
if (timestamps.length >= max) {
|
|
144
|
+
memoryStore.set(limitKey, timestamps);
|
|
145
|
+
return {
|
|
146
|
+
success: false,
|
|
147
|
+
remaining: 0,
|
|
148
|
+
limit: max,
|
|
149
|
+
reset: Math.max(1, reset)
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
timestamps.push(now);
|
|
153
|
+
memoryStore.set(limitKey, timestamps);
|
|
154
|
+
return {
|
|
155
|
+
success: true,
|
|
156
|
+
remaining: Math.max(0, max - timestamps.length),
|
|
157
|
+
limit: max,
|
|
158
|
+
reset: Math.max(1, reset)
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
export async function assertRateLimit(eventOrKey, options) {
|
|
162
|
+
const isEvent = eventOrKey && typeof eventOrKey === "object" && ("node" in eventOrKey || "headers" in eventOrKey || "req" in eventOrKey);
|
|
163
|
+
const event = isEvent ? eventOrKey : options?.event;
|
|
164
|
+
const result = await checkRateLimit(eventOrKey, options);
|
|
165
|
+
if (event) {
|
|
166
|
+
setResponseHeaderSafe(event, "X-RateLimit-Limit", String(result.limit));
|
|
167
|
+
setResponseHeaderSafe(event, "X-RateLimit-Remaining", String(result.remaining));
|
|
168
|
+
setResponseHeaderSafe(event, "X-RateLimit-Reset", String(result.reset));
|
|
169
|
+
}
|
|
170
|
+
if (!result.success) {
|
|
171
|
+
if (event) {
|
|
172
|
+
setResponseHeaderSafe(event, "Retry-After", String(result.reset));
|
|
173
|
+
}
|
|
174
|
+
throw createError({
|
|
175
|
+
statusCode: 429,
|
|
176
|
+
statusMessage: "Too Many Requests",
|
|
177
|
+
message: options?.message || "Rate limit exceeded. Please try again later.",
|
|
178
|
+
data: result
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return result;
|
|
182
|
+
}
|