@nuasite/cms 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/README.md +237 -0
  2. package/dist/src/build-processor.d.ts +20 -0
  3. package/dist/src/build-processor.d.ts.map +1 -0
  4. package/dist/src/collection-scanner.d.ts +6 -0
  5. package/dist/src/collection-scanner.d.ts.map +1 -0
  6. package/dist/src/component-registry.d.ts +63 -0
  7. package/dist/src/component-registry.d.ts.map +1 -0
  8. package/dist/src/config.d.ts +24 -0
  9. package/dist/src/config.d.ts.map +1 -0
  10. package/dist/src/dev-middleware.d.ts +20 -0
  11. package/dist/src/dev-middleware.d.ts.map +1 -0
  12. package/dist/src/editor/ai.d.ts +60 -0
  13. package/dist/src/editor/ai.d.ts.map +1 -0
  14. package/dist/src/editor/api.d.ts +140 -0
  15. package/dist/src/editor/api.d.ts.map +1 -0
  16. package/dist/src/editor/color-utils.d.ts +106 -0
  17. package/dist/src/editor/color-utils.d.ts.map +1 -0
  18. package/dist/src/editor/components/ai-chat.d.ts +11 -0
  19. package/dist/src/editor/components/ai-chat.d.ts.map +1 -0
  20. package/dist/src/editor/components/ai-tooltip.d.ts +12 -0
  21. package/dist/src/editor/components/ai-tooltip.d.ts.map +1 -0
  22. package/dist/src/editor/components/attribute-editor.d.ts +5 -0
  23. package/dist/src/editor/components/attribute-editor.d.ts.map +1 -0
  24. package/dist/src/editor/components/block-editor.d.ts +12 -0
  25. package/dist/src/editor/components/block-editor.d.ts.map +1 -0
  26. package/dist/src/editor/components/collections-browser.d.ts +2 -0
  27. package/dist/src/editor/components/collections-browser.d.ts.map +1 -0
  28. package/dist/src/editor/components/color-toolbar.d.ts +12 -0
  29. package/dist/src/editor/components/color-toolbar.d.ts.map +1 -0
  30. package/dist/src/editor/components/confirm-dialog.d.ts +2 -0
  31. package/dist/src/editor/components/confirm-dialog.d.ts.map +1 -0
  32. package/dist/src/editor/components/create-page-modal.d.ts +2 -0
  33. package/dist/src/editor/components/create-page-modal.d.ts.map +1 -0
  34. package/dist/src/editor/components/editable-highlights.d.ts +9 -0
  35. package/dist/src/editor/components/editable-highlights.d.ts.map +1 -0
  36. package/dist/src/editor/components/error-boundary.d.ts +32 -0
  37. package/dist/src/editor/components/error-boundary.d.ts.map +1 -0
  38. package/dist/src/editor/components/fields.d.ts +75 -0
  39. package/dist/src/editor/components/fields.d.ts.map +1 -0
  40. package/dist/src/editor/components/frontmatter-fields.d.ts +29 -0
  41. package/dist/src/editor/components/frontmatter-fields.d.ts.map +1 -0
  42. package/dist/src/editor/components/highlight-overlay.d.ts +64 -0
  43. package/dist/src/editor/components/highlight-overlay.d.ts.map +1 -0
  44. package/dist/src/editor/components/image-overlay.d.ts +12 -0
  45. package/dist/src/editor/components/image-overlay.d.ts.map +1 -0
  46. package/dist/src/editor/components/markdown-editor-overlay.d.ts +6 -0
  47. package/dist/src/editor/components/markdown-editor-overlay.d.ts.map +1 -0
  48. package/dist/src/editor/components/markdown-inline-editor.d.ts +10 -0
  49. package/dist/src/editor/components/markdown-inline-editor.d.ts.map +1 -0
  50. package/dist/src/editor/components/media-library.d.ts +2 -0
  51. package/dist/src/editor/components/media-library.d.ts.map +1 -0
  52. package/dist/src/editor/components/outline.d.ts +21 -0
  53. package/dist/src/editor/components/outline.d.ts.map +1 -0
  54. package/dist/src/editor/components/redirect-countdown.d.ts +2 -0
  55. package/dist/src/editor/components/redirect-countdown.d.ts.map +1 -0
  56. package/dist/src/editor/components/seo-editor.d.ts +2 -0
  57. package/dist/src/editor/components/seo-editor.d.ts.map +1 -0
  58. package/dist/src/editor/components/text-style-toolbar.d.ts +8 -0
  59. package/dist/src/editor/components/text-style-toolbar.d.ts.map +1 -0
  60. package/dist/src/editor/components/toast/toast-container.d.ts +7 -0
  61. package/dist/src/editor/components/toast/toast-container.d.ts.map +1 -0
  62. package/dist/src/editor/components/toast/toast.d.ts +7 -0
  63. package/dist/src/editor/components/toast/toast.d.ts.map +1 -0
  64. package/dist/src/editor/components/toast/types.d.ts +7 -0
  65. package/dist/src/editor/components/toast/types.d.ts.map +1 -0
  66. package/dist/src/editor/components/toolbar.d.ts +21 -0
  67. package/dist/src/editor/components/toolbar.d.ts.map +1 -0
  68. package/dist/src/editor/config.d.ts +4 -0
  69. package/dist/src/editor/config.d.ts.map +1 -0
  70. package/dist/src/editor/constants.d.ts +101 -0
  71. package/dist/src/editor/constants.d.ts.map +1 -0
  72. package/dist/src/editor/context.d.ts +14 -0
  73. package/dist/src/editor/context.d.ts.map +1 -0
  74. package/dist/src/editor/dom.d.ts +77 -0
  75. package/dist/src/editor/dom.d.ts.map +1 -0
  76. package/dist/src/editor/editor.d.ts +64 -0
  77. package/dist/src/editor/editor.d.ts.map +1 -0
  78. package/dist/src/editor/history.d.ts +20 -0
  79. package/dist/src/editor/history.d.ts.map +1 -0
  80. package/dist/src/editor/hooks/index.d.ts +14 -0
  81. package/dist/src/editor/hooks/index.d.ts.map +1 -0
  82. package/dist/src/editor/hooks/useAIHandlers.d.ts +22 -0
  83. package/dist/src/editor/hooks/useAIHandlers.d.ts.map +1 -0
  84. package/dist/src/editor/hooks/useBlockEditorHandlers.d.ts +18 -0
  85. package/dist/src/editor/hooks/useBlockEditorHandlers.d.ts.map +1 -0
  86. package/dist/src/editor/hooks/useElementDetection.d.ts +26 -0
  87. package/dist/src/editor/hooks/useElementDetection.d.ts.map +1 -0
  88. package/dist/src/editor/hooks/useImageHoverDetection.d.ts +12 -0
  89. package/dist/src/editor/hooks/useImageHoverDetection.d.ts.map +1 -0
  90. package/dist/src/editor/hooks/useTextSelection.d.ts +23 -0
  91. package/dist/src/editor/hooks/useTextSelection.d.ts.map +1 -0
  92. package/dist/src/editor/hooks/useTooltipState.d.ts +19 -0
  93. package/dist/src/editor/hooks/useTooltipState.d.ts.map +1 -0
  94. package/dist/src/editor/hooks/utils.d.ts +32 -0
  95. package/dist/src/editor/hooks/utils.d.ts.map +1 -0
  96. package/dist/src/editor/index.d.ts +12 -0
  97. package/dist/src/editor/index.d.ts.map +1 -0
  98. package/dist/src/editor/lib/cn.d.ts +3 -0
  99. package/dist/src/editor/lib/cn.d.ts.map +1 -0
  100. package/dist/src/editor/manifest.d.ts +19 -0
  101. package/dist/src/editor/manifest.d.ts.map +1 -0
  102. package/dist/src/editor/markdown-api.d.ts +36 -0
  103. package/dist/src/editor/markdown-api.d.ts.map +1 -0
  104. package/dist/src/editor/signals.d.ts +242 -0
  105. package/dist/src/editor/signals.d.ts.map +1 -0
  106. package/dist/src/editor/storage.d.ts +27 -0
  107. package/dist/src/editor/storage.d.ts.map +1 -0
  108. package/dist/src/editor/text-styling.d.ts +350 -0
  109. package/dist/src/editor/text-styling.d.ts.map +1 -0
  110. package/dist/src/editor/themes.d.ts +38 -0
  111. package/dist/src/editor/themes.d.ts.map +1 -0
  112. package/dist/src/editor/types.d.ts +454 -0
  113. package/dist/src/editor/types.d.ts.map +1 -0
  114. package/dist/src/error-collector.d.ts +56 -0
  115. package/dist/src/error-collector.d.ts.map +1 -0
  116. package/dist/src/handlers/component-ops.d.ts +34 -0
  117. package/dist/src/handlers/component-ops.d.ts.map +1 -0
  118. package/dist/src/handlers/markdown-ops.d.ts +41 -0
  119. package/dist/src/handlers/markdown-ops.d.ts.map +1 -0
  120. package/dist/src/handlers/request-utils.d.ts +20 -0
  121. package/dist/src/handlers/request-utils.d.ts.map +1 -0
  122. package/dist/src/handlers/source-writer.d.ts +51 -0
  123. package/dist/src/handlers/source-writer.d.ts.map +1 -0
  124. package/dist/src/html-processor.d.ts +63 -0
  125. package/dist/src/html-processor.d.ts.map +1 -0
  126. package/dist/src/index.d.ts +41 -0
  127. package/dist/src/index.d.ts.map +1 -0
  128. package/dist/src/manifest-writer.d.ts +111 -0
  129. package/dist/src/manifest-writer.d.ts.map +1 -0
  130. package/dist/src/media/contember.d.ts +15 -0
  131. package/dist/src/media/contember.d.ts.map +1 -0
  132. package/dist/src/media/local.d.ts +9 -0
  133. package/dist/src/media/local.d.ts.map +1 -0
  134. package/dist/src/media/s3.d.ts +12 -0
  135. package/dist/src/media/s3.d.ts.map +1 -0
  136. package/dist/src/media/types.d.ts +40 -0
  137. package/dist/src/media/types.d.ts.map +1 -0
  138. package/dist/src/preview-generator.d.ts +19 -0
  139. package/dist/src/preview-generator.d.ts.map +1 -0
  140. package/dist/src/seo-processor.d.ts +23 -0
  141. package/dist/src/seo-processor.d.ts.map +1 -0
  142. package/dist/src/source-finder/ast-extractors.d.ts +35 -0
  143. package/dist/src/source-finder/ast-extractors.d.ts.map +1 -0
  144. package/dist/src/source-finder/ast-parser.d.ts +16 -0
  145. package/dist/src/source-finder/ast-parser.d.ts.map +1 -0
  146. package/dist/src/source-finder/cache.d.ts +18 -0
  147. package/dist/src/source-finder/cache.d.ts.map +1 -0
  148. package/dist/src/source-finder/collection-finder.d.ts +29 -0
  149. package/dist/src/source-finder/collection-finder.d.ts.map +1 -0
  150. package/dist/src/source-finder/cross-file-tracker.d.ts +39 -0
  151. package/dist/src/source-finder/cross-file-tracker.d.ts.map +1 -0
  152. package/dist/src/source-finder/element-finder.d.ts +42 -0
  153. package/dist/src/source-finder/element-finder.d.ts.map +1 -0
  154. package/dist/src/source-finder/image-finder.d.ts +24 -0
  155. package/dist/src/source-finder/image-finder.d.ts.map +1 -0
  156. package/dist/src/source-finder/index.d.ts +9 -0
  157. package/dist/src/source-finder/index.d.ts.map +1 -0
  158. package/dist/src/source-finder/search-index.d.ts +27 -0
  159. package/dist/src/source-finder/search-index.d.ts.map +1 -0
  160. package/dist/src/source-finder/snippet-utils.d.ts +90 -0
  161. package/dist/src/source-finder/snippet-utils.d.ts.map +1 -0
  162. package/dist/src/source-finder/source-lookup.d.ts +16 -0
  163. package/dist/src/source-finder/source-lookup.d.ts.map +1 -0
  164. package/dist/src/source-finder/types.d.ts +167 -0
  165. package/dist/src/source-finder/types.d.ts.map +1 -0
  166. package/dist/src/source-finder/variable-extraction.d.ts +37 -0
  167. package/dist/src/source-finder/variable-extraction.d.ts.map +1 -0
  168. package/dist/src/tailwind-colors.d.ts +54 -0
  169. package/dist/src/tailwind-colors.d.ts.map +1 -0
  170. package/dist/src/tsconfig.tsbuildinfo +1 -0
  171. package/dist/src/types.d.ts +367 -0
  172. package/dist/src/types.d.ts.map +1 -0
  173. package/dist/src/utils.d.ts +61 -0
  174. package/dist/src/utils.d.ts.map +1 -0
  175. package/dist/src/vite-plugin.d.ts +14 -0
  176. package/dist/src/vite-plugin.d.ts.map +1 -0
  177. package/dist/types/tsconfig.tsbuildinfo +1 -0
  178. package/package.json +80 -0
  179. package/src/build-processor.ts +784 -0
  180. package/src/collection-scanner.ts +304 -0
  181. package/src/component-registry.ts +393 -0
  182. package/src/config.ts +74 -0
  183. package/src/dev-middleware.ts +525 -0
  184. package/src/dist/src/tsconfig.tsbuildinfo +1 -0
  185. package/src/editor/ai.ts +185 -0
  186. package/src/editor/api.ts +513 -0
  187. package/src/editor/color-utils.ts +556 -0
  188. package/src/editor/components/ai-chat.tsx +632 -0
  189. package/src/editor/components/ai-tooltip.tsx +179 -0
  190. package/src/editor/components/attribute-editor.tsx +596 -0
  191. package/src/editor/components/block-editor.tsx +546 -0
  192. package/src/editor/components/collections-browser.tsx +248 -0
  193. package/src/editor/components/color-toolbar.tsx +314 -0
  194. package/src/editor/components/confirm-dialog.tsx +69 -0
  195. package/src/editor/components/create-page-modal.tsx +163 -0
  196. package/src/editor/components/editable-highlights.tsx +260 -0
  197. package/src/editor/components/error-boundary.tsx +87 -0
  198. package/src/editor/components/fields.tsx +387 -0
  199. package/src/editor/components/frontmatter-fields.tsx +469 -0
  200. package/src/editor/components/highlight-overlay.ts +229 -0
  201. package/src/editor/components/image-overlay.tsx +230 -0
  202. package/src/editor/components/markdown-editor-overlay.tsx +505 -0
  203. package/src/editor/components/markdown-inline-editor.tsx +780 -0
  204. package/src/editor/components/media-library.tsx +297 -0
  205. package/src/editor/components/outline.tsx +402 -0
  206. package/src/editor/components/redirect-countdown.tsx +45 -0
  207. package/src/editor/components/seo-editor.tsx +498 -0
  208. package/src/editor/components/text-style-toolbar.tsx +362 -0
  209. package/src/editor/components/toast/toast-container.tsx +15 -0
  210. package/src/editor/components/toast/toast.tsx +49 -0
  211. package/src/editor/components/toast/types.ts +7 -0
  212. package/src/editor/components/toolbar.tsx +366 -0
  213. package/src/editor/config.ts +12 -0
  214. package/src/editor/constants.ts +106 -0
  215. package/src/editor/context.tsx +38 -0
  216. package/src/editor/dom.ts +357 -0
  217. package/src/editor/editor.ts +1510 -0
  218. package/src/editor/env.d.ts +4 -0
  219. package/src/editor/history.ts +355 -0
  220. package/src/editor/hooks/index.ts +19 -0
  221. package/src/editor/hooks/useAIHandlers.ts +345 -0
  222. package/src/editor/hooks/useBlockEditorHandlers.ts +206 -0
  223. package/src/editor/hooks/useElementDetection.ts +284 -0
  224. package/src/editor/hooks/useImageHoverDetection.ts +102 -0
  225. package/src/editor/hooks/useTextSelection.ts +187 -0
  226. package/src/editor/hooks/useTooltipState.ts +126 -0
  227. package/src/editor/hooks/utils.ts +101 -0
  228. package/src/editor/index.tsx +481 -0
  229. package/src/editor/lib/cn.ts +4 -0
  230. package/src/editor/manifest.ts +25 -0
  231. package/src/editor/markdown-api.ts +209 -0
  232. package/src/editor/signals.ts +1351 -0
  233. package/src/editor/storage.ts +266 -0
  234. package/src/editor/styles.css +465 -0
  235. package/src/editor/text-styling.ts +773 -0
  236. package/src/editor/themes.ts +210 -0
  237. package/src/editor/types.ts +591 -0
  238. package/src/error-collector.ts +106 -0
  239. package/src/handlers/component-ops.ts +463 -0
  240. package/src/handlers/markdown-ops.ts +202 -0
  241. package/src/handlers/request-utils.ts +151 -0
  242. package/src/handlers/source-writer.ts +649 -0
  243. package/src/html-processor.ts +1108 -0
  244. package/src/index.ts +284 -0
  245. package/src/manifest-writer.ts +371 -0
  246. package/src/media/contember.ts +84 -0
  247. package/src/media/local.ts +114 -0
  248. package/src/media/s3.ts +133 -0
  249. package/src/media/types.ts +33 -0
  250. package/src/preview-generator.ts +293 -0
  251. package/src/seo-processor.ts +567 -0
  252. package/src/source-finder/ast-extractors.ts +185 -0
  253. package/src/source-finder/ast-parser.ts +150 -0
  254. package/src/source-finder/cache.ts +76 -0
  255. package/src/source-finder/collection-finder.ts +335 -0
  256. package/src/source-finder/cross-file-tracker.ts +741 -0
  257. package/src/source-finder/element-finder.ts +387 -0
  258. package/src/source-finder/image-finder.ts +283 -0
  259. package/src/source-finder/index.ts +37 -0
  260. package/src/source-finder/search-index.ts +525 -0
  261. package/src/source-finder/snippet-utils.ts +668 -0
  262. package/src/source-finder/source-lookup.ts +200 -0
  263. package/src/source-finder/types.ts +210 -0
  264. package/src/source-finder/variable-extraction.ts +406 -0
  265. package/src/tailwind-colors.ts +874 -0
  266. package/src/tsconfig.json +25 -0
  267. package/src/types.ts +406 -0
  268. package/src/utils.ts +186 -0
  269. package/src/vite-plugin.ts +42 -0
package/README.md ADDED
@@ -0,0 +1,237 @@
1
+ # @nuasite/astro-cms
2
+
3
+ Astro integration that adds inline visual editing to any Astro site. Scans your components, marks editable elements with CMS IDs, and serves a live editor overlay during development. All write operations (text, images, colors, components, markdown) are handled locally via a built-in dev server — no external backend required.
4
+
5
+ ## Quick Start
6
+
7
+ ```typescript
8
+ // astro.config.mjs
9
+ import nuaCms from '@nuasite/astro-cms'
10
+
11
+ export default defineConfig({
12
+ integrations: [nuaCms()],
13
+ })
14
+ ```
15
+
16
+ That's it. Run `astro dev` and the CMS editor loads automatically. Edits write directly to your source files, and Vite HMR picks up the changes instantly.
17
+
18
+ ## How It Works
19
+
20
+ The integration operates in two phases:
21
+
22
+ **HTML Processing** — As Astro renders each page, the integration intercepts the HTML response, parses it, and injects `data-cms-id` attributes on editable elements (text, images, components). It generates a per-page manifest mapping each CMS ID to its source file, line number, and code snippet.
23
+
24
+ **Dev Server API** — When you save an edit in the visual editor, the request goes to `/_nua/cms/*` endpoints running inside Vite's dev middleware. These handlers read the source file, find the snippet, apply the change, and write the file back. Vite HMR triggers a reload.
25
+
26
+ ## Options
27
+
28
+ ```typescript
29
+ nuaCms({
30
+ // --- Editor ---
31
+ src: undefined, // Custom editor script URL (default: built-in @app/cms bundle)
32
+ cmsConfig: { // Passed to window.NuaCmsConfig
33
+ apiBase: '/_nua/cms', // API endpoint base (auto-set when using local dev server)
34
+ highlightColor: undefined,
35
+ debug: false,
36
+ theme: undefined,
37
+ themePreset: undefined,
38
+ },
39
+
40
+ // --- Backend ---
41
+ proxy: undefined, // Proxy /_nua requests to a remote backend (e.g. 'http://localhost:8787')
42
+ // When set, the local dev server API is disabled
43
+ media: undefined, // Media storage adapter (default: localMedia() when no proxy)
44
+
45
+ // --- Marker ---
46
+ attributeName: 'data-cms-id',
47
+ includeTags: null, // null = all tags
48
+ excludeTags: ['html', 'head', 'body', 'script', 'style'],
49
+ includeEmptyText: false,
50
+ generateManifest: true,
51
+ manifestFile: 'cms-manifest.json',
52
+ markComponents: true,
53
+ componentDirs: ['src/components'],
54
+ contentDir: 'src/content',
55
+ seo: { trackSeo: true, markTitle: true, parseJsonLd: true },
56
+ })
57
+ ```
58
+
59
+ ## Dev Server API
60
+
61
+ When no `proxy` is configured, the integration spins up a local API at `/_nua/cms/`. This handles all CMS operations without needing the Cloudflare Worker backend.
62
+
63
+ | Method | Path | Description |
64
+ |--------|------|-------------|
65
+ | POST | `/_nua/cms/update` | Save text, image, color, and attribute changes |
66
+ | POST | `/_nua/cms/insert-component` | Insert a component before/after a reference |
67
+ | POST | `/_nua/cms/remove-component` | Remove a component from the page |
68
+ | GET | `/_nua/cms/markdown/content` | Read markdown file content + frontmatter |
69
+ | POST | `/_nua/cms/markdown/update` | Update markdown file (partial frontmatter merge) |
70
+ | POST | `/_nua/cms/markdown/create` | Create a new markdown file in a collection |
71
+ | GET | `/_nua/cms/media/list` | List uploaded media files |
72
+ | POST | `/_nua/cms/media/upload` | Upload a file (multipart/form-data) |
73
+ | DELETE | `/_nua/cms/media/:id` | Delete an uploaded file |
74
+ | GET | `/_nua/cms/deployment/status` | Returns `{ currentDeployment: null, pendingCount: 0 }` |
75
+ | OPTIONS | `/_nua/cms/*` | CORS preflight |
76
+
77
+ ### Update Payload
78
+
79
+ The `POST /update` endpoint accepts a batch of changes:
80
+
81
+ ```typescript
82
+ {
83
+ changes: [
84
+ {
85
+ cmsId: 'cms-0',
86
+ newValue: 'Updated heading text',
87
+ originalValue: 'Original heading text',
88
+ sourcePath: 'src/pages/index.astro',
89
+ sourceLine: 42,
90
+ sourceSnippet: '<h1>Original heading text</h1>',
91
+ // Optional for specific change types:
92
+ colorChange: { oldClass: 'bg-blue-500', newClass: 'bg-red-500', type: 'bg' },
93
+ imageChange: { newSrc: '/uploads/photo.webp', newAlt: 'A photo' },
94
+ attributeChanges: [{ attributeName: 'href', oldValue: '/old', newValue: '/new' }],
95
+ }
96
+ ],
97
+ meta: { source: 'cms-editor', url: 'http://localhost:4321/about' }
98
+ }
99
+ ```
100
+
101
+ Changes are grouped by source file, sorted by line number (descending to avoid offset shifts), and applied in-place. The response returns `{ updated: number, errors?: [...] }`.
102
+
103
+ ## Media Storage Adapters
104
+
105
+ Media uploads use a pluggable adapter pattern. Three adapters are included:
106
+
107
+ ### Local Filesystem (default)
108
+
109
+ Stores files in `public/uploads/`. Served directly by Vite's static file server. Zero configuration needed.
110
+
111
+ ```typescript
112
+ import nuaCms, { localMedia } from '@nuasite/astro-cms'
113
+
114
+ nuaCms({
115
+ media: localMedia({
116
+ dir: 'public/uploads', // default
117
+ urlPrefix: '/uploads', // default
118
+ }),
119
+ })
120
+ ```
121
+
122
+ Files are named with UUIDs to avoid collisions. Listed by modification time (newest first).
123
+
124
+ ### Contember (R2 + Database)
125
+
126
+ Proxies to the existing Contember worker API. Files are stored in Cloudflare R2, metadata in the Contember database. Includes AI-powered image annotation.
127
+
128
+ ```typescript
129
+ import nuaCms, { contemberMedia } from '@nuasite/astro-cms'
130
+
131
+ nuaCms({
132
+ media: contemberMedia({
133
+ apiBaseUrl: 'https://api.example.com',
134
+ projectSlug: 'my-project',
135
+ sessionToken: process.env.NUA_SESSION_TOKEN,
136
+ }),
137
+ })
138
+ ```
139
+
140
+ This adapter calls the worker's `/cms/:projectSlug/media/*` endpoints, which handle R2 upload, Asset record creation, and image annotation. Authentication uses the `NUA_SITE_SESSION_TOKEN` cookie.
141
+
142
+ ### S3 / R2 Direct
143
+
144
+ Direct S3-compatible storage. Works with AWS S3, Cloudflare R2, MinIO, or any S3-compatible provider. Requires `@aws-sdk/client-s3` as a peer dependency.
145
+
146
+ ```typescript
147
+ import nuaCms, { s3Media } from '@nuasite/astro-cms'
148
+
149
+ nuaCms({
150
+ media: s3Media({
151
+ bucket: 'my-bucket',
152
+ region: 'us-east-1',
153
+ // Optional:
154
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID,
155
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
156
+ endpoint: 'https://account.r2.cloudflarestorage.com', // for R2
157
+ cdnPrefix: 'https://cdn.example.com', // public URL prefix
158
+ prefix: 'uploads', // key prefix in bucket
159
+ }),
160
+ })
161
+ ```
162
+
163
+ Install the optional dependency:
164
+
165
+ ```bash
166
+ npm install @aws-sdk/client-s3
167
+ ```
168
+
169
+ ### Custom Adapter
170
+
171
+ Implement the `MediaStorageAdapter` interface to use any storage backend:
172
+
173
+ ```typescript
174
+ import type { MediaStorageAdapter } from '@nuasite/astro-cms'
175
+
176
+ const myAdapter: MediaStorageAdapter = {
177
+ async list(options) {
178
+ // Return { items: MediaItem[], hasMore: boolean, cursor?: string }
179
+ },
180
+ async upload(file: Buffer, filename: string, contentType: string) {
181
+ // Return { success: boolean, url?: string, filename?: string, id?: string, error?: string }
182
+ },
183
+ async delete(id: string) {
184
+ // Return { success: boolean, error?: string }
185
+ },
186
+ }
187
+
188
+ nuaCms({ media: myAdapter })
189
+ ```
190
+
191
+ ## Proxy Mode
192
+
193
+ To use the Contember worker backend for all CMS operations (not just media), set the `proxy` option. This disables the local dev server API and forwards all `/_nua` requests to the target:
194
+
195
+ ```typescript
196
+ nuaCms({
197
+ proxy: 'http://localhost:8787', // Worker dev server
198
+ })
199
+ ```
200
+
201
+ In proxy mode, the integration only handles HTML processing and manifest serving. All write operations go through the worker (which uses GitHub API for commits and R2 for media).
202
+
203
+ ## Content Collections
204
+
205
+ The integration auto-detects Astro content collections in `src/content/`. For each collection:
206
+
207
+ - Scans all `.md`/`.mdx` files to infer a field schema from frontmatter
208
+ - Marks collection pages with a wrapper element for body editing
209
+ - Provides markdown CRUD endpoints for creating/updating entries
210
+ - Parses frontmatter with `yaml` (no `gray-matter` dependency needed)
211
+
212
+ ## Component Operations
213
+
214
+ Components in `componentDirs` (default: `src/components/`) are scanned for props and registered as insertable/removable elements. The editor can:
215
+
216
+ - **Insert** a component before or after any existing component on the page
217
+ - **Remove** a component from the page
218
+
219
+ Both operations find the invocation site (the page file, not the component file itself), locate the correct JSX tag using occurrence indexing, and modify the source with proper indentation.
220
+
221
+ ## Exports
222
+
223
+ ```typescript
224
+ // Default export
225
+ import nuaCms from '@nuasite/astro-cms'
226
+
227
+ // Media adapters
228
+ import { localMedia, s3Media, contemberMedia } from '@nuasite/astro-cms'
229
+
230
+ // Types
231
+ import type { MediaStorageAdapter, MediaItem } from '@nuasite/astro-cms'
232
+ import type { CmsManifest, ManifestEntry, ComponentDefinition } from '@nuasite/astro-cms'
233
+
234
+ // Utilities
235
+ import { scanCollections, getProjectRoot, setProjectRoot } from '@nuasite/astro-cms'
236
+ import { findCollectionSource, parseMarkdownContent } from '@nuasite/astro-cms'
237
+ ```
@@ -0,0 +1,20 @@
1
+ import type { AstroIntegrationLogger } from 'astro';
2
+ import type { ManifestWriter } from './manifest-writer';
3
+ import type { CmsMarkerOptions } from './types';
4
+ /**
5
+ * Cluster entries from the same source file into separate component instances.
6
+ * When a component is used multiple times on a page, its entries are in different
7
+ * subtrees. We partition by finding which direct child of the LCA each entry belongs to.
8
+ */
9
+ export declare function clusterComponentEntries<T>(elements: T[], entryIds: string[], findLCA: (els: T[]) => T | null): Array<{
10
+ clusterEntryIds: string[];
11
+ clusterElements: T[];
12
+ }>;
13
+ /**
14
+ * Process build output - processes all HTML files in parallel.
15
+ * Uses error aggregation to continue processing even if some files fail.
16
+ */
17
+ export declare function processBuildOutput(dir: URL, config: Required<CmsMarkerOptions>, manifestWriter: ManifestWriter, idCounter: {
18
+ value: number;
19
+ }, logger?: AstroIntegrationLogger): Promise<void>;
20
+ //# sourceMappingURL=build-processor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-processor.d.ts","sourceRoot":"","sources":["../../src/build-processor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAA;AAOnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAcvD,OAAO,KAAK,EAAE,gBAAgB,EAAmB,MAAM,SAAS,CAAA;AA6BhE;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EACxC,QAAQ,EAAE,CAAC,EAAE,EACb,QAAQ,EAAE,MAAM,EAAE,EAClB,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,CAAC,GAAG,IAAI,GAC7B,KAAK,CAAC;IAAE,eAAe,EAAE,MAAM,EAAE,CAAC;IAAC,eAAe,EAAE,CAAC,EAAE,CAAA;CAAE,CAAC,CAkD5D;AAwkBD;;;GAGG;AACH,wBAAsB,kBAAkB,CACvC,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,QAAQ,CAAC,gBAAgB,CAAC,EAClC,cAAc,EAAE,cAAc,EAC9B,SAAS,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,EAC5B,MAAM,CAAC,EAAE,sBAAsB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAyDf"}
@@ -0,0 +1,6 @@
1
+ import type { CollectionDefinition } from './types';
2
+ /**
3
+ * Scan all collections in the content directory
4
+ */
5
+ export declare function scanCollections(contentDir?: string): Promise<Record<string, CollectionDefinition>>;
6
+ //# sourceMappingURL=collection-scanner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection-scanner.d.ts","sourceRoot":"","sources":["../../src/collection-scanner.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAmD,MAAM,SAAS,CAAA;AA+QpG;;GAEG;AACH,wBAAsB,eAAe,CAAC,UAAU,GAAE,MAAsB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAyBvH"}
@@ -0,0 +1,63 @@
1
+ import type { ComponentDefinition } from './types';
2
+ /**
3
+ * Scans Astro component files and extracts their definitions including props
4
+ */
5
+ export declare class ComponentRegistry {
6
+ private components;
7
+ private componentDirs;
8
+ constructor(componentDirs?: string[]);
9
+ /**
10
+ * Scan all component directories and build the registry
11
+ */
12
+ scan(): Promise<void>;
13
+ /**
14
+ * Get all registered components
15
+ */
16
+ getComponents(): Record<string, ComponentDefinition>;
17
+ /**
18
+ * Get a specific component by name
19
+ */
20
+ getComponent(name: string): ComponentDefinition | undefined;
21
+ /**
22
+ * Scan a directory recursively for .astro files
23
+ */
24
+ private scanDirectory;
25
+ /**
26
+ * Parse a single Astro component file
27
+ */
28
+ private parseComponent;
29
+ /**
30
+ * Parse Props content and extract individual property definitions
31
+ * Handles multi-line properties with nested types
32
+ */
33
+ private parsePropsContent;
34
+ /**
35
+ * Extract content between balanced braces after a pattern match
36
+ * Properly handles nested objects
37
+ */
38
+ private extractBalancedBraces;
39
+ /**
40
+ * Extract props from component frontmatter
41
+ */
42
+ private extractProps;
43
+ /**
44
+ * Extract slot names from template
45
+ */
46
+ private extractSlots;
47
+ /**
48
+ * Extract component description from JSDoc comment
49
+ */
50
+ private extractDescription;
51
+ /**
52
+ * Extract @previewWidth value from JSDoc comment
53
+ */
54
+ private extractPreviewWidth;
55
+ }
56
+ /**
57
+ * Parse component usage in an Astro file to extract prop values
58
+ */
59
+ export declare function parseComponentUsage(content: string, componentName: string): Array<{
60
+ line: number;
61
+ props: Record<string, string>;
62
+ }>;
63
+ //# sourceMappingURL=component-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-registry.d.ts","sourceRoot":"","sources":["../../src/component-registry.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,mBAAmB,EAAiB,MAAM,SAAS,CAAA;AAEjE;;GAEG;AACH,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,UAAU,CAA8C;IAChE,OAAO,CAAC,aAAa,CAAU;gBAEnB,aAAa,GAAE,MAAM,EAAuB;IAIxD;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAW3B;;OAEG;IACH,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC;IAIpD;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS;IAI3D;;OAEG;YACW,aAAa;IAe3B;;OAEG;YACW,cAAc;IAuB5B;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IA2FzB;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IAyB7B;;OAEG;YACW,YAAY;IA2C1B;;OAEG;IACH,OAAO,CAAC,YAAY;IA2BpB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAa1B;;OAEG;IACH,OAAO,CAAC,mBAAmB;CAU3B;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,MAAM,GACnB,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAAC,CA0BxD"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Global configuration for cms-marker.
3
+ * This allows overriding the project root for testing.
4
+ */
5
+ /**
6
+ * Get the current project root directory.
7
+ * Returns the override if set, otherwise process.cwd().
8
+ */
9
+ export declare function getProjectRoot(): string;
10
+ /**
11
+ * Set the project root directory override.
12
+ * Call this to use a specific directory instead of process.cwd().
13
+ */
14
+ export declare function setProjectRoot(root: string): void;
15
+ /**
16
+ * Reset the project root to use process.cwd() again.
17
+ */
18
+ export declare function resetProjectRoot(): void;
19
+ export declare function getValidationRoot(): string;
20
+ /**
21
+ * Reset the cached validation root (call when project root changes).
22
+ */
23
+ export declare function resetValidationRoot(): void;
24
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH;;;GAGG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEjD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AASD,wBAAgB,iBAAiB,IAAI,MAAM,CAK1C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C"}
@@ -0,0 +1,20 @@
1
+ import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ import type { ManifestWriter } from './manifest-writer';
3
+ import type { MediaStorageAdapter } from './media/types';
4
+ import type { CmsMarkerOptions, ComponentDefinition } from './types';
5
+ /** Minimal ViteDevServer interface to avoid version conflicts between Astro's bundled Vite and root Vite */
6
+ interface ViteDevServerLike {
7
+ middlewares: {
8
+ use: (middleware: (req: IncomingMessage, res: ServerResponse, next: () => void) => void) => void;
9
+ };
10
+ transformIndexHtml: (url: string, html: string) => Promise<string>;
11
+ }
12
+ export interface DevMiddlewareOptions {
13
+ enableCmsApi?: boolean;
14
+ mediaAdapter?: MediaStorageAdapter;
15
+ }
16
+ export declare function createDevMiddleware(server: ViteDevServerLike, config: Required<CmsMarkerOptions>, manifestWriter: ManifestWriter, componentDefinitions: Record<string, ComponentDefinition>, idCounter: {
17
+ value: number;
18
+ }, options?: DevMiddlewareOptions): void;
19
+ export {};
20
+ //# sourceMappingURL=dev-middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-middleware.d.ts","sourceRoot":"","sources":["../../src/dev-middleware.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAkBhE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAExD,OAAO,KAAK,EAAE,gBAAgB,EAAmB,mBAAmB,EAAe,MAAM,SAAS,CAAA;AAGlG,4GAA4G;AAC5G,UAAU,iBAAiB;IAC1B,WAAW,EAAE;QACZ,GAAG,EAAE,CAAC,UAAU,EAAE,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,IAAI,KAAK,IAAI,KAAK,IAAI,CAAA;KAChG,CAAA;IACD,kBAAkB,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CAClE;AAED,MAAM,WAAW,oBAAoB;IACpC,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,YAAY,CAAC,EAAE,mBAAmB,CAAA;CAClC;AAED,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,iBAAiB,EACzB,MAAM,EAAE,QAAQ,CAAC,gBAAgB,CAAC,EAClC,cAAc,EAAE,cAAc,EAC9B,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,EACzD,SAAS,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,EAC5B,OAAO,GAAE,oBAAyB,QAoMlC"}
@@ -0,0 +1,60 @@
1
+ import { type CmsAiAction } from './api';
2
+ import type { CmsConfig, ComponentProp } from './types';
3
+ export type { CmsAiAction };
4
+ export interface AIRequest {
5
+ prompt: string;
6
+ elementId: string;
7
+ currentContent: string;
8
+ context?: string;
9
+ }
10
+ export interface AIBlockPropsRequest {
11
+ prompt: string;
12
+ componentName: string;
13
+ props: ComponentProp[];
14
+ currentValues: Record<string, unknown>;
15
+ context?: string;
16
+ }
17
+ export interface AIStreamCallbacks {
18
+ onStart?: () => void;
19
+ onToken?: (token: string, fullText: string) => void;
20
+ onComplete?: (finalText: string) => void;
21
+ onError?: (error: Error) => void;
22
+ /** Called when AI provides status updates (thinking, coding, building, deploying) */
23
+ onStatus?: (status: string, message?: string) => void;
24
+ /** Called when AI requests an action (refresh page, show preview, apply edit) */
25
+ onAction?: (action: CmsAiAction) => void;
26
+ }
27
+ export interface AIConfig {
28
+ endpoint: string;
29
+ headers?: Record<string, string>;
30
+ }
31
+ export declare function getAIConfig(config: CmsConfig): AIConfig;
32
+ export declare class AIService {
33
+ private config;
34
+ private aiConfig;
35
+ private abortController;
36
+ constructor(config: CmsConfig);
37
+ /**
38
+ * Stream AI chat request using rich SSE events
39
+ * Supports status updates, actions (refresh, preview), and streaming text
40
+ */
41
+ streamRequest(request: AIRequest, callbacks: AIStreamCallbacks): Promise<void>;
42
+ abort(): void;
43
+ isStreaming(): boolean;
44
+ /**
45
+ * Generate prop values for a component using AI
46
+ */
47
+ generateBlockProps(request: AIBlockPropsRequest): Promise<Record<string, unknown>>;
48
+ /**
49
+ * Suggest the best component to use based on user intent
50
+ */
51
+ suggestComponent(prompt: string, availableComponents: Array<{
52
+ name: string;
53
+ description?: string;
54
+ props: ComponentProp[];
55
+ }>): Promise<{
56
+ componentName: string;
57
+ suggestedProps: Record<string, unknown>;
58
+ } | null>;
59
+ }
60
+ //# sourceMappingURL=ai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai.d.ts","sourceRoot":"","sources":["../../../src/editor/ai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAkE,MAAM,OAAO,CAAA;AAExG,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAGvD,YAAY,EAA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GG;IACG,aAAa,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmDpF,KAAK,IAAI,IAAI;IAOb,WAAW,IAAI,OAAO;IAItB;;OAEG;IACG,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IA4BxF;;OAEG;IACG,gBAAgB,CACrB,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,aAAa,EAAE,CAAA;KAAE,CAAC,GACxF,OAAO,CAAC;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,GAAG,IAAI,CAAC;CAwBrF"}
@@ -0,0 +1,140 @@
1
+ import type { CmsManifest, ComponentInsertOperation, DeploymentStatusResponse, SaveBatchRequest, SaveBatchResponse, UpdateMarkdownPageRequest, UpdateMarkdownPageResponse } from './types';
2
+ /**
3
+ * Response from fetching markdown content
4
+ */
5
+ export interface GetMarkdownContentResponse {
6
+ content: string;
7
+ frontmatter: Record<string, unknown>;
8
+ filePath: string;
9
+ }
10
+ /**
11
+ * Types for CMS AI chat communication (SSE events)
12
+ */
13
+ export interface CmsAiChatRequest {
14
+ prompt: string;
15
+ elementId?: string;
16
+ currentContent?: string;
17
+ pageUrl: string;
18
+ /** Source file context for the element being edited */
19
+ context?: string;
20
+ sessionId?: string;
21
+ }
22
+ export type CmsAiEvent = CmsAiTokenEvent | CmsAiStatusEvent | CmsAiActionEvent | CmsAiErrorEvent | CmsAiDoneEvent;
23
+ export interface CmsAiTokenEvent {
24
+ type: 'token';
25
+ token: string;
26
+ fullText: string;
27
+ }
28
+ export interface CmsAiStatusEvent {
29
+ type: 'status';
30
+ status: 'thinking' | 'coding' | 'building' | 'deploying' | 'complete';
31
+ message?: string;
32
+ }
33
+ export interface CmsAiActionEvent {
34
+ type: 'action';
35
+ action: CmsAiAction;
36
+ }
37
+ export type CmsAiAction = {
38
+ name: 'refresh';
39
+ } | {
40
+ name: 'preview';
41
+ url: string;
42
+ } | {
43
+ name: 'commit';
44
+ sha: string;
45
+ message: string;
46
+ } | {
47
+ name: 'apply-edit';
48
+ elementId: string;
49
+ content: string;
50
+ htmlContent?: string;
51
+ };
52
+ export interface CmsAiErrorEvent {
53
+ type: 'error';
54
+ error: string;
55
+ code?: string;
56
+ }
57
+ export interface CmsAiDoneEvent {
58
+ type: 'done';
59
+ summary?: string;
60
+ }
61
+ export interface CmsAiStreamCallbacks {
62
+ onToken?: (token: string, fullText: string) => void;
63
+ onStatus?: (status: CmsAiStatusEvent['status'], message?: string) => void;
64
+ onAction?: (action: CmsAiAction) => void;
65
+ onError?: (error: string, code?: string) => void;
66
+ onDone?: (summary?: string) => void;
67
+ }
68
+ /**
69
+ * Get the manifest URL for the current page
70
+ * For example: /about -> /about.json
71
+ * / -> /index.json
72
+ * /blog/post -> /blog/post.json
73
+ */
74
+ export declare function getPageManifestUrl(pathname: string): string;
75
+ /**
76
+ * Fetch manifest by combining page-specific and global manifests:
77
+ * 1. Per-page manifest (/{page}.json) - contains entries, components for this page
78
+ * 2. Global manifest (/cms-manifest.json) - contains componentDefinitions, availableColors
79
+ */
80
+ export declare function fetchManifest(): Promise<CmsManifest>;
81
+ export declare function saveBatchChanges(apiBase: string, request: SaveBatchRequest): Promise<SaveBatchResponse>;
82
+ export interface InsertComponentResponse {
83
+ success: boolean;
84
+ message?: string;
85
+ sourceFile?: string;
86
+ commit?: string | null;
87
+ commitMessage?: string;
88
+ error?: string;
89
+ }
90
+ export declare function insertComponent(apiBase: string, operation: ComponentInsertOperation): Promise<InsertComponentResponse>;
91
+ export interface RemoveComponentResponse {
92
+ success: boolean;
93
+ message?: string;
94
+ sourceFile?: string;
95
+ commit?: string | null;
96
+ commitMessage?: string;
97
+ error?: string;
98
+ }
99
+ export declare function removeComponent(apiBase: string, componentId: string): Promise<RemoveComponentResponse>;
100
+ /**
101
+ * Parse SSE data line to event
102
+ */
103
+ export declare function parseSseEvent(data: string): CmsAiEvent | null;
104
+ /**
105
+ * Stream AI chat response from the server using SSE
106
+ * Provides rich events including status updates, actions (refresh, preview), and streaming tokens
107
+ */
108
+ export declare function streamAiChat(apiBase: string, request: CmsAiChatRequest, callbacks: CmsAiStreamCallbacks, abortSignal?: AbortSignal): Promise<void>;
109
+ /**
110
+ * Chat message type from history endpoint
111
+ */
112
+ export interface ChatHistoryMessage {
113
+ id: string;
114
+ role: 'user' | 'assistant' | 'tool';
115
+ content: string | null;
116
+ created_at: string;
117
+ channel?: string;
118
+ identifier?: string;
119
+ }
120
+ export interface ChatHistoryResponse {
121
+ messages: ChatHistoryMessage[];
122
+ hasMore: boolean;
123
+ }
124
+ /**
125
+ * Fetch AI chat history for the current project
126
+ */
127
+ export declare function getChatHistory(apiBase: string, limit?: number): Promise<ChatHistoryResponse>;
128
+ /**
129
+ * Fetch deployment status for the current project
130
+ */
131
+ export declare function getDeploymentStatus(apiBase: string): Promise<DeploymentStatusResponse>;
132
+ /**
133
+ * Fetch markdown content from a file
134
+ */
135
+ export declare function getMarkdownContent(apiBase: string, filePath: string): Promise<GetMarkdownContentResponse | null>;
136
+ /**
137
+ * Update markdown page content
138
+ */
139
+ export declare function updateMarkdownPage(apiBase: string, request: UpdateMarkdownPageRequest): Promise<UpdateMarkdownPageResponse>;
140
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/editor/api.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,WAAW,EACX,wBAAwB,EACxB,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,yBAAyB,EACzB,0BAA0B,EAC1B,MAAM,SAAS,CAAA;AAEhB;;GA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