qarpeo 0.1.18 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/README.md +96 -96
  2. package/dist/chunks/auth-schema.mjs +3 -1
  3. package/dist/chunks/wrangler.mjs +22 -3
  4. package/dist/cli/index.mjs +448 -221
  5. package/dist/fate/index.d.ts +29 -22
  6. package/dist/fate/index.mjs +1 -3
  7. package/dist/module.d.ts +1 -1
  8. package/dist/module.mjs +103 -82
  9. package/dist/runtime/ai.d.ts +2 -2
  10. package/dist/runtime/app/components/BlobImage.vue +119 -107
  11. package/dist/runtime/app/components/CMSBlocks.vue +104 -93
  12. package/dist/runtime/app/components/CMSContent.vue +24 -23
  13. package/dist/runtime/app/components/CMSImage.vue +49 -49
  14. package/dist/runtime/app/components/CMSLocaleSwitcher.vue +110 -110
  15. package/dist/runtime/app/components/CMSPreviewBanner.vue +83 -79
  16. package/dist/runtime/app/components/CMSVersionBanner.vue +53 -49
  17. package/dist/runtime/app/components/CMSVersionSwitcher.vue +140 -140
  18. package/dist/runtime/app/components/ContentRenderer.vue +83 -80
  19. package/dist/runtime/app/components/FileUpload.vue +200 -196
  20. package/dist/runtime/app/components/ImpersonationBanner.vue +61 -57
  21. package/dist/runtime/app/components/QarpeoWelcome.vue +84 -84
  22. package/dist/runtime/app/components/SignedIn.vue +13 -13
  23. package/dist/runtime/app/components/SignedOut.vue +13 -13
  24. package/dist/runtime/app/components/shiki.css +34 -34
  25. package/dist/runtime/app/composables/ai.d.ts +22 -22
  26. package/dist/runtime/app/composables/ai.mjs +3 -7
  27. package/dist/runtime/app/composables/analytics.mjs +1 -1
  28. package/dist/runtime/app/composables/api-tokens.mjs +1 -1
  29. package/dist/runtime/app/composables/auth.d.ts +6 -7
  30. package/dist/runtime/app/composables/auth.mjs +6 -3
  31. package/dist/runtime/app/composables/chat.mjs +3 -7
  32. package/dist/runtime/app/composables/cms-preview.d.ts +3 -3
  33. package/dist/runtime/app/composables/cms-preview.mjs +1 -1
  34. package/dist/runtime/app/composables/cms.d.ts +3 -5
  35. package/dist/runtime/app/composables/cms.mjs +2 -2
  36. package/dist/runtime/app/composables/docs-version.d.ts +8 -7
  37. package/dist/runtime/app/composables/docs-version.mjs +3 -3
  38. package/dist/runtime/app/composables/impersonation.mjs +1 -1
  39. package/dist/runtime/app/composables/notifications.d.ts +5 -5
  40. package/dist/runtime/app/composables/notifications.mjs +4 -5
  41. package/dist/runtime/app/composables/organization.mjs +1 -1
  42. package/dist/runtime/app/composables/passkey.mjs +1 -1
  43. package/dist/runtime/app/composables/passwordless.mjs +1 -1
  44. package/dist/runtime/app/composables/payments.d.ts +2 -1
  45. package/dist/runtime/app/composables/payments.mjs +1 -1
  46. package/dist/runtime/app/composables/realtime.d.ts +13 -13
  47. package/dist/runtime/app/composables/realtime.mjs +2 -2
  48. package/dist/runtime/app/composables/resumable-upload.d.ts +11 -11
  49. package/dist/runtime/app/composables/resumable-upload.mjs +1 -1
  50. package/dist/runtime/app/composables/site.mjs +1 -1
  51. package/dist/runtime/app/composables/storage.d.ts +151 -11
  52. package/dist/runtime/app/composables/storage.mjs +291 -33
  53. package/dist/runtime/app/composables/turnstile.mjs +1 -1
  54. package/dist/runtime/app/composables/two-factor.mjs +1 -1
  55. package/dist/runtime/app/pages/devtools/agents.vue +716 -716
  56. package/dist/runtime/app/pages/devtools/analytics.vue +616 -616
  57. package/dist/runtime/app/pages/devtools/auth.vue +381 -350
  58. package/dist/runtime/app/pages/devtools/blob.vue +743 -744
  59. package/dist/runtime/app/pages/devtools/db.vue +545 -545
  60. package/dist/runtime/app/pages/devtools/domains.vue +771 -771
  61. package/dist/runtime/app/pages/devtools/kv.vue +827 -828
  62. package/dist/runtime/app/pages/devtools/logs.vue +649 -653
  63. package/dist/runtime/app/pages/devtools/mail.vue +388 -388
  64. package/dist/runtime/app/pages/devtools/overview.vue +391 -389
  65. package/dist/runtime/app/pages/devtools/realtime.vue +89 -27
  66. package/dist/runtime/app/pages/devtools/security.vue +20 -5
  67. package/dist/runtime/app/pages/devtools/settings.vue +559 -559
  68. package/dist/runtime/app/pages/devtools/tasks.vue +26 -10
  69. package/dist/runtime/app/pages/devtools.vue +176 -176
  70. package/dist/runtime/app/plugins/seo.mjs +1 -1
  71. package/dist/runtime/app/plugins/shortcuts.client.d.ts +1 -4
  72. package/dist/runtime/app/public/sw-notifications.mjs +47 -52
  73. package/dist/runtime/blob.mjs +11 -4
  74. package/dist/runtime/browser.d.ts +1 -1
  75. package/dist/runtime/browser.mjs +12 -2
  76. package/dist/runtime/cache.d.ts +2 -1
  77. package/dist/runtime/kv.mjs +4 -1
  78. package/dist/runtime/providers/qarpeo.d.ts +3 -3
  79. package/dist/runtime/server/durable-objects/agent.mjs +1 -1
  80. package/dist/runtime/server/durable-objects/room.d.ts +2 -2
  81. package/dist/runtime/server/durable-objects/room.mjs +5 -5
  82. package/dist/runtime/server/middleware/devtools.mjs +6 -2
  83. package/dist/runtime/server/plugins/cms.d.ts +4 -2
  84. package/dist/runtime/server/plugins/dev-proxy.mjs +1 -1
  85. package/dist/runtime/server/routes/__qarpeo/agents/chat.post.d.ts +2 -2
  86. package/dist/runtime/server/routes/__qarpeo/agents/chat.post.mjs +4 -1
  87. package/dist/runtime/server/routes/__qarpeo/analytics/events.get.d.ts +1 -4
  88. package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.d.ts +2 -2
  89. package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.mjs +5 -1
  90. package/dist/runtime/server/routes/__qarpeo/db/tables.get.d.ts +2 -2
  91. package/dist/runtime/server/routes/__qarpeo/db/tables.get.mjs +1 -1
  92. package/dist/runtime/server/routes/__qarpeo/logs.get.d.ts +4 -1
  93. package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +1 -1
  94. package/dist/runtime/server/routes/__qarpeo/mail/track/open/[id].get.mjs +2 -2
  95. package/dist/runtime/server/routes/__qarpeo/overview.get.d.ts +2 -2
  96. package/dist/runtime/server/routes/__qarpeo/realtime/broadcast.post.d.ts +2 -2
  97. package/dist/runtime/server/routes/__qarpeo/realtime/broadcast.post.mjs +1 -1
  98. package/dist/runtime/server/routes/__qarpeo/realtime/clear.post.d.ts +1 -4
  99. package/dist/runtime/server/routes/__qarpeo/realtime/clear.post.mjs +1 -1
  100. package/dist/runtime/server/routes/__qarpeo/realtime/disconnect.post.d.ts +1 -4
  101. package/dist/runtime/server/routes/__qarpeo/realtime/disconnect.post.mjs +1 -1
  102. package/dist/runtime/server/routes/__qarpeo/realtime/room.get.d.ts +2 -2
  103. package/dist/runtime/server/routes/__qarpeo/realtime/rooms.get.d.ts +2 -2
  104. package/dist/runtime/server/routes/__qarpeo/security/analytics.get.d.ts +2 -2
  105. package/dist/runtime/server/routes/__qarpeo/security/ban.post.d.ts +1 -4
  106. package/dist/runtime/server/routes/__qarpeo/security/clear.post.d.ts +1 -4
  107. package/dist/runtime/server/routes/__qarpeo/security/unban.post.d.ts +1 -4
  108. package/dist/runtime/server/routes/__qarpeo/settings.get.mjs +1 -1
  109. package/dist/runtime/server/routes/__qarpeo/tasks/run.post.mjs +3 -1
  110. package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +8 -2
  111. package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +8 -2
  112. package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +8 -2
  113. package/dist/runtime/server/routes/ai/embed.post.d.ts +1 -4
  114. package/dist/runtime/server/routes/ai/search.post.d.ts +2 -2
  115. package/dist/runtime/server/routes/auth/account.delete.mjs +1 -1
  116. package/dist/runtime/server/routes/auth/handler.mjs +6 -1
  117. package/dist/runtime/server/routes/auth/magic-link/verify.get.mjs +1 -1
  118. package/dist/runtime/server/routes/auth/organization/members/[id].delete.mjs +7 -1
  119. package/dist/runtime/server/routes/auth/otp/verify.post.mjs +1 -1
  120. package/dist/runtime/server/routes/auth/sso/login.get.mjs +7 -1
  121. package/dist/runtime/server/routes/auth/sso/oidc/callback.get.mjs +8 -2
  122. package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +7 -2
  123. package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +1 -1
  124. package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +7 -2
  125. package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +6 -1
  126. package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +6 -1
  127. package/dist/runtime/server/routes/browser/crawl.post.d.ts +1 -2
  128. package/dist/runtime/server/routes/browser/invoice.post.d.ts +1 -2
  129. package/dist/runtime/server/routes/browser/og-image.post.d.ts +2 -2
  130. package/dist/runtime/server/routes/browser/pdf.post.d.ts +1 -2
  131. package/dist/runtime/server/routes/browser/pdf.post.mjs +6 -1
  132. package/dist/runtime/server/routes/browser/screenshot.post.d.ts +2 -2
  133. package/dist/runtime/server/routes/browser/screenshot.post.mjs +5 -1
  134. package/dist/runtime/server/routes/cms/components/index.get.d.ts +2 -2
  135. package/dist/runtime/server/routes/cms/preview/disable.get.d.ts +4 -3
  136. package/dist/runtime/server/routes/cms/preview/enable.get.d.ts +8 -8
  137. package/dist/runtime/server/routes/cms/search.get.mjs +1 -1
  138. package/dist/runtime/server/routes/cms/webhooks/[provider].post.d.ts +7 -7
  139. package/dist/runtime/server/routes/cms/webhooks/[provider].post.mjs +9 -2
  140. package/dist/runtime/server/routes/docs/search.get.d.ts +9 -9
  141. package/dist/runtime/server/routes/fate.mjs +5 -8
  142. package/dist/runtime/server/routes/mail/bounce.post.d.ts +2 -2
  143. package/dist/runtime/server/routes/mail/unsubscribe.d.ts +2 -2
  144. package/dist/runtime/server/routes/mail/webhooks.post.d.ts +2 -2
  145. package/dist/runtime/server/routes/mail/webhooks.post.mjs +7 -1
  146. package/dist/runtime/server/routes/payments/usage.get.d.ts +8 -8
  147. package/dist/runtime/server/routes/payments/usage.post.d.ts +2 -2
  148. package/dist/runtime/server/routes/realtime/history.delete.d.ts +4 -3
  149. package/dist/runtime/server/routes/realtime/history.get.d.ts +7 -6
  150. package/dist/runtime/server/routes/realtime/ws.get.mjs +6 -1
  151. package/dist/runtime/server/routes/robots.txt.get.mjs +1 -1
  152. package/dist/runtime/server/routes/sitemap.xml.get.mjs +2 -1
  153. package/dist/runtime/server/routes/storage/multipart/abort.post.d.ts +2 -2
  154. package/dist/runtime/server/routes/storage/multipart/complete.post.d.ts +2 -2
  155. package/dist/runtime/server/routes/storage/multipart/complete.post.mjs +2 -2
  156. package/dist/runtime/server/routes/storage/multipart/create.post.d.ts +2 -2
  157. package/dist/runtime/server/routes/storage/multipart/create.post.mjs +7 -3
  158. package/dist/runtime/server/routes/storage/multipart/part.put.d.ts +2 -2
  159. package/dist/runtime/server/routes/storage/multipart/part.put.mjs +1 -1
  160. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +2 -4
  161. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +2 -4
  162. package/dist/runtime/server/routes/tenants/[tenant]/domains/index.get.mjs +1 -1
  163. package/dist/runtime/server/routes/tenants/[tenant]/domains/index.post.mjs +2 -4
  164. package/dist/runtime/server/tasks/cms/publish.mjs +1 -1
  165. package/dist/runtime/server/utils/ai.d.ts +9 -9
  166. package/dist/runtime/server/utils/ai.mjs +3 -3
  167. package/dist/runtime/server/utils/auth.d.ts +12 -16
  168. package/dist/runtime/server/utils/auth.mjs +15 -9
  169. package/dist/runtime/server/utils/bots.mjs +21 -7
  170. package/dist/runtime/server/utils/browser-utils.d.ts +44 -41
  171. package/dist/runtime/server/utils/browser-utils.mjs +14 -4
  172. package/dist/runtime/server/utils/cache.d.ts +5 -5
  173. package/dist/runtime/server/utils/cms/common.d.ts +26 -0
  174. package/dist/runtime/server/utils/cms/common.mjs +68 -0
  175. package/dist/runtime/server/utils/cms/git.d.ts +24 -0
  176. package/dist/runtime/server/utils/cms/git.mjs +240 -0
  177. package/dist/runtime/server/utils/cms/markdown.d.ts +22 -0
  178. package/dist/runtime/server/utils/cms/markdown.mjs +92 -0
  179. package/dist/runtime/server/utils/cms/path.d.ts +51 -0
  180. package/dist/runtime/server/utils/cms/path.mjs +127 -0
  181. package/dist/runtime/server/utils/cms/search.d.ts +22 -0
  182. package/dist/runtime/server/utils/cms/search.mjs +221 -0
  183. package/dist/runtime/server/utils/cms-events.d.ts +1 -1
  184. package/dist/runtime/server/utils/cms-events.mjs +2 -2
  185. package/dist/runtime/server/utils/cms-filter.mjs +2 -2
  186. package/dist/runtime/server/utils/cms.d.ts +17 -149
  187. package/dist/runtime/server/utils/cms.mjs +52 -761
  188. package/dist/runtime/server/utils/config.d.ts +5 -4
  189. package/dist/runtime/server/utils/domains.mjs +7 -4
  190. package/dist/runtime/server/utils/email-templates.d.ts +10 -7
  191. package/dist/runtime/server/utils/email-templates.mjs +20 -5
  192. package/dist/runtime/server/utils/feed.d.ts +2 -2
  193. package/dist/runtime/server/utils/feed.mjs +3 -1
  194. package/dist/runtime/server/utils/mail-suppression.d.ts +8 -24
  195. package/dist/runtime/server/utils/mail-suppression.mjs +2 -2
  196. package/dist/runtime/server/utils/mail.d.ts +7 -8
  197. package/dist/runtime/server/utils/mail.mjs +17 -12
  198. package/dist/runtime/server/utils/multipart-store.d.ts +2 -2
  199. package/dist/runtime/server/utils/notifications.d.ts +9 -23
  200. package/dist/runtime/server/utils/organization.mjs +4 -12
  201. package/dist/runtime/server/utils/passwordless.mjs +1 -1
  202. package/dist/runtime/server/utils/payments.d.ts +2 -6
  203. package/dist/runtime/server/utils/payments.mjs +1 -1
  204. package/dist/runtime/server/utils/queue.d.ts +21 -31
  205. package/dist/runtime/server/utils/rag.d.ts +4 -4
  206. package/dist/runtime/server/utils/rag.mjs +8 -8
  207. package/dist/runtime/server/utils/realtime-store.d.ts +2 -2
  208. package/dist/runtime/server/utils/realtime.d.ts +26 -28
  209. package/dist/runtime/server/utils/scheduled-task.d.ts +1 -3
  210. package/dist/runtime/server/utils/security-store.d.ts +2 -2
  211. package/dist/runtime/server/utils/session.d.ts +9 -11
  212. package/dist/runtime/server/utils/sso.d.ts +9 -15
  213. package/dist/runtime/server/utils/sso.mjs +4 -8
  214. package/dist/runtime/server/utils/storage.d.ts +19 -2
  215. package/dist/runtime/server/utils/storage.mjs +36 -7
  216. package/dist/runtime/server/utils/tenant.mjs +3 -1
  217. package/dist/runtime/server/utils/turnstile.d.ts +3 -5
  218. package/dist/runtime/server/utils/vapid.d.ts +5 -8
  219. package/dist/runtime/server/utils/vapid.mjs +26 -13
  220. package/dist/runtime/service.d.ts +13 -13
  221. package/dist/runtime/service.mjs +4 -2
  222. package/dist/runtime/test-utils.d.ts +20 -30
  223. package/dist/runtime/test-utils.mjs +5 -4
  224. package/dist/runtime/types/auth-globals.d.ts +14 -14
  225. package/dist/runtime/types/imports.d.ts +82 -82
  226. package/dist/runtime/types/index.d.ts +2 -2
  227. package/dist/runtime/types/r2.d.ts +5 -0
  228. package/dist/runtime/types/service.d.ts +11 -18
  229. package/dist/types.d.ts +100 -107
  230. package/dist/utils/auth-schema.d.ts +2 -2
  231. package/dist/utils/cms-sources.d.ts +3 -3
  232. package/dist/utils/local-db.d.ts +3 -3
  233. package/dist/utils/notifications-schema.d.ts +1 -3
  234. package/dist/utils/pkg.d.ts +7 -0
  235. package/dist/utils/queue.d.ts +3 -3
  236. package/dist/utils/tasks.d.ts +3 -2
  237. package/package.json +11 -8
@@ -1,5 +1,5 @@
1
- import type { AuthOptions, BlobOptions, CMSOptions, PaymentsOptions, AppRateLimitOptions, RealtimeOptions, MailOptions, AnalyticsOptions, MultitenantOptions } from "../../../types";
2
1
  import { type RequestEvent } from "nuxt/server";
2
+ import type { AuthOptions, BlobOptions, CMSOptions, PaymentsOptions, AppRateLimitOptions, RealtimeOptions, MailOptions, AnalyticsOptions, MultitenantOptions } from "../../../types";
3
3
  export interface QarpeoRuntimeConfig {
4
4
  auth: AuthOptions;
5
5
  blob: BlobOptions;
@@ -16,13 +16,14 @@ export interface QarpeoRuntimeConfig {
16
16
  [key: string]: any;
17
17
  }
18
18
  /**
19
- * Returns strongly-typed Qarpeo server runtime configuration without requiring manual `as any` casting.
19
+ * Returns strongly-typed Qarpeo server runtime configuration without requiring manual `as any`
20
+ * casting.
20
21
  */
21
22
  export declare function getQarpeoConfig(event?: RequestEvent): QarpeoRuntimeConfig;
22
23
  /** Alias for getQarpeoConfig */
23
24
  export declare const useQarpeoConfig: typeof getQarpeoConfig;
24
25
  /**
25
- * Returns the application secret (NUXT_APP_SECRET or legacy NUXT_SESSION_PASSWORD) from runtime config.
26
- * Used for HMAC signing where we need a root secret key but not qarpeo-specific config.
26
+ * Returns the application secret (NUXT_APP_SECRET or legacy NUXT_SESSION_PASSWORD) from runtime
27
+ * config. Used for HMAC signing where we need a root secret key but not qarpeo-specific config.
27
28
  */
28
29
  export declare function getSessionSecret(event?: RequestEvent, fallback?: string): string;
@@ -81,11 +81,14 @@ async function callCloudflareHostnamesApi(endpoint, method, body, config) {
81
81
  Authorization: `Bearer ${apiToken}`,
82
82
  "Content-Type": "application/json"
83
83
  };
84
- const res = await fetch(url, {
84
+ const reqInit = {
85
85
  method,
86
- headers,
87
- body: body ? JSON.stringify(body) : void 0
88
- });
86
+ headers
87
+ };
88
+ if (method !== "GET" && body) {
89
+ reqInit.body = JSON.stringify(body);
90
+ }
91
+ const res = await fetch(url, reqInit);
89
92
  const json = await res.json().catch(() => ({}));
90
93
  if (!res.ok || json.success === false) {
91
94
  const err = json.errors?.[0]?.message || `Cloudflare API error ${res.status}`;
@@ -4,11 +4,14 @@ export type { EmailTemplateResult };
4
4
  * Register a typed custom email template.
5
5
  *
6
6
  * @example
7
- * defineEmailTemplate("invoice-ready", (data: { invoiceId: string; amount: string }, branding) => ({
8
- * subject: `Invoice #${data.invoiceId} is ready`,
9
- * html: `<p>Your invoice for ${data.amount} is ready.</p>`,
10
- * text: `Your invoice for ${data.amount} is ready.`,
11
- * }))
7
+ * defineEmailTemplate(
8
+ * "invoice-ready",
9
+ * (data: { invoiceId: string; amount: string }, branding) => ({
10
+ * subject: `Invoice #${data.invoiceId} is ready`,
11
+ * html: `<p>Your invoice for ${data.amount} is ready.</p>`,
12
+ * text: `Your invoice for ${data.amount} is ready.`,
13
+ * }),
14
+ * )
12
15
  */
13
16
  export declare function defineEmailTemplate<T = Record<string, any>>(name: string, handler: EmailTemplateHandler<T>): void;
14
17
  /** Retrieve a registered custom email template by name. */
@@ -26,8 +29,8 @@ export declare function renderEmailLayout(options: {
26
29
  /** Renders a primary call-to-action button HTML. */
27
30
  export declare function renderEmailButton(url: string, label: string, color?: string): string;
28
31
  /**
29
- * Lightweight, zero-dependency Markdown-to-Email renderer.
30
- * Converts markdown into responsive, inline-styled HTML compatible with major email clients.
32
+ * Lightweight, zero-dependency Markdown-to-Email renderer. Converts markdown into responsive,
33
+ * inline-styled HTML compatible with major email clients.
31
34
  */
32
35
  export declare function renderMarkdownEmail(markdown: string, options?: {
33
36
  title?: string;
@@ -100,11 +100,26 @@ export function renderMarkdownEmail(markdown, options) {
100
100
  result = result.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_, label, url) => {
101
101
  return `<a href="${sanitizeUrl(url)}" target="_blank" style="color: ${brandColor}; text-decoration: underline; font-weight: 500;">${label}</a>`;
102
102
  });
103
- result = result.replace(/\*\*\*([^*]+)\*\*\*/g, `<strong style="font-weight: 700;"><em style="font-style: italic;">$1</em></strong>`);
104
- result = result.replace(/\*\*([^*]+)\*\*/g, `<strong style="font-weight: 700; color: #0f172a;">$1</strong>`);
105
- result = result.replace(/(?:^|\s)\*([^*]+)\*(?:\s|$)/g, ` <em style="font-style: italic; color: #475569;">$1</em> `);
106
- result = result.replace(/(?:^|\s)_([^_]+)_(?:\s|$)/g, ` <em style="font-style: italic; color: #475569;">$1</em> `);
107
- result = result.replace(/`([^`]+)`/g, `<code style="background-color: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-family: monospace; font-size: 13px; color: #0f172a;">$1</code>`);
103
+ result = result.replace(
104
+ /\*\*\*([^*]+)\*\*\*/g,
105
+ `<strong style="font-weight: 700;"><em style="font-style: italic;">$1</em></strong>`
106
+ );
107
+ result = result.replace(
108
+ /\*\*([^*]+)\*\*/g,
109
+ `<strong style="font-weight: 700; color: #0f172a;">$1</strong>`
110
+ );
111
+ result = result.replace(
112
+ /(?:^|\s)\*([^*]+)\*(?:\s|$)/g,
113
+ ` <em style="font-style: italic; color: #475569;">$1</em> `
114
+ );
115
+ result = result.replace(
116
+ /(?:^|\s)_([^_]+)_(?:\s|$)/g,
117
+ ` <em style="font-style: italic; color: #475569;">$1</em> `
118
+ );
119
+ result = result.replace(
120
+ /`([^`]+)`/g,
121
+ `<code style="background-color: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-family: monospace; font-size: 13px; color: #0f172a;">$1</code>`
122
+ );
108
123
  return result;
109
124
  }
110
125
  for (let i = 0; i < lines.length; i++) {
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Shared utilities for RSS 2.0 and Atom 1.0 feed generation.
3
- * Edge-native — no external packages, runs on Cloudflare Workers.
2
+ * Shared utilities for RSS 2.0 and Atom 1.0 feed generation. Edge-native — no external packages,
3
+ * runs on Cloudflare Workers.
4
4
  */
5
5
  export interface FeedEntry {
6
6
  id: string;
@@ -143,7 +143,9 @@ export function rowToFeedEntry(row, baseUrl) {
143
143
  if (Array.isArray(parsed)) tags.push(...parsed.map(String));
144
144
  } catch {
145
145
  if (typeof row.tags === "string") {
146
- tags.push(...row.tags.split(",").map((t) => t.trim()).filter(Boolean));
146
+ tags.push(
147
+ ...row.tags.split(",").map((t) => t.trim()).filter(Boolean)
148
+ );
147
149
  }
148
150
  }
149
151
  }
@@ -1,26 +1,18 @@
1
1
  import type { RequestEvent } from "nuxt/server";
2
2
  import type { MailSuppressionReason, MailSuppressionRecord, MailSuppressionType, MailUnsubscribeOptions } from "../../../types";
3
3
  export declare function ensureMailSuppressionsTable(db: any): Promise<void>;
4
- /**
5
- * Generates an HMAC-signed one-click unsubscribe token.
6
- */
4
+ /** Generates an HMAC-signed one-click unsubscribe token. */
7
5
  export declare function generateUnsubscribeToken(email: string, secret?: string): Promise<string>;
8
- /**
9
- * Verifies an HMAC-signed unsubscribe token and extracts the email address.
10
- */
6
+ /** Verifies an HMAC-signed unsubscribe token and extracts the email address. */
11
7
  export declare function verifyUnsubscribeToken(token: string, secret?: string): Promise<string | null>;
12
- /**
13
- * Builds RFC 2369 and RFC 8058 compliant `List-Unsubscribe` headers.
14
- */
8
+ /** Builds RFC 2369 and RFC 8058 compliant `List-Unsubscribe` headers. */
15
9
  export declare function buildListUnsubscribeHeaders(options: {
16
10
  to: string;
17
11
  baseUrl: string;
18
12
  config?: MailUnsubscribeOptions;
19
13
  secret?: string;
20
14
  }): Promise<Record<string, string>>;
21
- /**
22
- * Adds an email address to the suppression list.
23
- */
15
+ /** Adds an email address to the suppression list. */
24
16
  export declare function suppressEmail(event: RequestEvent, options: {
25
17
  email: string;
26
18
  reason?: MailSuppressionReason;
@@ -28,22 +20,16 @@ export declare function suppressEmail(event: RequestEvent, options: {
28
20
  source?: string;
29
21
  metadata?: Record<string, any>;
30
22
  }): Promise<MailSuppressionRecord>;
31
- /**
32
- * Checks whether an email address is suppressed.
33
- */
23
+ /** Checks whether an email address is suppressed. */
34
24
  export declare function isEmailSuppressed(event: RequestEvent | undefined, email: string): Promise<{
35
25
  suppressed: boolean;
36
26
  reason?: MailSuppressionReason;
37
27
  type?: MailSuppressionType;
38
28
  record?: MailSuppressionRecord;
39
29
  }>;
40
- /**
41
- * Removes an email address from the suppression list.
42
- */
30
+ /** Removes an email address from the suppression list. */
43
31
  export declare function unsuppressEmail(event: RequestEvent, email: string): Promise<boolean>;
44
- /**
45
- * Lists suppressed emails with pagination and optional search filter.
46
- */
32
+ /** Lists suppressed emails with pagination and optional search filter. */
47
33
  export declare function listSuppressedEmails(event: RequestEvent, options?: {
48
34
  limit?: number;
49
35
  offset?: number;
@@ -54,9 +40,7 @@ export declare function listSuppressedEmails(event: RequestEvent, options?: {
54
40
  items: MailSuppressionRecord[];
55
41
  total: number;
56
42
  }>;
57
- /**
58
- * Tracks soft bounces and promotes to suppression if threshold is reached.
59
- */
43
+ /** Tracks soft bounces and promotes to suppression if threshold is reached. */
60
44
  export declare function recordSoftBounce(event: RequestEvent, email: string, threshold?: number): Promise<{
61
45
  suppressed: boolean;
62
46
  count: number;
@@ -23,7 +23,7 @@ export async function ensureMailSuppressionsTable(db) {
23
23
  )`
24
24
  ).run();
25
25
  _tableEnsured = true;
26
- } catch (err) {
26
+ } catch {
27
27
  _tableEnsured = true;
28
28
  }
29
29
  }
@@ -147,7 +147,7 @@ export async function suppressEmail(event, options) {
147
147
  now
148
148
  ).run();
149
149
  }
150
- } catch (dbErr) {
150
+ } catch {
151
151
  }
152
152
  const nitroApp = globalThis.useNitroApp?.();
153
153
  if (nitroApp && typeof nitroApp.hooks?.callHook === "function") {
@@ -34,9 +34,7 @@ export declare function recordEmailOpen(id: string): boolean;
34
34
  export declare function recordEmailClick(id: string, url: string): boolean;
35
35
  /** Record a bounce event for a message. */
36
36
  export declare function recordEmailBounce(id: string, reason?: string): boolean;
37
- /**
38
- * Injects open tracking pixel and click tracking redirect URLs into HTML email content.
39
- */
37
+ /** Injects open tracking pixel and click tracking redirect URLs into HTML email content. */
40
38
  export declare function injectEmailTracking(html: string, options: {
41
39
  messageId: string;
42
40
  baseUrl: string;
@@ -44,8 +42,8 @@ export declare function injectEmailTracking(html: string, options: {
44
42
  clicks?: boolean;
45
43
  }): string;
46
44
  /**
47
- * Direct delivery executor using Cloudflare send_email binding or external providers.
48
- * Used internally for immediate sends, waitUntil backgrounds, and queue consumer workers.
45
+ * Direct delivery executor using Cloudflare send_email binding or external providers. Used
46
+ * internally for immediate sends, waitUntil backgrounds, and queue consumer workers.
49
47
  */
50
48
  export declare function deliverMailDirect(options: {
51
49
  from: string;
@@ -62,15 +60,16 @@ export declare function deliverMailDirect(options: {
62
60
  apiKey?: string;
63
61
  }, event?: RequestEvent): Promise<string>;
64
62
  /**
65
- * High-level transactional mail sender with template rendering, markdown support,
66
- * open/click tracking, queue-backed delivery, and dev mailbox capture.
63
+ * High-level transactional mail sender with template rendering, markdown support, open/click
64
+ * tracking, queue-backed delivery, and dev mailbox capture.
67
65
  *
68
66
  * @example
69
67
  * // Markdown content:
70
68
  * await sendMail({
71
69
  * to: "user@example.com",
72
70
  * subject: "Welcome to Acme",
73
- * markdown: "# Welcome!\nWe are glad you joined us.\n\n[btn: Go to Dashboard](https://myapp.com)",
71
+ * markdown:
72
+ * "# Welcome!\nWe are glad you joined us.\n\n[btn: Go to Dashboard](https://myapp.com)",
74
73
  * })
75
74
  *
76
75
  * // Template:
@@ -2,10 +2,7 @@ import { resolveRuntimeBinding } from "../../bindings.mjs";
2
2
  import { sendEmail } from "../../email.mjs";
3
3
  import { useQueue } from "../../queue.mjs";
4
4
  import { renderEmailTemplate, renderMarkdownEmail } from "./email-templates.mjs";
5
- import {
6
- buildListUnsubscribeHeaders,
7
- isEmailSuppressed
8
- } from "./mail-suppression.mjs";
5
+ import { buildListUnsubscribeHeaders, isEmailSuppressed } from "./mail-suppression.mjs";
9
6
  function getSharedMailbox() {
10
7
  return globalThis.__qarpeo_dev_mailbox__ ||= [];
11
8
  }
@@ -44,13 +41,16 @@ export function injectEmailTracking(html, options) {
44
41
  let result = html;
45
42
  const base = options.baseUrl.replace(/\/$/, "");
46
43
  if (options.clicks !== false) {
47
- result = result.replace(/<a\b([^>]*)\bhref=["']([^"']+)["']([^>]*)>/gi, (match, prefix, href, suffix) => {
48
- if (/^(?:mailto:|tel:|#|javascript:)/i.test(href) || href.includes("/__qarpeo/mail/track/")) {
49
- return match;
44
+ result = result.replace(
45
+ /<a\b([^>]*)\bhref=["']([^"']+)["']([^>]*)>/gi,
46
+ (match, prefix, href, suffix) => {
47
+ if (/^(?:mailto:|tel:|#|javascript:)/i.test(href) || href.includes("/__qarpeo/mail/track/")) {
48
+ return match;
49
+ }
50
+ const trackUrl = `${base}/__qarpeo/mail/track/click/${encodeURIComponent(options.messageId)}?url=${encodeURIComponent(href)}`;
51
+ return `<a${prefix}href="${trackUrl}"${suffix}>`;
50
52
  }
51
- const trackUrl = `${base}/__qarpeo/mail/track/click/${encodeURIComponent(options.messageId)}?url=${encodeURIComponent(href)}`;
52
- return `<a${prefix}href="${trackUrl}"${suffix}>`;
53
- });
53
+ );
54
54
  }
55
55
  if (options.opens !== false) {
56
56
  const pixelUrl = `${base}/__qarpeo/mail/track/open/${encodeURIComponent(options.messageId)}`;
@@ -201,7 +201,7 @@ export async function sendMail(request, event) {
201
201
  }
202
202
  const unsubsConfig = typeof mailConfig.unsubscribe === "object" ? mailConfig.unsubscribe : {};
203
203
  const shouldAddUnsubscribe = mailConfig.unsubscribe !== false && unsubsConfig.enabled !== false && request.unsubscribe !== false;
204
- const effectiveHeaders = { ...request.headers || {} };
204
+ const effectiveHeaders = { ...request.headers };
205
205
  if (shouldAddUnsubscribe && activeRecipients.length > 0) {
206
206
  const trackConfig2 = mailConfig.tracking || {};
207
207
  const baseUrl = trackConfig2.baseUrl || (event?.node?.req?.headers?.host ? `http://${event.node.req.headers.host}` : "") || runtimeConfig.public?.qarpeo?.site?.url || "http://localhost:3000";
@@ -325,7 +325,12 @@ export async function sendMail(request, event) {
325
325
  (err) => console.error(`[qarpeo:mail] Async ${provider} delivery failed:`, err?.message || err)
326
326
  )
327
327
  );
328
- return { success: true, messageId, timestamp, suppressedRecipients: suppressedRecipients.length > 0 ? suppressedRecipients : void 0 };
328
+ return {
329
+ success: true,
330
+ messageId,
331
+ timestamp,
332
+ suppressedRecipients: suppressedRecipients.length > 0 ? suppressedRecipients : void 0
333
+ };
329
334
  }
330
335
  try {
331
336
  const finalId = await sendDirectPromise;
@@ -1,6 +1,6 @@
1
1
  /**
2
- * In-memory storage for active R2 multipart upload sessions.
3
- * Supports local development preview and mock testing across Vite/Nitro reloads.
2
+ * In-memory storage for active R2 multipart upload sessions. Supports local development preview and
3
+ * mock testing across Vite/Nitro reloads.
4
4
  */
5
5
  import type { BlobAccessTier, ResumableUploadSession } from "../../../types";
6
6
  export interface DevMultipartPart {
@@ -1,8 +1,8 @@
1
1
  import type { RequestEvent } from "nuxt/server";
2
2
  import type { NotificationRecord, PushSubscriptionRecord, SendNotificationRequest } from "../../../types";
3
3
  /**
4
- * Send a notification via one or more channels (in-app, push, email).
5
- * Persists to D1 for in-app channel.
4
+ * Send a notification via one or more channels (in-app, push, email). Persists to D1 for in-app
5
+ * channel.
6
6
  */
7
7
  export declare function sendNotification(request: SendNotificationRequest, event?: RequestEvent): Promise<void>;
8
8
  /** Alias for sendNotification */
@@ -13,37 +13,23 @@ export interface GetNotificationsOptions {
13
13
  unreadOnly?: boolean;
14
14
  tenantId?: string;
15
15
  }
16
- /**
17
- * Get paginated notifications for a user from D1.
18
- */
16
+ /** Get paginated notifications for a user from D1. */
19
17
  export declare function getNotifications(userId: string, options?: GetNotificationsOptions, event?: RequestEvent): Promise<{
20
18
  notifications: NotificationRecord[];
21
19
  total: number;
22
20
  unread: number;
23
21
  }>;
24
- /**
25
- * Mark a single notification as read.
26
- */
22
+ /** Mark a single notification as read. */
27
23
  export declare function markNotificationRead(id: string, userId: string, event?: RequestEvent): Promise<void>;
28
- /**
29
- * Mark all notifications as read for a user.
30
- */
24
+ /** Mark all notifications as read for a user. */
31
25
  export declare function markAllNotificationsRead(userId: string, event?: RequestEvent): Promise<void>;
32
- /**
33
- * Delete a notification.
34
- */
26
+ /** Delete a notification. */
35
27
  export declare function deleteNotification(id: string, userId: string, event?: RequestEvent): Promise<void>;
36
- /**
37
- * Save a Web Push subscription for a user.
38
- */
28
+ /** Save a Web Push subscription for a user. */
39
29
  export declare function savePushSubscription(userId: string, subscription: PushSubscriptionRecord, tenantId?: string, event?: RequestEvent): Promise<void>;
40
- /**
41
- * Remove a Web Push subscription by endpoint.
42
- */
30
+ /** Remove a Web Push subscription by endpoint. */
43
31
  export declare function removePushSubscription(endpoint: string, event?: RequestEvent): Promise<void>;
44
- /**
45
- * Send a Web Push notification to all subscriptions for a user.
46
- */
32
+ /** Send a Web Push notification to all subscriptions for a user. */
47
33
  export declare function sendWebPush(userId: string, payload: {
48
34
  title: string;
49
35
  body?: string;
@@ -53,9 +53,7 @@ export async function createOrganization(event, input) {
53
53
  createdAt: now
54
54
  };
55
55
  await d1.batch([
56
- d1.prepare(
57
- "INSERT INTO organization (id, name, slug, logo, created_at) VALUES (?, ?, ?, ?, ?)"
58
- ).bind(
56
+ d1.prepare("INSERT INTO organization (id, name, slug, logo, created_at) VALUES (?, ?, ?, ?, ?)").bind(
59
57
  organization.id,
60
58
  organization.name,
61
59
  organization.slug,
@@ -103,9 +101,7 @@ export async function switchActiveOrganization(event, organizationId) {
103
101
  }
104
102
  const d1 = getD1(event);
105
103
  await ensureAuthTables(d1);
106
- const member = await d1.prepare(
107
- "SELECT id, role FROM member WHERE organization_id = ? AND user_id = ? LIMIT 1"
108
- ).bind(organizationId, user.id).first();
104
+ const member = await d1.prepare("SELECT id, role FROM member WHERE organization_id = ? AND user_id = ? LIMIT 1").bind(organizationId, user.id).first();
109
105
  if (!member) {
110
106
  throw createError({
111
107
  statusCode: 403,
@@ -240,9 +236,7 @@ export async function removeOrganizationMember(event, input) {
240
236
  }
241
237
  const d1 = getD1(event);
242
238
  await ensureAuthTables(d1);
243
- const callerMember = await d1.prepare(
244
- "SELECT id, role FROM member WHERE organization_id = ? AND user_id = ? LIMIT 1"
245
- ).bind(input.organizationId, user.id).first();
239
+ const callerMember = await d1.prepare("SELECT id, role FROM member WHERE organization_id = ? AND user_id = ? LIMIT 1").bind(input.organizationId, user.id).first();
246
240
  if (!callerMember) {
247
241
  throw createError({
248
242
  statusCode: 403,
@@ -266,9 +260,7 @@ export async function removeOrganizationMember(event, input) {
266
260
  throw createError({ statusCode: 403, statusMessage: "Forbidden", message: "Permission denied" });
267
261
  }
268
262
  if (targetMember.role === "owner") {
269
- const ownerCount = await d1.prepare(
270
- "SELECT count(*) as count FROM member WHERE organization_id = ? AND role = 'owner'"
271
- ).bind(input.organizationId).first();
263
+ const ownerCount = await d1.prepare("SELECT count(*) as count FROM member WHERE organization_id = ? AND role = 'owner'").bind(input.organizationId).first();
272
264
  if ((ownerCount?.count || 0) <= 1) {
273
265
  throw createError({
274
266
  statusCode: 400,
@@ -1,8 +1,8 @@
1
1
  import { useNitroApp } from "nitro/app";
2
2
  import { getRequestURL, createError } from "nuxt/server";
3
- import { getQarpeoConfig } from "./config.mjs";
4
3
  import { sendEmail } from "../../email.mjs";
5
4
  import { getKVBinding } from "../../kv.mjs";
5
+ import { getQarpeoConfig } from "./config.mjs";
6
6
  import { escapeHtml, sanitizeUrl } from "./email-templates.mjs";
7
7
  import { assertRateLimit } from "./ratelimit.mjs";
8
8
  import { hashSessionToken } from "./session.mjs";
@@ -106,13 +106,9 @@ export declare function checkLimit(event: RequestEvent, limitKey: string, curren
106
106
  limit: number;
107
107
  current: number;
108
108
  }>;
109
- /**
110
- * Records a metered usage event in D1 and reports to upstream provider (e.g. Stripe Meters API).
111
- */
109
+ /** Records a metered usage event in D1 and reports to upstream provider (e.g. Stripe Meters API). */
112
110
  export declare function reportUsage(event: RequestEvent, options: MeterRecordOptions): Promise<MeterUsageResult>;
113
- /**
114
- * Queries metered usage summary and records from D1 for a user or organization.
115
- */
111
+ /** Queries metered usage summary and records from D1 for a user or organization. */
116
112
  export declare function getUsageSummary(event: RequestEvent, options: {
117
113
  eventName?: string;
118
114
  userId?: string;
@@ -589,7 +589,7 @@ export async function createCheckoutSession(event, options) {
589
589
  const cancelUrl = options.cancelUrl || config.checkoutUrls?.cancel || `${siteUrl}/?checkout=cancelled`;
590
590
  const metadata = {
591
591
  planId,
592
- ...options.metadata || {}
592
+ ...options.metadata
593
593
  };
594
594
  if (user?.id) metadata.userId = user.id;
595
595
  if (auth?.organization?.id) metadata.orgId = auth.organization.id;
@@ -21,13 +21,11 @@ export interface QueueConsumerContext {
21
21
  export type QueueMessageHandler<T = any> = (message: QueueMessage<T>, context: QueueConsumerContext) => Promise<void> | void;
22
22
  export type QueueBatchHandler<T = any> = (batch: QueueMessageBatch<T>, context: QueueConsumerContext) => Promise<void> | void;
23
23
  export interface QueueConsumerOptions<T = any> {
24
- /**
25
- * Filter messages to only run for a specific queue name.
26
- */
24
+ /** Filter messages to only run for a specific queue name. */
27
25
  queue?: string;
28
26
  /**
29
- * Maximum number of messages to process concurrently in chunks.
30
- * Prevents overwhelming CPU or connection pools when batches contain many messages.
27
+ * Maximum number of messages to process concurrently in chunks. Prevents overwhelming CPU or
28
+ * connection pools when batches contain many messages.
31
29
  *
32
30
  * @default 10
33
31
  */
@@ -42,25 +40,19 @@ export interface QueueConsumerOptions<T = any> {
42
40
  * Delay in seconds for retries. Can be a fixed number or a function computing backoff.
43
41
  *
44
42
  * @example
45
- * (attempt) => Math.min(3600, Math.pow(2, attempt) * 5)
43
+ * ;(attempt) => Math.min(3600, Math.pow(2, attempt) * 5)
46
44
  */
47
45
  retryDelaySeconds?: number | ((attempt: number) => number);
48
- /**
49
- * Cloudflare Queue binding or queue name to route permanently failed messages to.
50
- */
46
+ /** Cloudflare Queue binding or queue name to route permanently failed messages to. */
51
47
  deadLetterQueue?: string;
52
- /**
53
- * Callback hook executed when a message exceeds maxRetries and is about to be dead-lettered.
54
- */
48
+ /** Callback hook executed when a message exceeds maxRetries and is about to be dead-lettered. */
55
49
  onDeadLetter?: (message: QueueMessage<T>, error: Error, context: QueueConsumerContext) => Promise<void> | void;
56
50
  /**
57
- * Message-by-message processing handler.
58
- * Automatically handles individual message acknowledgment and retry tracking.
51
+ * Message-by-message processing handler. Automatically handles individual message acknowledgment
52
+ * and retry tracking.
59
53
  */
60
54
  handler?: QueueMessageHandler<T>;
61
- /**
62
- * Batch processing handler for processing the entire batch at once.
63
- */
55
+ /** Batch processing handler for processing the entire batch at once. */
64
56
  batchHandler?: QueueBatchHandler<T>;
65
57
  }
66
58
  export interface QueueConsumer<T = any> {
@@ -69,28 +61,26 @@ export interface QueueConsumer<T = any> {
69
61
  (batch: QueueMessageBatch<T>, env?: any, ctx?: any): Promise<void>;
70
62
  }
71
63
  /**
72
- * Define a typed Cloudflare Queue consumer with automatic batch chunking,
73
- * retry tracking, and Dead Letter Queue (DLQ) routing.
64
+ * Define a typed Cloudflare Queue consumer with automatic batch chunking, retry tracking, and Dead
65
+ * Letter Queue (DLQ) routing.
74
66
  *
75
67
  * @example
76
- * ```ts
77
- * // server/queue.ts or server/queues/orders.ts
78
- * export default defineQueueConsumer({
68
+ * ```ts
69
+ * // server/queue.ts or server/queues/orders.ts
70
+ * export default defineQueueConsumer({
79
71
  * batchSize: 5,
80
72
  * maxRetries: 3,
81
73
  * deadLetterQueue: "ORDERS_DLQ",
82
74
  * async handler(message, ctx) {
83
- * console.log(`Processing order ${message.body.id}, attempt ${message.attempts}`)
84
- * await processOrder(message.body)
75
+ * console.log(`Processing order ${message.body.id}, attempt ${message.attempts}`)
76
+ * await processOrder(message.body)
85
77
  * },
86
78
  * async onDeadLetter(message, err) {
87
- * console.error(`Order ${message.id} failed after retries:`, err.message)
88
- * }
89
- * })
90
- * ```
79
+ * console.error(`Order ${message.id} failed after retries:`, err.message)
80
+ * },
81
+ * })
82
+ * ```
91
83
  */
92
84
  export declare function defineQueueConsumer<T = any>(optionsOrHandler: QueueConsumerOptions<T> | QueueMessageHandler<T> | QueueBatchHandler<T>, maybeOptions?: Omit<QueueConsumerOptions<T>, "handler">): QueueConsumer<T>;
93
- /**
94
- * Backward-compatible alias for defineQueueConsumer.
95
- */
85
+ /** Backward-compatible alias for defineQueueConsumer. */
96
86
  export declare const defineQueueHandler: typeof defineQueueConsumer;
@@ -1,13 +1,13 @@
1
1
  import type { ChunkOptions, RAGPipelineConfig, RAGPipeline } from "../../../types";
2
2
  export type { ChunkOptions, RAGDocument, RAGChunk, RAGChunkMatch, RAGPipelineConfig, RAGQueryOptions, RAGContextResult, RAGAnswerOptions, RAGAnswerResult, RAGPipeline, } from "../../../types";
3
3
  /**
4
- * Splits raw text into overlapping contextual chunks respecting paragraph,
5
- * sentence, and word boundaries.
4
+ * Splits raw text into overlapping contextual chunks respecting paragraph, sentence, and word
5
+ * boundaries.
6
6
  */
7
7
  export declare function splitTextIntoChunks(text: string, options?: ChunkOptions): string[];
8
8
  /**
9
- * Creates an edge-native RAG (Retrieval-Augmented Generation) pipeline backed by
10
- * Cloudflare Vectorize and Workers AI.
9
+ * Creates an edge-native RAG (Retrieval-Augmented Generation) pipeline backed by Cloudflare
10
+ * Vectorize and Workers AI.
11
11
  *
12
12
  * @example
13
13
  * // server/utils/rag.ts
@@ -91,7 +91,7 @@ export function createRAGPipeline(config) {
91
91
  return null;
92
92
  }
93
93
  }
94
- return {
94
+ const pipeline = {
95
95
  chunkText(text, options) {
96
96
  return splitTextIntoChunks(text, { ...defaultChunking, ...options });
97
97
  },
@@ -111,7 +111,7 @@ export function createRAGPipeline(config) {
111
111
  });
112
112
  } catch {
113
113
  embeddings = chunkTexts.map((txt) => {
114
- const vec = new Array(768).fill(0);
114
+ const vec = Array.from({ length: 768 }, () => 0);
115
115
  for (let i = 0; i < txt.length; i++) {
116
116
  vec[i % 768] = (vec[i % 768] + txt.charCodeAt(i)) / 1e3;
117
117
  }
@@ -120,9 +120,9 @@ export function createRAGPipeline(config) {
120
120
  }
121
121
  const vectors = chunkTexts.map((text, i) => {
122
122
  const chunkId = `${doc.id}#chunk-${i}`;
123
- const values = embeddings[i] || new Array(768).fill(0);
123
+ const values = embeddings[i] || Array.from({ length: 768 }, () => 0);
124
124
  const metadata = {
125
- ...doc.metadata || {},
125
+ ...doc.metadata,
126
126
  documentId: doc.id,
127
127
  chunkIndex: i,
128
128
  totalChunks: chunkTexts.length,
@@ -204,7 +204,7 @@ export function createRAGPipeline(config) {
204
204
  });
205
205
  queryVector = emb[0] || [];
206
206
  } catch {
207
- queryVector = new Array(768).fill(0);
207
+ queryVector = Array.from({ length: 768 }, () => 0);
208
208
  for (let i = 0; i < queryText.length; i++) {
209
209
  queryVector[i % 768] = (queryVector[i % 768] + queryText.charCodeAt(i)) / 1e3;
210
210
  }
@@ -293,7 +293,7 @@ ${contextText}`;
293
293
  binding: aiBindingName,
294
294
  event: options?.event || config?.event
295
295
  });
296
- } catch (err) {
296
+ } catch {
297
297
  answer = `[Dev Mock] Based on ${matches.length} retrieved context sources, here is the answer for: "${queryText}".`;
298
298
  }
299
299
  return {
@@ -303,7 +303,6 @@ ${contextText}`;
303
303
  };
304
304
  },
305
305
  asTool(toolOptions) {
306
- const self = this;
307
306
  return defineTool({
308
307
  name: toolOptions?.name || "searchKnowledge",
309
308
  description: toolOptions?.description || "Search knowledge base and documentation for factual context and technical references.",
@@ -318,7 +317,7 @@ ${contextText}`;
318
317
  required: ["query"]
319
318
  },
320
319
  async execute({ query }) {
321
- const { contextText, matches } = await self.retrieveContext(query, {
320
+ const { contextText, matches } = await pipeline.retrieveContext(query, {
322
321
  topK: toolOptions?.topK,
323
322
  minScore: toolOptions?.minScore
324
323
  });
@@ -330,4 +329,5 @@ ${contextText}`;
330
329
  });
331
330
  }
332
331
  };
332
+ return pipeline;
333
333
  }