@hintergrund/worker 0.1.5 → 0.1.7

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 (186) hide show
  1. package/dist/api/cms/handlers/admin-users.handler.d.ts +8 -0
  2. package/dist/api/cms/handlers/admin-users.handler.d.ts.map +1 -0
  3. package/dist/api/cms/handlers/admin-users.handler.js +121 -0
  4. package/dist/api/cms/handlers/agent-conversations.handler.d.ts +7 -0
  5. package/dist/api/cms/handlers/agent-conversations.handler.d.ts.map +1 -0
  6. package/dist/api/cms/handlers/agent-conversations.handler.js +94 -0
  7. package/dist/api/cms/handlers/auth.handler.d.ts +0 -3
  8. package/dist/api/cms/handlers/auth.handler.d.ts.map +1 -1
  9. package/dist/api/cms/handlers/auth.handler.js +74 -153
  10. package/dist/api/cms/handlers/website-repo.handler.d.ts +8 -0
  11. package/dist/api/cms/handlers/website-repo.handler.d.ts.map +1 -0
  12. package/dist/api/cms/handlers/website-repo.handler.js +148 -0
  13. package/dist/api/cms/routes/index.d.ts.map +1 -1
  14. package/dist/api/cms/routes/index.js +16 -4
  15. package/dist/api/emails/handlers/campaigns.handler.d.ts +10 -23
  16. package/dist/api/emails/handlers/campaigns.handler.d.ts.map +1 -1
  17. package/dist/api/emails/handlers/campaigns.handler.js +164 -92
  18. package/dist/api/emails/handlers/invoice.handler.d.ts +5 -19
  19. package/dist/api/emails/handlers/invoice.handler.d.ts.map +1 -1
  20. package/dist/api/emails/handlers/invoice.handler.js +58 -340
  21. package/dist/api/emails/handlers/public.handler.d.ts +6 -29
  22. package/dist/api/emails/handlers/public.handler.d.ts.map +1 -1
  23. package/dist/api/emails/handlers/public.handler.js +150 -312
  24. package/dist/api/emails/handlers/send.handler.d.ts +5 -17
  25. package/dist/api/emails/handlers/send.handler.d.ts.map +1 -1
  26. package/dist/api/emails/handlers/send.handler.js +107 -92
  27. package/dist/api/emails/handlers/settings.handler.d.ts +28 -33
  28. package/dist/api/emails/handlers/settings.handler.d.ts.map +1 -1
  29. package/dist/api/emails/handlers/settings.handler.js +96 -287
  30. package/dist/api/emails/handlers/subscribers.handler.d.ts +13 -0
  31. package/dist/api/emails/handlers/subscribers.handler.d.ts.map +1 -0
  32. package/dist/api/emails/handlers/subscribers.handler.js +125 -0
  33. package/dist/api/emails/handlers/webhook.handler.d.ts +1 -2
  34. package/dist/api/emails/handlers/webhook.handler.d.ts.map +1 -1
  35. package/dist/api/emails/handlers/webhook.handler.js +66 -166
  36. package/dist/api/emails/routes/admin.routes.d.ts +1 -3
  37. package/dist/api/emails/routes/admin.routes.d.ts.map +1 -1
  38. package/dist/api/emails/routes/admin.routes.js +19 -49
  39. package/dist/api/emails/routes/public.routes.d.ts +1 -3
  40. package/dist/api/emails/routes/public.routes.d.ts.map +1 -1
  41. package/dist/api/emails/routes/public.routes.js +2 -9
  42. package/dist/api/shop/handlers/prices.handler.d.ts +2 -15
  43. package/dist/api/shop/handlers/prices.handler.d.ts.map +1 -1
  44. package/dist/api/shop/handlers/prices.handler.js +2 -83
  45. package/dist/api/shop/handlers/products.handler.d.ts +29 -20
  46. package/dist/api/shop/handlers/products.handler.d.ts.map +1 -1
  47. package/dist/api/shop/handlers/products.handler.js +195 -162
  48. package/dist/api/shop/handlers/public.handler.d.ts +24 -8
  49. package/dist/api/shop/handlers/public.handler.d.ts.map +1 -1
  50. package/dist/api/shop/handlers/public.handler.js +525 -78
  51. package/dist/api/shop/routes.d.ts.map +1 -1
  52. package/dist/api/shop/routes.js +14 -9
  53. package/dist/hintergrund-assets.d.ts +3 -2
  54. package/dist/hintergrund-assets.d.ts.map +1 -1
  55. package/dist/hintergrund-assets.js +4 -2
  56. package/dist/index.d.ts +14 -7
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +44 -4
  59. package/dist/lib/auth/crypto.d.ts +2 -15
  60. package/dist/lib/auth/crypto.d.ts.map +1 -1
  61. package/dist/lib/auth/crypto.js +8 -95
  62. package/dist/lib/auth/jwt.d.ts +0 -4
  63. package/dist/lib/auth/jwt.d.ts.map +1 -1
  64. package/dist/lib/auth/jwt.js +0 -6
  65. package/dist/lib/config.d.ts +1 -1
  66. package/dist/lib/config.d.ts.map +1 -1
  67. package/dist/lib/config.js +42 -86
  68. package/dist/lib/email-template.d.ts +15 -0
  69. package/dist/lib/email-template.d.ts.map +1 -0
  70. package/dist/lib/email-template.js +58 -0
  71. package/dist/lib/email.d.ts +18 -8
  72. package/dist/lib/email.d.ts.map +1 -1
  73. package/dist/lib/email.js +59 -70
  74. package/dist/lib/github-config.d.ts +19 -0
  75. package/dist/lib/github-config.d.ts.map +1 -0
  76. package/dist/lib/github-config.js +23 -0
  77. package/dist/lib/github.d.ts +10 -0
  78. package/dist/lib/github.d.ts.map +1 -1
  79. package/dist/lib/github.js +20 -2
  80. package/dist/lib/project-db.d.ts +24 -0
  81. package/dist/lib/project-db.d.ts.map +1 -0
  82. package/dist/lib/project-db.js +172 -0
  83. package/dist/lib/template.js +4 -4
  84. package/dist/middleware/auth.d.ts +0 -2
  85. package/dist/middleware/auth.d.ts.map +1 -1
  86. package/dist/middleware/auth.js +21 -50
  87. package/package.json +2 -1
  88. package/dist/api/builder/handlers/generate.handler.d.ts +0 -12
  89. package/dist/api/builder/handlers/generate.handler.d.ts.map +0 -1
  90. package/dist/api/builder/handlers/generate.handler.js +0 -203
  91. package/dist/api/builder/handlers/template.handler.d.ts +0 -12
  92. package/dist/api/builder/handlers/template.handler.d.ts.map +0 -1
  93. package/dist/api/builder/handlers/template.handler.js +0 -208
  94. package/dist/api/builder/routes.d.ts +0 -7
  95. package/dist/api/builder/routes.d.ts.map +0 -1
  96. package/dist/api/builder/routes.js +0 -15
  97. package/dist/api/cms/handlers/assets.handler.d.ts +0 -31
  98. package/dist/api/cms/handlers/assets.handler.d.ts.map +0 -1
  99. package/dist/api/cms/handlers/assets.handler.js +0 -200
  100. package/dist/api/cms/handlers/config.handler.d.ts +0 -7
  101. package/dist/api/cms/handlers/config.handler.d.ts.map +0 -1
  102. package/dist/api/cms/handlers/config.handler.js +0 -37
  103. package/dist/api/cms/handlers/content.handler.d.ts +0 -21
  104. package/dist/api/cms/handlers/content.handler.d.ts.map +0 -1
  105. package/dist/api/cms/handlers/content.handler.js +0 -117
  106. package/dist/api/cms/routes/assets.routes.d.ts +0 -4
  107. package/dist/api/cms/routes/assets.routes.d.ts.map +0 -1
  108. package/dist/api/cms/routes/assets.routes.js +0 -13
  109. package/dist/api/cms/routes/content.routes.d.ts +0 -4
  110. package/dist/api/cms/routes/content.routes.d.ts.map +0 -1
  111. package/dist/api/cms/routes/content.routes.js +0 -11
  112. package/dist/api/emails/handlers/branding.handler.d.ts +0 -17
  113. package/dist/api/emails/handlers/branding.handler.d.ts.map +0 -1
  114. package/dist/api/emails/handlers/branding.handler.js +0 -120
  115. package/dist/api/emails/handlers/contacts.handler.d.ts +0 -37
  116. package/dist/api/emails/handlers/contacts.handler.d.ts.map +0 -1
  117. package/dist/api/emails/handlers/contacts.handler.js +0 -161
  118. package/dist/api/emails/handlers/templates.handler.d.ts +0 -32
  119. package/dist/api/emails/handlers/templates.handler.d.ts.map +0 -1
  120. package/dist/api/emails/handlers/templates.handler.js +0 -132
  121. package/dist/api/newsletter/handlers/email.handler.d.ts +0 -7
  122. package/dist/api/newsletter/handlers/email.handler.d.ts.map +0 -1
  123. package/dist/api/newsletter/handlers/email.handler.js +0 -102
  124. package/dist/api/newsletter/handlers/emails.handler.d.ts +0 -31
  125. package/dist/api/newsletter/handlers/emails.handler.d.ts.map +0 -1
  126. package/dist/api/newsletter/handlers/emails.handler.js +0 -262
  127. package/dist/api/newsletter/handlers/invoice.handler.d.ts +0 -22
  128. package/dist/api/newsletter/handlers/invoice.handler.d.ts.map +0 -1
  129. package/dist/api/newsletter/handlers/invoice.handler.js +0 -455
  130. package/dist/api/newsletter/handlers/public.handler.d.ts +0 -22
  131. package/dist/api/newsletter/handlers/public.handler.d.ts.map +0 -1
  132. package/dist/api/newsletter/handlers/public.handler.js +0 -300
  133. package/dist/api/newsletter/handlers/send.handler.d.ts +0 -12
  134. package/dist/api/newsletter/handlers/send.handler.d.ts.map +0 -1
  135. package/dist/api/newsletter/handlers/send.handler.js +0 -153
  136. package/dist/api/newsletter/handlers/subscribers.handler.d.ts +0 -22
  137. package/dist/api/newsletter/handlers/subscribers.handler.d.ts.map +0 -1
  138. package/dist/api/newsletter/handlers/subscribers.handler.js +0 -195
  139. package/dist/api/newsletter/routes/admin.routes.d.ts +0 -4
  140. package/dist/api/newsletter/routes/admin.routes.d.ts.map +0 -1
  141. package/dist/api/newsletter/routes/admin.routes.js +0 -28
  142. package/dist/api/newsletter/routes/index.d.ts +0 -4
  143. package/dist/api/newsletter/routes/index.d.ts.map +0 -1
  144. package/dist/api/newsletter/routes/index.js +0 -9
  145. package/dist/api/newsletter/routes/public.routes.d.ts +0 -4
  146. package/dist/api/newsletter/routes/public.routes.d.ts.map +0 -1
  147. package/dist/api/newsletter/routes/public.routes.js +0 -9
  148. package/dist/api/shop/handlers/assets.handler.d.ts +0 -3
  149. package/dist/api/shop/handlers/assets.handler.d.ts.map +0 -1
  150. package/dist/api/shop/handlers/assets.handler.js +0 -62
  151. package/dist/api/shop/handlers/checkout.handler.d.ts +0 -10
  152. package/dist/api/shop/handlers/checkout.handler.d.ts.map +0 -1
  153. package/dist/api/shop/handlers/checkout.handler.js +0 -50
  154. package/dist/api/shop/handlers/customers.handler.d.ts +0 -17
  155. package/dist/api/shop/handlers/customers.handler.d.ts.map +0 -1
  156. package/dist/api/shop/handlers/customers.handler.js +0 -89
  157. package/dist/api/shop/handlers/orders.handler.d.ts +0 -17
  158. package/dist/api/shop/handlers/orders.handler.d.ts.map +0 -1
  159. package/dist/api/shop/handlers/orders.handler.js +0 -84
  160. package/dist/api/shop/handlers/stats.handler.d.ts +0 -10
  161. package/dist/api/shop/handlers/stats.handler.d.ts.map +0 -1
  162. package/dist/api/shop/handlers/stats.handler.js +0 -71
  163. package/dist/api/shop/handlers/webhook.handler.d.ts +0 -10
  164. package/dist/api/shop/handlers/webhook.handler.d.ts.map +0 -1
  165. package/dist/api/shop/handlers/webhook.handler.js +0 -233
  166. package/dist/cms-assets.d.ts +0 -4
  167. package/dist/cms-assets.d.ts.map +0 -1
  168. package/dist/cms-assets.js +0 -5
  169. package/dist/cms-bundle.d.ts +0 -3
  170. package/dist/cms-bundle.d.ts.map +0 -1
  171. package/dist/cms-bundle.js +0 -4
  172. package/dist/config-loader.d.ts +0 -26
  173. package/dist/config-loader.d.ts.map +0 -1
  174. package/dist/config-loader.js +0 -98
  175. package/dist/jwt.d.ts +0 -26
  176. package/dist/jwt.d.ts.map +0 -1
  177. package/dist/jwt.js +0 -102
  178. package/dist/lib/plunk.d.ts +0 -204
  179. package/dist/lib/plunk.d.ts.map +0 -1
  180. package/dist/lib/plunk.js +0 -259
  181. package/dist/template.d.ts +0 -2
  182. package/dist/template.d.ts.map +0 -1
  183. package/dist/template.js +0 -61
  184. package/dist/utils.d.ts +0 -23
  185. package/dist/utils.d.ts.map +0 -1
  186. package/dist/utils.js +0 -110
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hintergrund/worker",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -23,6 +23,7 @@
23
23
  "typescript": "^5.5.2"
24
24
  },
25
25
  "dependencies": {
26
+ "@hintergrund/auth": "^0.1.2",
26
27
  "@hintergrund/shared": "workspace:*",
27
28
  "@octokit/rest": "^22.0.0",
28
29
  "cookie": "^1.0.2",
@@ -1,12 +0,0 @@
1
- import { Context } from 'hono';
2
- /**
3
- * POST /api/builder/admin/chat
4
- * Analyze user request, return implementation plan + questions
5
- */
6
- export declare function chat(c: Context): Promise<Response>;
7
- /**
8
- * POST /api/builder/admin/implement
9
- * Generate final code based on conversation
10
- */
11
- export declare function implement(c: Context): Promise<Response>;
12
- //# sourceMappingURL=generate.handler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/builder/handlers/generate.handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AA8K/B;;;GAGG;AACH,wBAAsB,IAAI,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAgDxD;AAED;;;GAGG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA6C7D"}
@@ -1,203 +0,0 @@
1
- import { getBuilderConfig } from '../../../lib/config';
2
- const SYSTEM_PROMPT = `You are an AI assistant helping to build and modify a SvelteKit website. You are working with a template that includes CMS integration, newsletter signup, and shop functionality.
3
-
4
- ## Template Structure
5
- - src/routes/ - SvelteKit page components (+page.svelte, +layout.svelte)
6
- - src/lib/components/ - Reusable Svelte 5 components
7
- - src/lib/content/globals.json - Site content (name, tagline, about text, social links, newsletter text)
8
- - src/lib/content/config.json - CMS schema definitions
9
- - src/lib/api/newsletter.ts - Newsletter API client (subscribe, unsubscribe, confirm)
10
- - src/lib/api/shop.ts - Shop API client (getProducts, createCheckoutSession)
11
- - src/lib/assets/ - Static images
12
- - static/ - Public static files
13
-
14
- ## Svelte 5 Patterns
15
- - Use $state() for reactive state: let count = $state(0);
16
- - Use $derived() for computed values: const doubled = $derived(count * 2);
17
- - Use $effect() for side effects: $effect(() => { console.log(count); });
18
- - Use $props() for component props: let { name, value = '' } = $props();
19
-
20
- ## Content Management
21
- - Site content is in src/lib/content/globals.json
22
- - Components import content: import { globals } from '$lib';
23
- - Access content: globals.siteName, globals.siteTagline, etc.
24
-
25
- ## API Integration
26
- - Newsletter: import { subscribeToNewsletter } from '$lib/api/newsletter';
27
- - Shop: import { getProducts, createCheckoutSession } from '$lib/api/shop';
28
-
29
- ## CSS Styling
30
- - Use scoped <style> blocks in Svelte components
31
- - CSS custom properties are available (--color-gray-900, etc.)
32
- - Follow existing design patterns in the codebase
33
-
34
- ## Guidelines
35
- 1. Follow existing code patterns and naming conventions
36
- 2. Keep components small and focused
37
- 3. Use semantic HTML elements
38
- 4. Ensure responsive design
39
- 5. Maintain accessibility (aria labels, keyboard navigation)`;
40
- const CHAT_PROMPT = `Based on the user's request, analyze what changes need to be made to the website.
41
-
42
- Your response must be valid JSON with this structure:
43
- {
44
- "plan": "A detailed implementation plan describing what will be changed and how",
45
- "questions": ["List of clarifying questions if you need more information to implement properly"],
46
- "affectedFiles": ["List of file paths that will be modified"]
47
- }
48
-
49
- Rules:
50
- 1. If the request is clear and you have all the information needed, return an empty questions array
51
- 2. If you need more details to implement properly, ask specific clarifying questions
52
- 3. If there are no questions, end your plan with: "Do you have any additional changes you'd like to make, or should I implement this now?"
53
- 4. The plan should be specific about what code changes will be made
54
- 5. List ALL files that will need to be modified
55
-
56
- Respond ONLY with valid JSON, no markdown code blocks.`;
57
- const IMPLEMENT_PROMPT = `Based on the conversation history, implement all the requested changes.
58
-
59
- Your response must be valid JSON with this structure:
60
- {
61
- "files": {
62
- "path/to/file.svelte": "complete file content",
63
- "path/to/another/file.ts": "complete file content"
64
- },
65
- "summary": "Brief summary of all changes made"
66
- }
67
-
68
- Rules:
69
- 1. Return the COMPLETE file content for each modified file, not partial snippets
70
- 2. Include ALL files that need to be changed based on the entire conversation
71
- 3. Follow the existing code style and patterns
72
- 4. Ensure the code is production-ready and error-free
73
- 5. The summary should list what was changed in each file
74
-
75
- Respond ONLY with valid JSON, no markdown code blocks.`;
76
- /**
77
- * Call Gemini API
78
- */
79
- async function callGemini(apiKey, systemPrompt, userPrompt, conversationHistory = []) {
80
- // Build conversation context
81
- const historyContext = conversationHistory
82
- .map(msg => `${msg.role === 'user' ? 'User' : 'Assistant'}: ${msg.content}`)
83
- .join('\n\n');
84
- const fullPrompt = historyContext
85
- ? `${historyContext}\n\nUser: ${userPrompt}`
86
- : userPrompt;
87
- const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent?key=${apiKey}`, {
88
- method: 'POST',
89
- headers: {
90
- 'Content-Type': 'application/json'
91
- },
92
- body: JSON.stringify({
93
- contents: [
94
- {
95
- role: 'user',
96
- parts: [{ text: `${systemPrompt}\n\n${fullPrompt}` }]
97
- }
98
- ],
99
- generationConfig: {
100
- temperature: 0.7,
101
- maxOutputTokens: 8192
102
- }
103
- })
104
- });
105
- if (!response.ok) {
106
- const error = await response.text();
107
- throw new Error(`Gemini API error: ${error}`);
108
- }
109
- const data = await response.json();
110
- const text = data.candidates?.[0]?.content?.parts?.[0]?.text;
111
- if (!text) {
112
- throw new Error('No response from Gemini');
113
- }
114
- return text;
115
- }
116
- /**
117
- * Parse JSON from AI response, handling potential markdown code blocks
118
- */
119
- function parseAIResponse(text) {
120
- // Remove markdown code blocks if present
121
- let cleaned = text.trim();
122
- if (cleaned.startsWith('```json')) {
123
- cleaned = cleaned.slice(7);
124
- }
125
- else if (cleaned.startsWith('```')) {
126
- cleaned = cleaned.slice(3);
127
- }
128
- if (cleaned.endsWith('```')) {
129
- cleaned = cleaned.slice(0, -3);
130
- }
131
- cleaned = cleaned.trim();
132
- return JSON.parse(cleaned);
133
- }
134
- /**
135
- * POST /api/builder/admin/chat
136
- * Analyze user request, return implementation plan + questions
137
- */
138
- export async function chat(c) {
139
- try {
140
- const request = await c.req.json();
141
- const config = getBuilderConfig(c.env);
142
- // Build file context
143
- const fileContext = Object.entries(request.currentFiles)
144
- .map(([path, content]) => `### ${path}\n\`\`\`\n${content}\n\`\`\``)
145
- .join('\n\n');
146
- const userPrompt = `${CHAT_PROMPT}
147
-
148
- ## Current Files
149
- ${fileContext}
150
-
151
- ## User Request
152
- ${request.message}`;
153
- const aiResponse = await callGemini(config.geminiApiKey, SYSTEM_PROMPT, userPrompt, request.conversationHistory);
154
- const parsed = parseAIResponse(aiResponse);
155
- const response = {
156
- success: true,
157
- response: {
158
- plan: parsed.plan,
159
- questions: parsed.questions || [],
160
- affectedFiles: parsed.affectedFiles || []
161
- }
162
- };
163
- return c.json(response);
164
- }
165
- catch (error) {
166
- console.error('Chat error:', error);
167
- return c.json({ success: false, error: error.message || 'Failed to process chat' }, 500);
168
- }
169
- }
170
- /**
171
- * POST /api/builder/admin/implement
172
- * Generate final code based on conversation
173
- */
174
- export async function implement(c) {
175
- try {
176
- const request = await c.req.json();
177
- const config = getBuilderConfig(c.env);
178
- // Build file context
179
- const fileContext = Object.entries(request.currentFiles)
180
- .map(([path, content]) => `### ${path}\n\`\`\`\n${content}\n\`\`\``)
181
- .join('\n\n');
182
- const userPrompt = `${IMPLEMENT_PROMPT}
183
-
184
- ## Current Files
185
- ${fileContext}
186
-
187
- Please implement all the changes discussed in the conversation.`;
188
- const aiResponse = await callGemini(config.geminiApiKey, SYSTEM_PROMPT, userPrompt, request.conversationHistory);
189
- const parsed = parseAIResponse(aiResponse);
190
- const response = {
191
- success: true,
192
- result: {
193
- files: parsed.files || {},
194
- summary: parsed.summary || 'Changes implemented'
195
- }
196
- };
197
- return c.json(response);
198
- }
199
- catch (error) {
200
- console.error('Implement error:', error);
201
- return c.json({ success: false, error: error.message || 'Failed to implement changes' }, 500);
202
- }
203
- }
@@ -1,12 +0,0 @@
1
- import { Context } from 'hono';
2
- /**
3
- * GET /api/builder/admin/template
4
- * Fetch all template files from the GitHub repository
5
- */
6
- export declare function getTemplate(c: Context): Promise<Response>;
7
- /**
8
- * PUT /api/builder/admin/template
9
- * Save modified files to GitHub (commit)
10
- */
11
- export declare function updateTemplate(c: Context): Promise<Response>;
12
- //# sourceMappingURL=template.handler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"template.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/builder/handlers/template.handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AA+G/B;;;GAGG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAwC/D;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA4FlE"}
@@ -1,208 +0,0 @@
1
- import { Octokit } from '@octokit/rest';
2
- import { getBuilderConfig } from '../../../lib/config';
3
- // Files to include from the template repo
4
- const INCLUDED_PATHS = [
5
- 'src/',
6
- 'static/',
7
- 'svelte.config.js',
8
- 'vite.config.ts',
9
- 'tsconfig.json',
10
- 'package.json'
11
- ];
12
- // Files to exclude
13
- const EXCLUDED_PATHS = [
14
- 'node_modules/',
15
- '.svelte-kit/',
16
- 'build/',
17
- '.git/'
18
- ];
19
- function shouldIncludeFile(path) {
20
- // Check exclusions first
21
- for (const excluded of EXCLUDED_PATHS) {
22
- if (path.startsWith(excluded) || path.includes('/' + excluded)) {
23
- return false;
24
- }
25
- }
26
- // Check if it matches any included path
27
- for (const included of INCLUDED_PATHS) {
28
- if (path.startsWith(included) || path === included.replace('/', '')) {
29
- return true;
30
- }
31
- }
32
- return false;
33
- }
34
- /**
35
- * Recursively fetch all files from a GitHub directory
36
- */
37
- async function fetchDirectoryContents(octokit, owner, repo, path, branch) {
38
- const files = [];
39
- try {
40
- const response = await octokit.rest.repos.getContent({
41
- owner,
42
- repo,
43
- path,
44
- ref: branch
45
- });
46
- if (Array.isArray(response.data)) {
47
- // It's a directory
48
- for (const item of response.data) {
49
- if (!shouldIncludeFile(item.path)) {
50
- continue;
51
- }
52
- if (item.type === 'dir') {
53
- const subFiles = await fetchDirectoryContents(octokit, owner, repo, item.path, branch);
54
- files.push(...subFiles);
55
- }
56
- else if (item.type === 'file') {
57
- // Fetch file content
58
- const fileResponse = await octokit.rest.repos.getContent({
59
- owner,
60
- repo,
61
- path: item.path,
62
- ref: branch
63
- });
64
- if (!Array.isArray(fileResponse.data) && 'content' in fileResponse.data) {
65
- files.push({
66
- path: item.path,
67
- content: atob(fileResponse.data.content),
68
- sha: fileResponse.data.sha
69
- });
70
- }
71
- }
72
- }
73
- }
74
- else if ('content' in response.data) {
75
- // It's a single file
76
- files.push({
77
- path: response.data.path,
78
- content: atob(response.data.content),
79
- sha: response.data.sha
80
- });
81
- }
82
- }
83
- catch (error) {
84
- if (error.status !== 404) {
85
- throw error;
86
- }
87
- }
88
- return files;
89
- }
90
- /**
91
- * GET /api/builder/admin/template
92
- * Fetch all template files from the GitHub repository
93
- */
94
- export async function getTemplate(c) {
95
- try {
96
- const config = getBuilderConfig(c.env);
97
- const [owner, repo] = config.templateRepo.split('/');
98
- const octokit = new Octokit({
99
- auth: config.gitToken
100
- });
101
- // Get current commit SHA
102
- const ref = await octokit.rest.git.getRef({
103
- owner,
104
- repo,
105
- ref: `heads/${config.gitBranch}`
106
- });
107
- const commitSha = ref.data.object.sha;
108
- // Fetch all files from included paths
109
- const allFiles = [];
110
- for (const includePath of INCLUDED_PATHS) {
111
- const pathToFetch = includePath.endsWith('/') ? includePath.slice(0, -1) : includePath;
112
- const files = await fetchDirectoryContents(octokit, owner, repo, pathToFetch, config.gitBranch);
113
- allFiles.push(...files);
114
- }
115
- const response = {
116
- files: allFiles,
117
- commitSha,
118
- templateRepo: config.templateRepo
119
- };
120
- return c.json(response);
121
- }
122
- catch (error) {
123
- console.error('Failed to fetch template:', error);
124
- return c.json({ success: false, error: error.message || 'Failed to fetch template' }, 500);
125
- }
126
- }
127
- /**
128
- * PUT /api/builder/admin/template
129
- * Save modified files to GitHub (commit)
130
- */
131
- export async function updateTemplate(c) {
132
- try {
133
- const request = await c.req.json();
134
- const config = getBuilderConfig(c.env);
135
- const [owner, repo] = config.templateRepo.split('/');
136
- const octokit = new Octokit({
137
- auth: config.gitToken
138
- });
139
- // Get current commit SHA
140
- const ref = await octokit.rest.git.getRef({
141
- owner,
142
- repo,
143
- ref: `heads/${config.gitBranch}`
144
- });
145
- const currentCommitSha = ref.data.object.sha;
146
- // Check for conflicts
147
- if (request.commitSha !== currentCommitSha) {
148
- const conflictResponse = {
149
- conflict: true,
150
- currentCommitSha,
151
- message: 'Template has been modified. Please sync and try again.'
152
- };
153
- return c.json(conflictResponse, 409);
154
- }
155
- // Get the current commit
156
- const commit = await octokit.rest.git.getCommit({
157
- owner,
158
- repo,
159
- commit_sha: currentCommitSha
160
- });
161
- // Create blobs for each modified file
162
- const blobs = await Promise.all(Object.entries(request.files).map(async ([path, content]) => {
163
- const blob = await octokit.rest.git.createBlob({
164
- owner,
165
- repo,
166
- content: content,
167
- encoding: 'utf-8'
168
- });
169
- return {
170
- path,
171
- mode: '100644',
172
- type: 'blob',
173
- sha: blob.data.sha
174
- };
175
- }));
176
- // Create new tree
177
- const newTree = await octokit.rest.git.createTree({
178
- owner,
179
- repo,
180
- tree: blobs,
181
- base_tree: commit.data.tree.sha
182
- });
183
- // Create commit
184
- const newCommit = await octokit.rest.git.createCommit({
185
- owner,
186
- repo,
187
- message: 'Update template via Builder',
188
- tree: newTree.data.sha,
189
- parents: [commit.data.sha]
190
- });
191
- // Update branch reference
192
- await octokit.rest.git.updateRef({
193
- owner,
194
- repo,
195
- ref: `heads/${config.gitBranch}`,
196
- sha: newCommit.data.sha
197
- });
198
- const response = {
199
- success: true,
200
- newCommitSha: newCommit.data.sha
201
- };
202
- return c.json(response);
203
- }
204
- catch (error) {
205
- console.error('Failed to update template:', error);
206
- return c.json({ success: false, error: error.message || 'Failed to update template' }, 500);
207
- }
208
- }
@@ -1,7 +0,0 @@
1
- import { Hono } from 'hono';
2
- import type { Bindings } from '../../index';
3
- declare const builderRoutes: Hono<{
4
- Bindings: Bindings;
5
- }, import("hono/types").BlankSchema, "/">;
6
- export default builderRoutes;
7
- //# sourceMappingURL=routes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../src/api/builder/routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAO5C,QAAA,MAAM,aAAa;cAAwB,QAAQ;yCAAK,CAAC;AAazD,eAAe,aAAa,CAAC"}
@@ -1,15 +0,0 @@
1
- import { Hono } from 'hono';
2
- import { authMiddleware } from '../../middleware/auth';
3
- // Import handlers
4
- import { getTemplate, updateTemplate } from './handlers/template.handler';
5
- import { chat, implement } from './handlers/generate.handler';
6
- const builderRoutes = new Hono();
7
- // Apply auth middleware to all builder routes
8
- builderRoutes.use('/admin/*', authMiddleware);
9
- // Template routes
10
- builderRoutes.get('/admin/template', getTemplate);
11
- builderRoutes.put('/admin/template', updateTemplate);
12
- // AI routes
13
- builderRoutes.post('/admin/chat', chat);
14
- builderRoutes.post('/admin/implement', implement);
15
- export default builderRoutes;
@@ -1,31 +0,0 @@
1
- import { Context } from 'hono';
2
- /**
3
- * GET /api/admin/assets
4
- * List all assets in the asset directory
5
- */
6
- export declare function listAssets(c: Context): Promise<Response>;
7
- /**
8
- * POST /api/admin/assets
9
- * Upload an asset to GitHub
10
- */
11
- export declare function uploadAsset(c: Context): Promise<Response>;
12
- /**
13
- * DELETE /api/admin/assets
14
- * Delete an asset from GitHub
15
- */
16
- export declare function deleteAsset(c: Context): Promise<Response>;
17
- /**
18
- * GET /api/admin/assets/:path
19
- * Get asset content
20
- */
21
- export declare function getAssetByPath(c: Context): Promise<Response>;
22
- /**
23
- * GET /api/admin/assets/sync
24
- * Sync all assets (with content)
25
- */
26
- export declare function syncAssets(c: Context): Promise<Response>;
27
- /**
28
- * Mock assets for development
29
- */
30
- export declare function syncAssetsMock(c: Context): Promise<Response>;
31
- //# sourceMappingURL=assets.handler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assets.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/handlers/assets.handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAuC/B;;;GAGG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA+B9D;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAuB/D;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAiB/D;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAoBlE;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA2E9D;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAGlE"}